Search in sources :

Example 1 with StructureViewBuilder

use of com.intellij.ide.structureView.StructureViewBuilder in project idea-handlebars by dmarcotte.

the class HbStructureViewFactory method getStructureViewBuilder.

@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
    return new TemplateLanguageStructureViewBuilder(psiFile) {

        @Override
        protected StructureViewComposite.StructureViewDescriptor createMainView(FileEditor fileEditor, PsiFile mainFile) {
            if (!psiFile.isValid())
                return null;
            final StructureViewBuilder builder = new TreeBasedStructureViewBuilder() {

                @NotNull
                @Override
                public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
                    return new HbStructureViewModel((HbPsiFile) psiFile, editor);
                }
            };
            StructureView structureView = builder.createStructureView(fileEditor, psiFile.getProject());
            return new StructureViewComposite.StructureViewDescriptor(HbLanguage.INSTANCE.getDisplayName(), structureView, HbFileType.INSTANCE.getIcon());
        }
    };
}
Also used : TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) TemplateLanguageStructureViewBuilder(com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureView(com.intellij.ide.structureView.StructureView) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) HbPsiFile(com.dmarcotte.handlebars.psi.HbPsiFile) PsiFile(com.intellij.psi.PsiFile) TemplateLanguageStructureViewBuilder(com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Nullable(org.jetbrains.annotations.Nullable) StructureViewComposite(com.intellij.ide.structureView.impl.StructureViewComposite) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with StructureViewBuilder

use of com.intellij.ide.structureView.StructureViewBuilder in project intellij-elixir by KronicDeth.

the class StructureViewBuilderProvider method getStructureViewBuilder.

/**
     * Returns the structure view builder for the specified file.
     *
     * @param fileType    file type of the file to provide structure for
     * @param virtualFile The file for which the structure view builder is requested.
     * @param project     The project to which the file belongs.
     * @return The structure view builder, or null if no structure view is available for the file.
     */
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(@NotNull FileType fileType, @NotNull VirtualFile virtualFile, @NotNull Project project) {
    PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
    StructureViewBuilder structureViewBuilder = null;
    if (psiFile instanceof BeamFileImpl) {
        BeamFileImpl beamFileImpl = (BeamFileImpl) psiFile;
        PsiElement mirror = beamFileImpl.getMirror();
        if (mirror instanceof ElixirFile) {
            structureViewBuilder = Factory.structureViewBuilder((ElixirFile) mirror);
        }
    }
    return structureViewBuilder;
}
Also used : StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) BeamFileImpl(org.elixir_lang.beam.psi.BeamFileImpl) PsiFile(com.intellij.psi.PsiFile) ElixirFile(org.elixir_lang.psi.ElixirFile) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with StructureViewBuilder

use of com.intellij.ide.structureView.StructureViewBuilder 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 4 with StructureViewBuilder

use of com.intellij.ide.structureView.StructureViewBuilder in project ideavim by JetBrains.

the class PsiHelper method findMethodOrClass.

private static int findMethodOrClass(@NotNull Editor editor, int offset, int count, boolean isStart) {
    PsiFile file = getFile(editor);
    if (file == null) {
        return -1;
    }
    StructureViewBuilder structureViewBuilder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file);
    if (!(structureViewBuilder instanceof TreeBasedStructureViewBuilder))
        return -1;
    TreeBasedStructureViewBuilder builder = (TreeBasedStructureViewBuilder) structureViewBuilder;
    StructureViewModel model = builder.createStructureViewModel(editor);
    TIntArrayList navigationOffsets = new TIntArrayList();
    addNavigationElements(model.getRoot(), navigationOffsets, isStart);
    if (navigationOffsets.isEmpty()) {
        return -1;
    }
    navigationOffsets.sort();
    int index = navigationOffsets.size();
    for (int i = 0; i < navigationOffsets.size(); i++) {
        if (navigationOffsets.get(i) > offset) {
            index = i;
            if (count > 0)
                count--;
            break;
        } else if (navigationOffsets.get(i) == offset) {
            index = i;
            break;
        }
    }
    int resultIndex = index + count;
    if (resultIndex < 0) {
        resultIndex = 0;
    } else if (resultIndex >= navigationOffsets.size()) {
        resultIndex = navigationOffsets.size() - 1;
    }
    return navigationOffsets.get(resultIndex);
}
Also used : LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) PsiFile(com.intellij.psi.PsiFile) TIntArrayList(gnu.trove.TIntArrayList)

Example 5 with StructureViewBuilder

use of com.intellij.ide.structureView.StructureViewBuilder in project intellij-community by JetBrains.

the class MethodUpDownUtil method addNavigationElements.

private static void addNavigationElements(Collection<PsiElement> array, PsiFile element) {
    StructureViewBuilder structureViewBuilder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(element);
    if (structureViewBuilder instanceof TreeBasedStructureViewBuilder) {
        TreeBasedStructureViewBuilder builder = (TreeBasedStructureViewBuilder) structureViewBuilder;
        StructureViewModel model = builder.createStructureViewModel(null);
        try {
            addStructureViewElements(model.getRoot(), array, element);
        } finally {
            model.dispose();
        }
    }
}
Also used : LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel)

Aggregations

StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)18 LanguageStructureViewBuilder (com.intellij.lang.LanguageStructureViewBuilder)11 TreeBasedStructureViewBuilder (com.intellij.ide.structureView.TreeBasedStructureViewBuilder)9 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)8 PsiFile (com.intellij.psi.PsiFile)7 Nullable (org.jetbrains.annotations.Nullable)7 FileEditor (com.intellij.openapi.fileEditor.FileEditor)6 StructureView (com.intellij.ide.structureView.StructureView)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 StructureViewComposite (com.intellij.ide.structureView.impl.StructureViewComposite)4 Editor (com.intellij.openapi.editor.Editor)4 HbPsiFile (com.dmarcotte.handlebars.psi.HbPsiFile)2 TemplateLanguageStructureViewBuilder (com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder)2 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)2 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)2 PsiStructureViewFactory (com.intellij.lang.PsiStructureViewFactory)2 PsiElement (com.intellij.psi.PsiElement)2 ElixirFile (org.elixir_lang.psi.ElixirFile)2 CfmlFileType (com.intellij.coldFusion.model.files.CfmlFileType)1 CfmlFileViewProvider (com.intellij.coldFusion.model.files.CfmlFileViewProvider)1