@NotNull private static Map<PsiElement, FoldingDescriptor> buildRanges(@NotNull Editor editor, @NotNull PsiFile psiFile) { final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(psiFile.getLanguage()); final ASTNode node = psiFile.getNode(); if (node == null) return Collections.emptyMap(); final FoldingDescriptor[] descriptors = LanguageFolding.buildFoldingDescriptors(foldingBuilder, psiFile, editor.getDocument(), true); Map<PsiElement, FoldingDescriptor> ranges = new HashMap<PsiElement, FoldingDescriptor>(); for (FoldingDescriptor descriptor : descriptors) { final ASTNode ast = descriptor.getElement(); final PsiElement psi = ast.getPsi(); if (psi != null) { ranges.put(psi, descriptor); } } return ranges; }
private static void getFoldingsFor(@NotNull PsiFile file, @NotNull Document document, @NotNull FoldingMap elementsToFoldMap, boolean quick) { final FileViewProvider viewProvider = file.getViewProvider(); TextRange docRange = TextRange.from(0, document.getTextLength()); for (final Language language : viewProvider.getLanguages()) { final PsiFile psi = viewProvider.getPsi(language); final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language); if (psi != null && foldingBuilder != null) { for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, quick)) { TextRange range = descriptor.getRange(); if (!docRange.contains(range)) { LOG.error("Folding descriptor " + descriptor + " made by " + foldingBuilder + " for " +language + " and called on file " + psi + " is outside document range: " + docRange); } elementsToFoldMap.putValue(descriptor.getElement().getPsi(), descriptor); } } } }
@Nonnull private static Map<PsiElement, FoldingDescriptor> buildRanges(@Nonnull Editor editor, @Nonnull PsiFile psiFile) { final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(psiFile.getLanguage()); final ASTNode node = psiFile.getNode(); if (node == null) return Collections.emptyMap(); final FoldingDescriptor[] descriptors = LanguageFolding.buildFoldingDescriptors(foldingBuilder, psiFile, editor.getDocument(), true); Map<PsiElement, FoldingDescriptor> ranges = new HashMap<>(); for (FoldingDescriptor descriptor : descriptors) { final ASTNode ast = descriptor.getElement(); final PsiElement psi = ast.getPsi(); if (psi != null) { ranges.put(psi, descriptor); } } return ranges; }
private static void getFoldingsFor(@Nonnull PsiFile file, @Nonnull Document document, @Nonnull List<RegionInfo> elementsToFold, boolean quick) { final FileViewProvider viewProvider = file.getViewProvider(); TextRange docRange = TextRange.from(0, document.getTextLength()); for (final Language language : viewProvider.getLanguages()) { final PsiFile psi = viewProvider.getPsi(language); final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language); if (psi != null && foldingBuilder != null) { for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, quick)) { PsiElement psiElement = descriptor.getElement().getPsi(); if (psiElement == null) { LOG.error("No PSI for folding descriptor " + descriptor); continue; } if (!docRange.contains(descriptor.getRange())) { diagnoseIncorrectRange(psi, document, language, foldingBuilder, descriptor, psiElement); continue; } RegionInfo regionInfo = new RegionInfo(descriptor, psiElement); elementsToFold.add(regionInfo); } } } }
/** * Checks the ability to initialize folding in the Dumb Mode for file. * * @param file the file to test * @return true if folding initialization available in the Dumb Mode */ public static boolean supportsDumbModeFolding(@NotNull PsiFile file) { final FileViewProvider viewProvider = file.getViewProvider(); for (final Language language : viewProvider.getLanguages()) { final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language); if(foldingBuilder != null && !DumbService.isDumbAware(foldingBuilder)) return false; } return true; }
private static void getFoldingsFor(@NotNull PsiFile file, @NotNull Document document, @NotNull FoldingMap elementsToFoldMap, boolean quick) { final FileViewProvider viewProvider = file.getViewProvider(); TextRange docRange = TextRange.from(0, document.getTextLength()); for (final Language language : viewProvider.getLanguages()) { final PsiFile psi = viewProvider.getPsi(language); final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language); if (psi != null && foldingBuilder != null) { for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, quick)) { TextRange range = descriptor.getRange(); ASTNode element = descriptor.getElement(); PsiElement psiElement = element.getPsi(); if (!docRange.contains(range)) { PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(file.getProject()); LOG.error("Folding descriptor " + descriptor + " made by " + foldingBuilder + " for " + language + " and called on file " + psi + " is outside document range: " + docRange + ", document committed: " + psiDocumentManager.isCommitted(document) + ", element range: " + element.getTextRange() + ", PSI element: " + psiElement + ", PSI element range: " + (psiElement == null ? null : psiElement.getTextRange()) + ", PSI element is valid: " + (psiElement != null && psiElement.isValid()) + ", PSI file is valid: " + file.isValid() + ", PSI file range: " + file.getTextRange() + ", PSI file corresponds to document: " + (file == psiDocumentManager.getCachedPsiFile(document)), ApplicationManager.getApplication().isInternal() ? new Attachment[] {AttachmentFactory.createAttachment(document), new Attachment("psiTree.txt", DebugUtil.psiToString(psi, false, true))} : new Attachment[0]); } elementsToFoldMap.putValue(psiElement, descriptor); } } } }
public ApplicationEnvironment(CoreApplicationEnvironment appEnvironment) { appEnvironment.registerFileType(HtmlFileType.INSTANCE, "html;htm;sht;shtm;shtml"); appEnvironment.registerFileType(XHtmlFileType.INSTANCE, "xhtml"); appEnvironment.registerFileType(DTDFileType.INSTANCE, "dtd;ent;mod;elt"); appEnvironment.registerFileType(XmlFileType.INSTANCE, "xml;xsd;tld;xsl;jnlp;wsdl;jhm;ant;xul;xslt;rng;fxml"); SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(XMLLanguage.INSTANCE, new XmlSyntaxHighlighterFactory()); SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(DTDLanguage.INSTANCE, new DtdSyntaxHighlighterFactory()); SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(HTMLLanguage.INSTANCE, new HtmlSyntaxHighlighterFactory()); SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(XHTMLLanguage.INSTANCE, new XhtmlSyntaxHighlighterFactory()); appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, XMLLanguage.INSTANCE, new XMLParserDefinition()); appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, DTDLanguage.INSTANCE, new DTDParserDefinition()); appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, HTMLLanguage.INSTANCE, new HTMLParserDefinition()); appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, XHTMLLanguage.INSTANCE, new XHTMLParserDefinition()); appEnvironment.addExplicitExtension(IdIndexers.INSTANCE, XmlFileType.INSTANCE, new XmlIdIndexer()); appEnvironment.addExplicitExtension(IdIndexers.INSTANCE, DTDFileType.INSTANCE, new XmlIdIndexer()); appEnvironment.addExplicitExtension(TodoIndexers.INSTANCE, XmlFileType.INSTANCE, new XmlTodoIndexer()); appEnvironment.addExplicitExtension(TodoIndexers.INSTANCE, DTDFileType.INSTANCE, new XmlTodoIndexer()); appEnvironment.addExplicitExtension(TodoIndexers.INSTANCE, XHtmlFileType.INSTANCE, new XHtmlTodoIndexer()); appEnvironment.addExtension(MetaDataContributor.EP_NAME, new XmlApplicationComponent()); appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new XmlNamespaceIndex()); appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new SchemaTypeInheritanceIndex()); appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new XmlTagNamesIndex()); appEnvironment.addExtension(StandardResourceProvider.EP_NAME, new InternalResourceProvider()); appEnvironment.registerApplicationComponent(PathMacros.class, new PathMacrosImpl()); appEnvironment.registerApplicationService(ExternalResourceManager.class, new ExternalResourceManagerExImpl()); appEnvironment.registerApplicationService(XmlFoldingSettings.class, new XmlFoldingSettings()); Language[] myLanguages = new Language[]{XMLLanguage.INSTANCE, HTMLLanguage.INSTANCE, XHTMLLanguage.INSTANCE, DTDLanguage.INSTANCE}; for (Language myLanguage : myLanguages) { appEnvironment.addExplicitExtension(LanguageFolding.INSTANCE, myLanguage, new XmlFoldingBuilder()); appEnvironment.addExplicitExtension(LanguageFindUsages.INSTANCE, myLanguage, new XmlFindUsagesProvider()); appEnvironment.addExplicitExtension(LanguageASTFactory.INSTANCE, myLanguage, new XmlASTFactory()); } }
protected void doAddForChildren(final XmlElement tag, final List<FoldingDescriptor> foldings, final Document document) { final PsiElement[] children = tag.getChildren(); for (PsiElement child : children) { ProgressManager.checkCanceled(); if (child instanceof XmlTag || child instanceof XmlConditionalSection) { addElementsToFold(foldings, (XmlElement)child, document); } else if (child instanceof XmlComment) { addToFold(foldings, child, document); } else if (child instanceof XmlText || child instanceof XmlProlog) { final PsiElement[] grandChildren = child.getChildren(); for (PsiElement grandChild : grandChildren) { ProgressManager.checkCanceled(); if (grandChild instanceof XmlComment) { addToFold(foldings, grandChild, document); } } } else if(child instanceof XmlAttribute && isAttributeShouldBeFolded((XmlAttribute)child)) { addToFold(foldings, child, document); } else { final Language language = child.getLanguage(); if (!(language instanceof XMLLanguage) && language != Language.ANY) { final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language); if (foldingBuilder != null) { final FoldingDescriptor[] foldingDescriptors = foldingBuilder.buildFoldRegions(child.getNode(), document); ContainerUtil.addAll(foldings, foldingDescriptors); } } } } }
public ApplicationEnvironment(CoreApplicationEnvironment appEnvironment) { appEnvironment.registerFileType(PropertiesFileType.INSTANCE, "properties"); appEnvironment.addExplicitExtension(SyntaxHighlighterFactory.LANGUAGE_FACTORY, PropertiesLanguage.INSTANCE, new PropertiesSyntaxHighlighterFactory()); appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesParserDefinition()); appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new XmlPropertiesIndex()); appEnvironment.addExtension(StubIndexExtension.EP_NAME, new PropertyKeyIndex()); appEnvironment.registerApplicationService(PropertiesQuickFixFactory.class, new EmptyPropertiesQuickFixFactory()); appEnvironment.registerApplicationService(PropertiesRefactoringSettings.class, new PropertiesRefactoringSettings()); appEnvironment.addExplicitExtension(LanguageAnnotators.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesAnnotator()); appEnvironment.addExplicitExtension(LanguageFindUsages.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesFindUsagesProvider()); appEnvironment.addExplicitExtension(LanguageASTFactory.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesASTFactory()); appEnvironment.addExplicitExtension(LanguageFolding.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesFoldingBuilder()); appEnvironment.addExplicitExtension(ElementManipulators.INSTANCE, PropertyImpl.class, new PropertyManipulator()); appEnvironment.addExplicitExtension(ElementManipulators.INSTANCE, PropertyKeyImpl.class, new PropertyKeyManipulator()); appEnvironment.addExplicitExtension(ElementManipulators.INSTANCE, PropertyValueImpl.class, new PropertyValueManipulator()); final StubElementTypeHolderEP stubElementTypeHolderBean = new StubElementTypeHolderEP(); stubElementTypeHolderBean.holderClass = PropertiesElementTypes.class.getName(); appEnvironment.addExtension(StubElementTypeHolderEP.EP_NAME, stubElementTypeHolderBean); appEnvironment.addExplicitExtension(LanguageCommenters.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesCommenter()); appEnvironment.addExplicitExtension(IdIndexers.INSTANCE, PropertiesFileType.INSTANCE, new PropertiesIdIndexer()); appEnvironment.addExplicitExtension(TodoIndexers.INSTANCE, PropertiesFileType.INSTANCE, new PropertiesTodoIndexer()); appEnvironment.addExtension(IconProvider.EXTENSION_POINT_NAME, new XmlPropertiesIconProvider()); }
/** * Checks the ability to initialize folding in the Dumb Mode for file. * * @param file the file to test * @return true if folding initialization available in the Dumb Mode */ static boolean supportsDumbModeFolding(@Nonnull PsiFile file) { final FileViewProvider viewProvider = file.getViewProvider(); for (final Language language : viewProvider.getLanguages()) { final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language); if(foldingBuilder != null && !DumbService.isDumbAware(foldingBuilder)) return false; } return true; }
public JavaCoreApplicationEnvironment(@NotNull Disposable parentDisposable) { super(parentDisposable); registerFileType(JavaClassFileType.INSTANCE, "class"); registerFileType(JavaFileType.INSTANCE, "java"); registerFileType(ArchiveFileType.INSTANCE, "jar;zip"); registerFileType(PlainTextFileType.INSTANCE, "txt;sh;bat;cmd;policy;log;cgi;MF;jad;jam;htaccess"); addExplicitExtension(LanguageASTFactory.INSTANCE, PlainTextLanguage.INSTANCE, new PlainTextASTFactory()); addExplicitExtension(LanguageParserDefinitions.INSTANCE, PlainTextLanguage.INSTANCE, new PlainTextParserDefinition()); addExplicitExtension(FileTypeFileViewProviders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileViewProviderFactory()); addExplicitExtension(BinaryFileStubBuilders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileStubBuilder()); addExplicitExtension(LanguageASTFactory.INSTANCE, JavaLanguage.INSTANCE, new CoreJavaASTFactory()); addExplicitExtension(LanguageParserDefinitions.INSTANCE, JavaLanguage.INSTANCE, new JavaParserDefinition()); addExplicitExtension(LanguageConstantExpressionEvaluator.INSTANCE, JavaLanguage.INSTANCE, new PsiExpressionEvaluator()); addExtension(ContainerProvider.EP_NAME, new JavaContainerProvider()); myApplication.registerService(PsiPackageImplementationHelper.class, new CorePsiPackageImplementationHelper()); myApplication.registerService(EmptySubstitutor.class, new EmptySubstitutorImpl()); myApplication.registerService(JavaDirectoryService.class, createJavaDirectoryService()); myApplication.registerService(JavaVersionService.class, new JavaVersionService()); addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiPackage.class, new PackagePresentationProvider()); addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiClass.class, new ClassPresentationProvider()); addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiMethod.class, new MethodPresentationProvider()); addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiField.class, new FieldPresentationProvider()); addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiLocalVariable.class, new VariablePresentationProvider()); addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiParameter.class, new VariablePresentationProvider()); registerApplicationService(JavaCodeFoldingSettings.class, new JavaCodeFoldingSettingsBase()); addExplicitExtension(LanguageFolding.INSTANCE, JavaLanguage.INSTANCE, new JavaFoldingBuilderBase() { @Override protected boolean shouldShowExplicitLambdaType(PsiAnonymousClass anonymousClass, PsiNewExpression expression) { return false; } @Override protected boolean isBelowRightMargin(Project project, int lineLength) { return false; } }); registerApplicationExtensionPoint(SuperMethodsSearch.EP_NAME, QueryExecutor.class); addExtension(SuperMethodsSearch.EP_NAME, new MethodSuperSearcher()); }
public static boolean isCollapseByDefault(PsiElement element) { final Language lang = element.getLanguage(); final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(lang); return foldingBuilder != null && foldingBuilder.isCollapsedByDefault(element.getNode()); }