@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; }
@Nullable private static PsiFile findPyFileInDir(PsiDirectory dir, String referencedName) { PsiFile file = dir.findFile(referencedName + PyNames.DOT_PY); if (file == null) { final List<FileNameMatcher> associations = FileTypeManager.getInstance().getAssociations(PythonFileType.INSTANCE); for (FileNameMatcher association : associations) { if (association instanceof ExtensionFileNameMatcher) { file = dir.findFile(referencedName + "." + ((ExtensionFileNameMatcher)association).getExtension()); if (file != null) break; } } } if (file != null && FileUtil.getNameWithoutExtension(file.getName()).equals(referencedName)) { return file; } 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; }
@Override public boolean accept(VirtualFile file) { if(file.isDirectory()) { return true; } for(ExtensionFileNameMatcher matcher : LuaFileType.EXTENSION_FILE_NAME_MATCHERS) { if(matcher.accept(file.getName())) { return true; } } return false; }
@NotNull private List<FileNameMatcher> parse(@Nullable String semicolonDelimited) { if (semicolonDelimited == null) { return Collections.emptyList(); } StringTokenizer tokenizer = new StringTokenizer(semicolonDelimited, FileTypeConsumer.EXTENSION_DELIMITER, false); ArrayList<FileNameMatcher> list = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { list.add(new ExtensionFileNameMatcher(tokenizer.nextToken().trim())); } return list; }
@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 static FileNameMatcher[] fileNameMatchers() { return new FileNameMatcher[] { new ExtensionFileNameMatcher(CODE_EXTENSION), new ExtensionFileNameMatcher(FS_CODE_EXTENSION), new ExtensionFileNameMatcher(HEADER_EXTENSION), }; }
@Override public void createFileTypes(@NotNull final FileTypeConsumer consumer) { FileNameMatcher[] matchers = ProjectViewStorageManager.VALID_EXTENSIONS .stream() .map(ExtensionFileNameMatcher::new) .toArray(ExtensionFileNameMatcher[]::new); consumer.consume(ProjectViewFileType.INSTANCE, matchers); }
/** * Consumes the file type with only the specified extensions. * * @param fileType The file type. * @param extensions The file extensions, without a leading '.'. */ public void consume(final FileType fileType, @NonNls final String... extensions) { Preconditions.checkNotNull(fileType); Preconditions.checkNotNull(extensions); final FileNameMatcher[] matchers = new FileNameMatcher[extensions.length]; for (int i = 0; i < extensions.length; i++) { matchers[i] = new ExtensionFileNameMatcher(extensions[i]); } consume(fileType, matchers); }
/** * Registers the given file type with IntelliJ IDEA. * * @param fileType The file type to register. */ public static void register(final IMetaborgFileType fileType) { FileTypeManagerEx.getInstanceEx().registerFileType(fileType); // Associate the file type with its file extensions. final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); for (final String ext : fileType.getExtensions()) { final FileNameMatcher matcher = new ExtensionFileNameMatcher(ext); fileTypeManager.associate(fileType, matcher); } }
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 ImmutableList<FileNameMatcher> buildLanguageFileTypeMatchers() { return ImmutableList.of( new ExactFileNameMatcher("BUILD"), new ExactFileNameMatcher("BUILD.bazel"), new ExtensionFileNameMatcher("bzl"), new ExactFileNameMatcher("WORKSPACE")); }
@NotNull public static FileNameMatcher[] fileNameMatchers() { return new FileNameMatcher[] { new ExtensionFileNameMatcher(EXTENSION) }; }
public void createFileTypes(@NotNull FileTypeConsumer consumer) { consumer.consume( HaxeFileType.HAXE_FILE_TYPE, new ExtensionFileNameMatcher(HaxeFileType.DEFAULT_EXTENSION)); }
public void createFileTypes(@NotNull FileTypeConsumer consumer) { consumer.consume( HXMLFileType.INSTANCE, new ExtensionFileNameMatcher(HXMLFileType.DEFAULT_EXTENSION)); }
public void createFileTypes(@NotNull FileTypeConsumer consumer) { consumer.consume( LIDFileType.INSTANCE, new ExtensionFileNameMatcher(LIDFileType.DEFAULT_EXTENSION), new ExtensionFileNameMatcher(LIDFileType.ALTERNATE_EXTENSION)); }
public void createFileTypes(@NotNull FileTypeConsumer consumer) { consumer.consume( DylanFileType.INSTANCE, new ExtensionFileNameMatcher(DylanFileType.DEFAULT_EXTENSION)); }
public void createFileTypes(@NotNull FileTypeConsumer consumer) { consumer.consume( MelangeInterfaceFileType.INSTANCE, new ExtensionFileNameMatcher(MelangeInterfaceFileType.DEFAULT_EXTENSION)); }