@Nullable public T findAssociatedFileType(@NotNull FileNameMatcher matcher) { if (matcher instanceof ExtensionFileNameMatcher) { return myExtensionMappings.get(((ExtensionFileNameMatcher)matcher).getExtension()); } if (matcher instanceof ExactFileNameMatcher) { final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher; Map<CharSequence, T> mapToUse = exactFileNameMatcher.isIgnoreCase() ? myExactFileNameAnyCaseMappings : myExactFileNameMappings; return mapToUse.get(exactFileNameMatcher.getFileName()); } for (Pair<FileNameMatcher, T> mapping : myMatchingMappings) { if (matcher.equals(mapping.getFirst())) return mapping.getSecond(); } return null; }
public void addAssociation(FileNameMatcher matcher, T type) { if (matcher instanceof ExtensionFileNameMatcher) { myExtensionMappings.put(((ExtensionFileNameMatcher)matcher).getExtension(), type); } else if (matcher instanceof ExactFileNameMatcher) { final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher; if (exactFileNameMatcher.isIgnoreCase()) { myExactFileNameAnyCaseMappings.put(exactFileNameMatcher.getFileName(), type); } else { myExactFileNameMappings.put(exactFileNameMatcher.getFileName(), type); } } else { myMatchingMappings.add(new Pair<FileNameMatcher, T>(matcher, type)); } }
@Nullable public T findAssociatedFileType(final FileNameMatcher matcher) { if (matcher instanceof ExtensionFileNameMatcher) { return myExtensionMappings.get(((ExtensionFileNameMatcher)matcher).getExtension()); } if (matcher instanceof ExactFileNameMatcher) { final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher; if (exactFileNameMatcher.isIgnoreCase()) { return myExactFileNameAnyCaseMappings.get(exactFileNameMatcher.getFileName()); } else { return myExactFileNameMappings.get(exactFileNameMatcher.getFileName()); } } for (Pair<FileNameMatcher, T> mapping : myMatchingMappings) { if (matcher.equals(mapping.getFirst())) return mapping.getSecond(); } return null; }
/** * Associates given file with proper {@link IgnoreFileType}. * * @param fileName to associate * @param fileType file type to bind with pattern */ public static void associateFileType(@NotNull final String fileName, @NotNull final IgnoreFileType fileType) { final Application application = ApplicationManager.getApplication(); if (application.isDispatchThread()) { final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); application.invokeLater(new Runnable() { @Override public void run() { application.runWriteAction(new Runnable() { @Override public void run() { fileTypeManager.associate(fileType, new ExactFileNameMatcher(fileName)); FILE_TYPES_ASSOCIATION_QUEUE.remove(fileName); } }); } }, ModalityState.NON_MODAL); } else if (!FILE_TYPES_ASSOCIATION_QUEUE.containsKey(fileName)) { FILE_TYPES_ASSOCIATION_QUEUE.put(fileName, fileType); } }
@NotNull public FileNameMatcher createMatcher(@NotNull String pattern) { if (pattern.startsWith("*.") && pattern.indexOf('*', 2) < 0 && pattern.indexOf('.', 2) < 0 && pattern.indexOf('?', 2) < 0) { return new ExtensionFileNameMatcher(pattern.substring(2).toLowerCase()); } if (pattern.contains("*") || pattern.contains("?")) { return new WildcardFileNameMatcher(pattern); } return new ExactFileNameMatcher(pattern); }
public boolean isAssociatedWith(@NotNull T type, @NotNull FileNameMatcher matcher) { if (matcher instanceof ExtensionFileNameMatcher || matcher instanceof ExactFileNameMatcher) { return findAssociatedFileType(matcher) == type; } for (Pair<FileNameMatcher, T> mapping : myMatchingMappings) { if (matcher.equals(mapping.getFirst()) && type == mapping.getSecond()) return true; } return false; }
public void addAssociation(FileNameMatcher matcher, T type) { if (matcher instanceof ExtensionFileNameMatcher) { myExtensionMappings.put(((ExtensionFileNameMatcher)matcher).getExtension(), type); } else if (matcher instanceof ExactFileNameMatcher) { final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher; Map<CharSequence, T> mapToUse = exactFileNameMatcher.isIgnoreCase() ? myExactFileNameAnyCaseMappings : myExactFileNameMappings; mapToUse.put(exactFileNameMatcher.getFileName(), type); } else { myMatchingMappings.add(Pair.create(matcher, type)); } }
boolean removeAssociation(@NotNull FileNameMatcher matcher, @NotNull T type) { if (matcher instanceof ExtensionFileNameMatcher) { String extension = ((ExtensionFileNameMatcher)matcher).getExtension(); if (myExtensionMappings.get(extension) == type) { myExtensionMappings.remove(extension); return true; } return false; } if (matcher instanceof ExactFileNameMatcher) { final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher; String fileName = exactFileNameMatcher.getFileName(); final Map<CharSequence, T> mapToUse = exactFileNameMatcher.isIgnoreCase() ? myExactFileNameAnyCaseMappings : myExactFileNameMappings; if(mapToUse.get(fileName) == type) { mapToUse.remove(fileName); return true; } return false; } List<Pair<FileNameMatcher, T>> copy = new ArrayList<Pair<FileNameMatcher, T>>(myMatchingMappings); for (Pair<FileNameMatcher, T> assoc : copy) { if (matcher.equals(assoc.getFirst())) { myMatchingMappings.remove(assoc); return true; } } return false; }
public boolean isAssociatedWith(T type, FileNameMatcher matcher) { if (matcher instanceof ExtensionFileNameMatcher || matcher instanceof ExactFileNameMatcher) { return findAssociatedFileType(matcher) == type; } for (Pair<FileNameMatcher, T> mapping : myMatchingMappings) { if (matcher.equals(mapping.getFirst()) && type == mapping.getSecond()) return true; } return false; }
public boolean removeAssociation(FileNameMatcher matcher, T type) { if (matcher instanceof ExtensionFileNameMatcher) { String extension = ((ExtensionFileNameMatcher)matcher).getExtension(); if (myExtensionMappings.get(extension) == type) { myExtensionMappings.remove(extension); return true; } return false; } if (matcher instanceof ExactFileNameMatcher) { final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher; final Map<String, T> mapToUse; String fileName = exactFileNameMatcher.getFileName(); if (exactFileNameMatcher.isIgnoreCase()) { mapToUse = myExactFileNameAnyCaseMappings; } else { mapToUse = myExactFileNameMappings; } if(mapToUse.get(fileName) == type) { mapToUse.remove(fileName); return true; } return false; } List<Pair<FileNameMatcher, T>> copy = new ArrayList<Pair<FileNameMatcher, T>>(myMatchingMappings); for (Pair<FileNameMatcher, T> assoc : copy) { if (matcher.equals(assoc.getFirst())) { myMatchingMappings.remove(assoc); return true; } } return false; }
public boolean removeAssociation(FileNameMatcher matcher, T type) { if (matcher instanceof ExtensionFileNameMatcher) { String extension = ((ExtensionFileNameMatcher)matcher).getExtension(); if (myExtensionMappings.get(extension) == type) { myExtensionMappings.remove(extension); return true; } return false; } if (matcher instanceof ExactFileNameMatcher) { final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher; final Map<CharSequence, T> mapToUse; String fileName = exactFileNameMatcher.getFileName(); if (exactFileNameMatcher.isIgnoreCase()) { mapToUse = myExactFileNameAnyCaseMappings; } else { mapToUse = myExactFileNameMappings; } if(mapToUse.get(fileName) == type) { mapToUse.remove(fileName); return true; } return false; } List<Pair<FileNameMatcher, T>> copy = new ArrayList<Pair<FileNameMatcher, T>>(myMatchingMappings); for (Pair<FileNameMatcher, T> assoc : copy) { if (matcher.equals(assoc.getFirst())) { myMatchingMappings.remove(assoc); return true; } } return false; }
@Override public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) { fileTypeConsumer.consume(CoffigYamlFileType.INSTANCE, new ExactFileNameMatcher("application.yaml"), new ExactFileNameMatcher("application.yml")); }
public void createFileTypes(@NotNull FileTypeConsumer consumer) { consumer.consume(StylintConfigFileType.INSTANCE, new ExactFileNameMatcher(StylintConfigFileType.STYLINTRC)); }
public void createFileTypes(final @NotNull FileTypeConsumer consumer) { consumer.consume(BuildoutCfgFileType.INSTANCE, new ExactFileNameMatcher(BuildoutFacet.BUILDOUT_CFG, true)); }
/** * {@inheritDoc} */ public void createFileTypes(@NotNull FileTypeConsumer consumer) { consumer.consume(PlainTextFileType.INSTANCE, new ExactFileNameMatcher(".gitignore"), new ExactFileNameMatcher(".gitmodules")); }
@Override public void createFileTypes(@NotNull FileTypeConsumer consumer) { ExactFileNameMatcher matcher = new ExactFileNameMatcher(GroovyExtensionProvider.ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE, !SystemInfo.isFileSystemCaseSensitive); consumer.consume(PropertiesFileType.INSTANCE, matcher); }
@Override public ImmutableList<FileNameMatcher> buildLanguageFileTypeMatchers() { return ImmutableList.of( new ExactFileNameMatcher("BUILD"), new ExactFileNameMatcher("BUILD.bazel"), new ExtensionFileNameMatcher("bzl"), new ExactFileNameMatcher("WORKSPACE")); }
public void createFileTypes(@NotNull FileTypeConsumer consumer) { consumer.consume(CoffeeLintConfigFileType.INSTANCE, new ExactFileNameMatcher(CoffeeLintConfigFileType.COFFEE_LINT_CONFIG)); }
public void createFileTypes(@NotNull FileTypeConsumer consumer) { consumer.consume(ESLintConfigFileType.INSTANCE, new ExactFileNameMatcher(ESLintConfigFileType.ESLINTRC)); // new ExtensionFileNameMatcher(ESLintConfigFileType.ESLINTRC), new ExactFileNameMatcher("eslint.json")); }
@Override public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) { fileTypeConsumer.consume(LombokConfigFileType.INSTANCE, new ExactFileNameMatcher("lombok.config")); }
/** * Shorthand for consuming ignore file types. * * @param consumer file types consumer * @param fileType file type to consume */ private void consume(@NotNull FileTypeConsumer consumer, @NotNull IgnoreFileType fileType) { consumer.consume(fileType, new ExactFileNameMatcher(fileType.getIgnoreLanguage().getFilename())); consumer.consume(fileType, fileType.getIgnoreLanguage().getExtension()); }