diff --git a/platform-api/src/com/intellij/openapi/fileTypes/FileTypeConsumer.java b/platform-api/src/com/intellij/openapi/fileTypes/FileTypeConsumer.java index 54ac902da052..9a7f5661fbbe 100644 --- a/platform-api/src/com/intellij/openapi/fileTypes/FileTypeConsumer.java +++ b/platform-api/src/com/intellij/openapi/fileTypes/FileTypeConsumer.java @@ -1,12 +1,19 @@ package com.intellij.openapi.fileTypes; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author yole */ public interface FileTypeConsumer { - void consume(final FileType fileType, @NonNls final String extensions); + String EXTENSION_DELIMITER = ";"; - void consume(final FileType fileType, final FileNameMatcher... matchers); + void consume(final @NotNull FileType fileType, @NonNls final String extensions); + + void consume(final @NotNull FileType fileType, final FileNameMatcher... matchers); + + @Nullable + FileType getStandardFileTypeByName(@NonNls @NotNull String name); } diff --git a/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java b/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java index a216c0dc76f8..a2195f990b47 100644 --- a/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java +++ b/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java @@ -84,12 +84,28 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME static { final FileTypeConsumer consumer = new FileTypeConsumer() { - public void consume(final FileType fileType, final String extensions) { - ourStandardFileTypes.put(fileType.getName(), new StandardFileType(fileType, parse(extensions))); + public void consume(final @NotNull FileType fileType, final String extensions) { + register(fileType, parse(extensions)); } - public void consume(final FileType fileType, final FileNameMatcher... matchers) { - ourStandardFileTypes.put(fileType.getName(), new StandardFileType(fileType, Arrays.asList(matchers))); + public void consume(final @NotNull FileType fileType, final FileNameMatcher... matchers) { + register(fileType, Arrays.asList(matchers)); + } + + public FileType getStandardFileTypeByName(@NotNull final String name) { + final StandardFileType type = ourStandardFileTypes.get(name); + return type != null ? type.fileType : null; + } + + private void register(final FileType fileType, final List fileNameMatchers) { + final StandardFileType type = ourStandardFileTypes.get(fileType.getName()); + + if (type != null) { + for (FileNameMatcher matcher : fileNameMatchers) type.matchers.add(matcher); + } + else { + ourStandardFileTypes.put(fileType.getName(), new StandardFileType(fileType, fileNameMatchers)); + } } }; final FileTypeFactory[] fileTypeFactories = Extensions.getExtensions(FileTypeFactory.FILE_TYPE_FACTORY_EP); @@ -619,7 +635,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME private static List parse(@NonNls String semicolonDelimited) { if (semicolonDelimited == null) return Collections.emptyList(); - StringTokenizer tokenizer = new StringTokenizer(semicolonDelimited, ";", false); + StringTokenizer tokenizer = new StringTokenizer(semicolonDelimited, FileTypeConsumer.EXTENSION_DELIMITER, false); ArrayList list = new ArrayList(); while (tokenizer.hasMoreTokens()) { list.add(new ExtensionFileNameMatcher(tokenizer.nextToken().trim()));