Search in sources :

Example 1 with TreeBasedStructureViewBuilder

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

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

the class FileStructureDialogTest method testFileStructureForClass.

public void testFileStructureForClass() throws Exception {
    final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(getPackageDirectory());
    assertNotNull(aPackage);
    final PsiClass psiClass = aPackage.getClasses()[0];
    final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
    assertNotNull(virtualFile);
    final StructureViewBuilder structureViewBuilder = StructureViewBuilder.PROVIDER.getStructureViewBuilder(virtualFile.getFileType(), virtualFile, myProject);
    assertNotNull(structureViewBuilder);
    final StructureViewModel structureViewModel = ((TreeBasedStructureViewBuilder) structureViewBuilder).createStructureViewModel(null);
    final EditorFactory factory = EditorFactory.getInstance();
    assertNotNull(factory);
    final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
    assertNotNull(document);
    final Editor editor = factory.createEditor(document, myProject);
    try {
        final FileStructureDialog dialog = new FileStructureDialog(structureViewModel, editor, myProject, psiClass, new Disposable() {

            @Override
            public void dispose() {
                structureViewModel.dispose();
            }
        }, true);
        try {
            final CommanderPanel panel = dialog.getPanel();
            assertListsEqual((ListModel) panel.getModel(), "Inner1\n" + "Inner2\n" + "__method(): void\n" + "_myField1: int\n" + "_myField2: String\n");
        } finally {
            dialog.close(0);
        }
    } finally {
        factory.releaseEditor(editor);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) EditorFactory(com.intellij.openapi.editor.EditorFactory) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) Document(com.intellij.openapi.editor.Document) CommanderPanel(com.intellij.ide.commander.CommanderPanel) FileStructureDialog(com.intellij.ide.util.FileStructureDialog) Editor(com.intellij.openapi.editor.Editor)

Example 3 with TreeBasedStructureViewBuilder

use of com.intellij.ide.structureView.TreeBasedStructureViewBuilder 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)

Example 4 with TreeBasedStructureViewBuilder

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

use of com.intellij.ide.structureView.TreeBasedStructureViewBuilder in project intellij-plugins by JetBrains.

the class CucumberStructureViewCucumberTest method getTopLevelItems.

private Object[] getTopLevelItems() {
    final FileType fileType = myFile.getFileType();
    TreeBasedStructureViewBuilder builder = (TreeBasedStructureViewBuilder) StructureViewBuilder.PROVIDER.getStructureViewBuilder(fileType, myFile, getProject());
    final StructureViewModel structureViewModel = builder.createStructureViewModel(getEditor());
    Object[] children = structureViewModel.getRoot().getChildren();
    structureViewModel.dispose();
    return children;
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel)

Aggregations

TreeBasedStructureViewBuilder (com.intellij.ide.structureView.TreeBasedStructureViewBuilder)9 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)8 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)7 PsiFile (com.intellij.psi.PsiFile)5 LanguageStructureViewBuilder (com.intellij.lang.LanguageStructureViewBuilder)4 Editor (com.intellij.openapi.editor.Editor)4 Nullable (org.jetbrains.annotations.Nullable)3 HbPsiFile (com.dmarcotte.handlebars.psi.HbPsiFile)2 StructureView (com.intellij.ide.structureView.StructureView)2 StructureViewComposite (com.intellij.ide.structureView.impl.StructureViewComposite)2 TemplateLanguageStructureViewBuilder (com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 CommanderPanel (com.intellij.ide.commander.CommanderPanel)1 FileStructureDialog (com.intellij.ide.util.FileStructureDialog)1 ItemPresentation (com.intellij.navigation.ItemPresentation)1 NavigationItem (com.intellij.navigation.NavigationItem)1 Disposable (com.intellij.openapi.Disposable)1 Document (com.intellij.openapi.editor.Document)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 FileType (com.intellij.openapi.fileTypes.FileType)1