Search in sources :

Example 6 with StructureViewComponent

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

the class JavaTreeStructureTest method dotest.

private void dotest(CheckAction checkAction) throws Exception {
    final PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory("com/package1"))[0];
    final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
    final FileEditor fileEditor = fileEditors[0];
    try {
        final StructureViewComponent structureViewComponent = (StructureViewComponent) fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
        checkAction.testClassStructure(structureViewComponent);
        Disposer.dispose(structureViewComponent);
    } finally {
        fileEditorManager.closeFile(virtualFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) PsiClass(com.intellij.psi.PsiClass) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent)

Example 7 with StructureViewComponent

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

the class JsonStructureViewTest method testSimpleStructure.

// Moved from JavaScript
public void testSimpleStructure() {
    myFixture.configureByFile("structureView/" + getTestName(false) + ".json");
    final StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(myFixture.getFile());
    assertNotNull(builder);
    StructureViewComponent component = null;
    try {
        final FileEditor editor = FileEditorManager.getInstance(getProject()).getSelectedEditor(myFixture.getFile().getVirtualFile());
        component = (StructureViewComponent) builder.createStructureView(editor, myFixture.getProject());
        final StructureViewModel model = component.getTreeModel();
        TreeElement[] children = model.getRoot().getChildren();
        assertEquals(2, children.length);
        assertEquals("aaa", children[0].getPresentation().getPresentableText());
        assertEquals(PlatformIcons.PROPERTY_ICON, children[0].getPresentation().getIcon(false));
        assertEquals("bbb", children[1].getPresentation().getPresentableText());
        assertEquals(AllIcons.Json.Property_braces, children[1].getPresentation().getIcon(false));
        children = children[1].getChildren();
        assertEquals(1, children.length);
        assertEquals("ccc", children[0].getPresentation().getPresentableText());
        assertEquals(PlatformIcons.PROPERTY_ICON, children[0].getPresentation().getIcon(false));
    } finally {
        if (component != null) {
            Disposer.dispose(component);
        }
    }
}
Also used : LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement)

Example 8 with StructureViewComponent

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

the class StructureViewUpdatingTest method testJavaClassStructure.

public void testJavaClassStructure() throws Exception {
    final PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory("com/package1"))[0];
    final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
    final FileEditor fileEditor = fileEditors[0];
    try {
        final StructureViewComponent structureViewComponent = (StructureViewComponent) fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
        final Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile());
        structureViewComponent.setActionActive(InheritedMembersNodeProvider.ID, true);
        PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + " -Class1\n" + "  getValue(): int\n" + "  getClass(): Class<? extends Object>\n" + "  hashCode(): int\n" + "  equals(Object): boolean\n" + "  clone(): Object\n" + "  toString(): String\n" + "  notify(): void\n" + "  notifyAll(): void\n" + "  wait(long): void\n" + "  wait(long, int): void\n" + "  wait(): void\n" + "  finalize(): void\n" + "  myField1: boolean\n" + "  myField2: boolean\n");
        new WriteCommandAction.Simple(getProject()) {

            @Override
            protected void run() throws Throwable {
                final int offset = document.getLineStartOffset(5);
                document.insertString(offset, "    boolean myNewField = false;\n");
            }
        }.execute().throwException();
        PsiDocumentManager.getInstance(myProject).commitDocument(document);
        PlatformTestUtil.waitForAlarm(600);
        //TreeUtil.expand(structureViewComponent.getTree(), 3);
        PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + " -Class1\n" + "  getValue(): int\n" + "  getClass(): Class<? extends Object>\n" + "  hashCode(): int\n" + "  equals(Object): boolean\n" + "  clone(): Object\n" + "  toString(): String\n" + "  notify(): void\n" + "  notifyAll(): void\n" + "  wait(long): void\n" + "  wait(long, int): void\n" + "  wait(): void\n" + "  finalize(): void\n" + "  myField1: boolean\n" + "  myField2: boolean\n" + "  myNewField: boolean = false\n");
        Disposer.dispose(structureViewComponent);
    } finally {
        fileEditorManager.closeFile(virtualFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) PsiClass(com.intellij.psi.PsiClass) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent) Document(com.intellij.openapi.editor.Document)

Example 9 with StructureViewComponent

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

the class TemplateLanguageStructureViewBuilder method updateBaseLanguageView.

private void updateBaseLanguageView() {
    if (myBaseStructureViewDescriptor == null || !myProject.isOpen())
        return;
    final StructureViewComponent view = (StructureViewComponent) myBaseStructureViewDescriptor.structureView;
    if (view.isDisposed())
        return;
    StructureViewState state = view.getState();
    List<PsiAnchor> expanded = collectAnchors(state.getExpandedElements());
    List<PsiAnchor> selected = collectAnchors(state.getSelectedElements());
    updateTemplateDataFileView();
    if (view.isDisposed())
        return;
    for (PsiAnchor pointer : expanded) {
        PsiElement element = pointer.retrieve();
        if (element != null) {
            view.expandPathToElement(element);
        }
    }
    for (PsiAnchor pointer : selected) {
        PsiElement element = pointer.retrieve();
        if (element != null) {
            view.addSelectionPathTo(element);
        }
    }
}
Also used : StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent)

Example 10 with StructureViewComponent

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

the class CodeInsightTestFixtureImpl method testStructureView.

@Override
public void testStructureView(@NotNull Consumer<StructureViewComponent> consumer) {
    assertNotNull("configure first", myFile);
    final FileEditor fileEditor = FileEditorManager.getInstance(getProject()).getSelectedEditor(myFile);
    assertNotNull("editor not opened for " + myFile, myFile);
    final StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(getFile());
    assertNotNull("no builder for " + myFile, builder);
    StructureViewComponent component = null;
    try {
        component = (StructureViewComponent) builder.createStructureView(fileEditor, getProject());
        consumer.consume(component);
    } finally {
        if (component != null)
            Disposer.dispose(component);
    }
}
Also used : LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent)

Aggregations

StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)11 FileEditor (com.intellij.openapi.fileEditor.FileEditor)6 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 PsiClass (com.intellij.psi.PsiClass)4 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)2 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)2 LanguageStructureViewBuilder (com.intellij.lang.LanguageStructureViewBuilder)2 PsiField (com.intellij.psi.PsiField)2 StructureViewWrapperImpl (com.intellij.ide.impl.StructureViewWrapperImpl)1 AbstractProjectViewPSIPane (com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane)1 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 Language (com.intellij.lang.Language)1 Document (com.intellij.openapi.editor.Document)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 XmlElement (com.intellij.psi.xml.XmlElement)1 XmlTag (com.intellij.psi.xml.XmlTag)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 DomElement (com.intellij.util.xml.DomElement)1