List of usage examples for com.intellij.openapi.fileTypes FileTypeManager getAssociations
@NotNull
public abstract List<FileNameMatcher> getAssociations(@NotNull FileType type);
From source file:altn8.filematcher.AlternateGenericRegexFileMatcher.java
License:Apache License
private String createFileExtensionPattern() { StringBuilder sb = new StringBuilder(); FileTypeManager fileTypeManager = FileTypeManager.getInstance(); for (FileType fileType : fileTypeManager.getRegisteredFileTypes()) { for (FileNameMatcher fileNameMatcher : fileTypeManager.getAssociations(fileType)) { String extension = null; if (fileNameMatcher instanceof ExtensionFileNameMatcher) { extension = ((ExtensionFileNameMatcher) fileNameMatcher).getExtension(); } else if (fileNameMatcher instanceof WildcardFileNameMatcher) { String pattern = ((WildcardFileNameMatcher) fileNameMatcher).getPattern(); if (pattern.startsWith("*.")) { // we only support matcher starting with *. assuming it's a file extension extension = PatternUtil.convertToRegex(pattern.substring(2)); }/*from w w w. j a v a 2s .c o m*/ } if (extension != null) { if (sb.length() > 0) { sb.append("|"); } sb.append(extension); } } } return sb.toString(); }
From source file:com.facebook.buck.intellij.ideabuck.file.BuckFileUtil.java
License:Apache License
public static void setBuckFileType() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override/*from www. j a v a 2s. c o m*/ public void run() { FileTypeManager fileTypeManager = FileTypeManagerImpl.getInstance(); FileType fileType = fileTypeManager .getFileTypeByFileName(BuckFileType.INSTANCE.getDefaultExtension()); // Remove all FileType associations for BUCK files that are not BuckFileType while (!(fileType instanceof BuckFileType || fileType instanceof UnknownFileType)) { List<FileNameMatcher> fileNameMatchers = fileTypeManager.getAssociations(fileType); for (FileNameMatcher fileNameMatcher : fileNameMatchers) { if (fileNameMatcher.accept(BuckFileType.INSTANCE.getDefaultExtension())) { fileTypeManager.removeAssociation(fileType, fileNameMatcher); } } fileType = fileTypeManager.getFileTypeByFileName(BuckFileType.INSTANCE.getDefaultExtension()); } // Use a simple BinaryFileStubBuilder, that doesn't offer stubbing BinaryFileStubBuilders.INSTANCE.addExplicitExtension(fileType, new BinaryFileStubBuilder() { @Override public boolean acceptsFile(VirtualFile virtualFile) { return false; } @Nullable @Override public Stub buildStubTree(FileContent fileContent) { return null; } @Override public int getStubVersion() { return 0; } }); } }); }
From source file:com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings.java
License:Apache License
public void updateSubstitutors() { // unregister Iterator<Map.Entry<String, Pair<Language, LanguageSubstitutor>>> iterator = substitutorMap.entrySet() .iterator();//from w w w .ja v a 2 s . c om while (iterator.hasNext()) { Map.Entry<String, Pair<Language, LanguageSubstitutor>> entry = iterator.next(); if (!substitutedExtensions.contains(entry.getKey())) { // System.err.println("Unregistering " + entry.getKey()); LanguageSubstitutors.INSTANCE.removeExplicitExtension(entry.getValue().first, entry.getValue().second); iterator.remove(); } } // register FileTypeManager fileTypeManager = FileTypeManager.getInstance(); for (FileType fileType : fileTypeManager.getRegisteredFileTypes()) { if (fileType instanceof LanguageFileType) { Language language = ((LanguageFileType) fileType).getLanguage(); for (FileNameMatcher matcher : fileTypeManager.getAssociations(fileType)) { String presentableString = matcher.getPresentableString(); if (substitutedExtensions.contains(presentableString) && !substitutorMap.containsKey(presentableString)) { // System.err.println("Registering " + presentableString); LanguageSubstitutor substitutor = new HTMLMasonLanguageSubstitutor(myProject, matcher); LanguageSubstitutors.INSTANCE.addExplicitExtension(language, substitutor); substitutorMap.put(presentableString, Pair.create(language, substitutor)); } } } } }
From source file:com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettingsConfigurable.java
License:Apache License
protected void reparseComponents(final Set<String> rootsDiff, Set<String> extDiff, final boolean forceAll) { boolean rootsChanged = !rootsDiff.isEmpty(); boolean extChanged = !extDiff.isEmpty(); if (rootsChanged || forceAll) extDiff.addAll(mySettings.substitutedExtensions); if (extChanged || forceAll) rootsDiff.addAll(mySettings.componentRoots); // collecting matchers final List<FileNameMatcher> matchers = new ArrayList<FileNameMatcher>(); FileTypeManager fileTypeManager = FileTypeManager.getInstance(); for (FileType fileType : fileTypeManager.getRegisteredFileTypes()) { if (fileType instanceof LanguageFileType) { for (FileNameMatcher matcher : fileTypeManager.getAssociations(fileType)) { if (extDiff.contains(matcher.getPresentableString())) { matchers.add(matcher); }/*from ww w .ja v a 2s.co m*/ } } } final String autohandlerName = mySettings.autoHandlerName; final String defaulthandlerName = mySettings.defaultHandlerName; // processing files final PushedFilePropertiesUpdater pushedFilePropertiesUpdater = PushedFilePropertiesUpdater .getInstance(myProject); VirtualFile projectRoot = myProject.getBaseDir(); if (projectRoot != null) { for (String root : rootsDiff) { VirtualFile componentRoot = VfsUtil.findRelativeFile(root, projectRoot); if (componentRoot != null) { VfsUtil.processFilesRecursively(componentRoot, new Processor<VirtualFile>() { @Override public boolean process(VirtualFile virtualFile) { if (!virtualFile.isDirectory()) { if (StringUtil.equals(autohandlerName, virtualFile.getName()) || StringUtil.equals(defaulthandlerName, virtualFile.getName())) { pushedFilePropertiesUpdater.filePropertiesChanged(virtualFile); } else { for (FileNameMatcher matcher : matchers) { if (matcher.accept(virtualFile.getName())) { pushedFilePropertiesUpdater.filePropertiesChanged(virtualFile); break; } } } } return true; } }); } } } FileContentUtil.reparseOpenedFiles(); // taken from 16 version of platform, dumbmode reindexing DumbModeTask dumbTask = FileBasedIndexProjectHandler.createChangedFilesIndexingTask(myProject); if (dumbTask != null) { DumbService.getInstance(myProject).queueTask(dumbTask); } }
From source file:com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettingsConfigurable.java
License:Apache License
protected void createSubstitutedExtensionsComponent(FormBuilder builder) { substitutedExtensionsModel = new CollectionListModel<String>(); substitutedExtensionsList = new JBList(substitutedExtensionsModel); substitutedExtensionsPanel = ToolbarDecorator.createDecorator(substitutedExtensionsList) .setAddAction(new AnActionButtonRunnable() { @Override/* www .j a va 2s. c om*/ public void run(AnActionButton anActionButton) { FileTypeManager fileTypeManager = FileTypeManager.getInstance(); final List<String> currentItems = substitutedExtensionsModel.getItems(); List<FileNameMatcher> possibleItems = new ArrayList<FileNameMatcher>(); List<Icon> itemsIcons = new ArrayList<Icon>(); for (FileType fileType : fileTypeManager.getRegisteredFileTypes()) { if (fileType instanceof LanguageFileType) { for (FileNameMatcher matcher : fileTypeManager.getAssociations(fileType)) { String presentableString = matcher.getPresentableString(); if (!currentItems.contains(presentableString)) { possibleItems.add(matcher); itemsIcons.add(fileType.getIcon()); } } } } BaseListPopupStep<FileNameMatcher> fileNameMatcherBaseListPopupStep = new BaseListPopupStep<FileNameMatcher>( "Select Extension", possibleItems, itemsIcons) { @Override public PopupStep onChosen(FileNameMatcher selectedValue, boolean finalChoice) { substitutedExtensionsModel.add(selectedValue.getPresentableString()); return super.onChosen(selectedValue, finalChoice); } }; JBPopupFactory.getInstance().createListPopup(fileNameMatcherBaseListPopupStep, 20) .showInCenterOf(substitutedExtensionsPanel); } }).disableDownAction().disableUpAction() .setPreferredSize(JBUI.size(0, PerlConfigurationUtil.WIDGET_HEIGHT)).createPanel(); builder.addLabeledComponent(new JLabel( "Extensions that should be handled as HTML::Mason components except *.mas (only under roots configured above):"), substitutedExtensionsPanel); }
From source file:com.twitter.intellij.pants.quickfix.TypeAssociationFix.java
License:Apache License
@Override public void invoke(@NotNull final Project project, Editor editor, PsiFile psiFile) throws IncorrectOperationException { FileTypeManager manager = FileTypeManager.getInstance(); FileType type = manager.getFileTypeByFileName(psiFile.getName()); // Remove the BUILD file matcher from the wrong type then add it to PythonFileType for (FileNameMatcher matcher : manager.getAssociations(type)) { if (matcher.accept(psiFile.getName())) { manager.removeAssociation(type, matcher); }/*from ww w.j a v a 2 s. com*/ } }