Search in sources :

Example 1 with PsiStructureViewFactory

use of com.intellij.lang.PsiStructureViewFactory in project intellij-community by JetBrains.

the class XmlStructureViewBuilderFactory method getStructureViewBuilderForExtensions.

@Nullable
private static StructureViewBuilder getStructureViewBuilderForExtensions(final PsiFile psiFile) {
    for (Language language : XMLLanguage.INSTANCE.getLanguageExtensionsForFile(psiFile)) {
        PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(language);
        if (factory == null)
            continue;
        final StructureViewBuilder builder = factory.getStructureViewBuilder(psiFile);
        if (builder != null) {
            return builder;
        }
    }
    return null;
}
Also used : PsiStructureViewFactory(com.intellij.lang.PsiStructureViewFactory) LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) Language(com.intellij.lang.Language) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PsiStructureViewFactory

use of com.intellij.lang.PsiStructureViewFactory in project intellij-community by JetBrains.

the class LanguageFileTypeStructureViewBuilderProvider method getStructureViewBuilder.

@Override
@Nullable
public StructureViewBuilder getStructureViewBuilder(@NotNull final FileType fileType, @NotNull final VirtualFile file, @NotNull final Project project) {
    if (!(fileType instanceof LanguageFileType))
        return null;
    final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile == null)
        return null;
    final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiFile.getLanguage());
    return factory == null ? null : factory.getStructureViewBuilder(psiFile);
}
Also used : PsiStructureViewFactory(com.intellij.lang.PsiStructureViewFactory) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PsiStructureViewFactory

use of com.intellij.lang.PsiStructureViewFactory in project intellij-community by JetBrains.

the class GotoClassAction method findMember.

@Nullable
private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
    final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiElement.getLanguage());
    final StructureViewBuilder builder = factory == null ? null : factory.getStructureViewBuilder(psiElement.getContainingFile());
    final FileEditor[] editors = FileEditorManager.getInstance(psiElement.getProject()).getEditors(file);
    if (builder == null || editors.length == 0) {
        return null;
    }
    final StructureView view = builder.createStructureView(editors[0], psiElement.getProject());
    try {
        final StructureViewTreeElement element = findElement(view.getTreeModel().getRoot(), psiElement, 4);
        if (element == null) {
            return null;
        }
        final MinusculeMatcher matcher = NameUtil.buildMatcher(pattern).build();
        int max = Integer.MIN_VALUE;
        Object target = null;
        for (TreeElement treeElement : element.getChildren()) {
            if (treeElement instanceof StructureViewTreeElement) {
                String presentableText = treeElement.getPresentation().getPresentableText();
                if (presentableText != null) {
                    final int degree = matcher.matchingDegree(presentableText);
                    if (degree > max) {
                        max = degree;
                        target = ((StructureViewTreeElement) treeElement).getValue();
                    }
                }
            }
        }
        return target instanceof Navigatable ? (Navigatable) target : null;
    } finally {
        Disposer.dispose(view);
    }
}
Also used : PsiStructureViewFactory(com.intellij.lang.PsiStructureViewFactory) LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureView(com.intellij.ide.structureView.StructureView) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PsiStructureViewFactory

use of com.intellij.lang.PsiStructureViewFactory in project intellij-community by JetBrains.

the class TemplateLanguageStructureViewBuilder method createBaseLanguageStructureView.

@Nullable
private StructureViewComposite.StructureViewDescriptor createBaseLanguageStructureView(final FileEditor fileEditor, final Language language) {
    if (!myVirtualFile.isValid())
        return null;
    final FileViewProvider viewProvider = getViewProvider();
    if (viewProvider == null)
        return null;
    final PsiFile dataFile = viewProvider.getPsi(language);
    if (dataFile == null || !isAcceptableBaseLanguageFile(dataFile))
        return null;
    final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(language);
    if (factory == null)
        return null;
    final StructureViewBuilder builder = factory.getStructureViewBuilder(dataFile);
    if (builder == null)
        return null;
    StructureView structureView = builder.createStructureView(fileEditor, myProject);
    return new StructureViewComposite.StructureViewDescriptor(IdeBundle.message("tab.structureview.baselanguage.view", language.getDisplayName()), structureView, findFileType(language).getIcon());
}
Also used : PsiStructureViewFactory(com.intellij.lang.PsiStructureViewFactory) LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiStructureViewFactory (com.intellij.lang.PsiStructureViewFactory)4 Nullable (org.jetbrains.annotations.Nullable)4 LanguageStructureViewBuilder (com.intellij.lang.LanguageStructureViewBuilder)3 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)2 StructureView (com.intellij.ide.structureView.StructureView)1 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 TreeBasedStructureViewBuilder (com.intellij.ide.structureView.TreeBasedStructureViewBuilder)1 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)1 Language (com.intellij.lang.Language)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 Navigatable (com.intellij.pom.Navigatable)1 PsiFile (com.intellij.psi.PsiFile)1 MinusculeMatcher (com.intellij.psi.codeStyle.MinusculeMatcher)1 TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)1