Search in sources :

Example 1 with AbstractProjectViewPSIPane

use of com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane in project intellij-community by JetBrains.

the class ProjectTreeBuilderTest method testShowClassMembers.

public void testShowClassMembers() throws IncorrectOperationException, IOException {
    myStructure.setShowMembers(true);
    useStandardProviders();
    final PsiClass[] classes = JavaDirectoryService.getInstance().getClasses(getPackageDirectory());
    sortClassesByName(classes);
    PsiClass aClass = classes[1];
    PsiClass innerClass1 = aClass.getInnerClasses()[0];
    PsiClass innerClass12 = innerClass1.getInnerClasses()[0];
    PsiClass innerClass13 = innerClass12.getInnerClasses()[0];
    PsiClass innerClass14 = innerClass13.getInnerClasses()[0];
    PsiClass innerClass15 = innerClass14.getInnerClasses()[0];
    PsiClass innerClass2 = aClass.getInnerClasses()[1];
    PsiClass innerClass21 = innerClass2.getInnerClasses()[0];
    PsiClass innerClass23 = innerClass21.getInnerClasses()[0];
    PsiClass innerClass24 = innerClass23.getInnerClasses()[0];
    PsiField innerClass1Field = innerClass14.getFields()[0];
    PsiField innerClass2Field = innerClass24.getFields()[0];
    final AbstractProjectViewPSIPane pane = myStructure.createPane();
    myStructure.checkNavigateFromSourceBehaviour(innerClass2Field, innerClass2Field.getContainingFile().getVirtualFile(), pane);
    IdeaTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" + " -PsiDirectory: showClassMembers\n" + "  -PsiDirectory: src\n" + "   -PsiDirectory: com\n" + "    -PsiDirectory: package1\n" + "     +Class1\n" + "     -Class2\n" + "      +InnerClass1\n" + "      -InnerClass2\n" + "       -InnerClass22\n" + "        -InnerClass23\n" + "         -InnerClass24\n" + "          +InnerClass25\n" + "          myFieldToSelect:int\n" + "         myInnerClassField:int\n" + "        myInnerClassField:int\n" + "       myInnerClassField:int\n" + "      getValue():int\n" + "      myField1:boolean\n" + "      myField2:boolean\n" + "      myField3:boolean\n" + "      myField4:boolean\n" + getRootFiles() + " +External Libraries\n");
    assertFalse(ProjectViewTestUtil.isExpanded(innerClass15.getFields()[0], pane));
    assertFalse(ProjectViewTestUtil.isExpanded(innerClass1Field, pane));
    assertTrue(ProjectViewTestUtil.isExpanded(innerClass2Field, pane));
    VirtualFile virtualFile = aClass.getContainingFile().getVirtualFile();
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
    StructureViewComponent structureViewComponent2 = null;
    StructureViewComponent structureViewComponent = null;
    try {
        structureViewComponent = (StructureViewComponent) fileEditors[0].getStructureViewBuilder().createStructureView(fileEditors[0], myProject);
        TreeUtil.collapseAll(structureViewComponent.getTree(), -1);
        structureViewComponent.select(innerClass2Field, true);
        String expected = "-Class2.java\n" + " -Class2\n" + "  +InnerClass1\n" + "  -InnerClass2\n" + "   -InnerClass22\n" + "    -InnerClass23\n" + "     -InnerClass24\n" + "      +InnerClass25\n" + "      myFieldToSelect: int\n" + "     myInnerClassField: int\n" + "    myInnerClassField: int\n" + "   myInnerClassField: int\n" + "  getValue(): int\n" + "  myField1: boolean\n" + "  myField2: boolean\n" + "  myField3: boolean\n" + "  myField4: boolean\n";
        IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), expected);
        Disposer.dispose(structureViewComponent);
        final FileEditor fileEditor = fileEditors[0];
        structureViewComponent2 = (StructureViewComponent) fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
        structureViewComponent2.setActionActive(JavaInheritedMembersNodeProvider.ID, false);
        IdeaTestUtil.assertTreeEqual(structureViewComponent2.getTree(), expected);
    } finally {
        fileEditorManager.closeFile(virtualFile);
        if (structureViewComponent2 != null) {
            Disposer.dispose(structureViewComponent2);
        }
    }
}
Also used : AbstractProjectViewPSIPane(com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent)

Example 2 with AbstractProjectViewPSIPane

use of com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane in project intellij-community by JetBrains.

the class ProjectViewUpdatingTest method testShowClassMembers.

public void testShowClassMembers() throws Exception {
    getProjectTreeStructure().setProviders(new ClassesTreeStructureProvider(myProject), new FormMergerTreeStructureProvider(myProject));
    final AbstractProjectViewPSIPane pane = myStructure.createPane();
    final JTree tree = pane.getTree();
    PlatformTestUtil.assertTreeEqual(tree, "-Project\n" + " +PsiDirectory: showClassMembers\n" + getRootFiles() + " +External Libraries\n");
    myStructure.setShowMembers(true);
    PsiJavaFile classFile = (PsiJavaFile) getContentDirectory().findSubdirectory("src").findSubdirectory("com").findSubdirectory("package1").findFile("Class1.java");
    PsiClass aClass = classFile.getClasses()[0];
    PsiFile containingFile = aClass.getContainingFile();
    pane.select(aClass, containingFile.getVirtualFile(), true);
    PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" + " -PsiDirectory: showClassMembers\n" + "  -PsiDirectory: src\n" + "   -PsiDirectory: com\n" + "    -PsiDirectory: package1\n" + "     -[Class1]\n" + "      +InnerClass\n" + "      getValue():int\n" + "      myField1:boolean\n" + "      myField2:boolean\n" + "     +Class2\n" + getRootFiles() + " +External Libraries\n", true);
    final Document document = FileDocumentManager.getInstance().getDocument(containingFile.getVirtualFile());
    final int caretPosition = document.getText().indexOf("public class InnerClass") - 1;
    ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().executeCommand(myProject, () -> document.insertString(caretPosition, "\n"), "typing", null));
    PsiDocumentManager.getInstance(myProject).commitDocument(document);
    PlatformTestUtil.waitForAlarm(600);
    PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" + " -PsiDirectory: showClassMembers\n" + "  -PsiDirectory: src\n" + "   -PsiDirectory: com\n" + "    -PsiDirectory: package1\n" + "     -[Class1]\n" + "      +InnerClass\n" + "      getValue():int\n" + "      myField1:boolean\n" + "      myField2:boolean\n" + "     +Class2\n" + getRootFiles() + " +External Libraries\n", true);
    classFile = (PsiJavaFile) getContentDirectory().findSubdirectory("src").findSubdirectory("com").findSubdirectory("package1").findFile("Class1.java");
    aClass = classFile.getClasses()[0];
    final PsiField lastField = aClass.getFields()[1];
    pane.select(lastField, containingFile.getVirtualFile(), true);
    PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" + " -PsiDirectory: showClassMembers\n" + "  -PsiDirectory: src\n" + "   -PsiDirectory: com\n" + "    -PsiDirectory: package1\n" + "     -Class1\n" + "      +InnerClass\n" + "      getValue():int\n" + "      myField1:boolean\n" + "      [myField2:boolean]\n" + "     +Class2\n" + getRootFiles() + " +External Libraries\n", true);
    CommandProcessor.getInstance().executeCommand(myProject, () -> ApplicationManager.getApplication().runWriteAction(() -> {
        try {
            assertEquals("myField2", lastField.getName());
            lastField.setName("_firstField");
        } catch (IncorrectOperationException e) {
            fail(e.getMessage());
        }
    }), null, null);
    PlatformTestUtil.waitForAlarm(600);
    PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" + " -PsiDirectory: showClassMembers\n" + "  -PsiDirectory: src\n" + "   -PsiDirectory: com\n" + "    -PsiDirectory: package1\n" + "     -Class1\n" + "      +InnerClass\n" + "      getValue():int\n" + "      [_firstField:boolean]\n" + "      myField1:boolean\n" + "     +Class2\n" + getRootFiles() + " +External Libraries\n", true);
}
Also used : AbstractProjectViewPSIPane(com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane) ClassesTreeStructureProvider(com.intellij.ide.projectView.impl.ClassesTreeStructureProvider) IncorrectOperationException(com.intellij.util.IncorrectOperationException) FormMergerTreeStructureProvider(com.intellij.uiDesigner.projectView.FormMergerTreeStructureProvider) Document(com.intellij.openapi.editor.Document)

Example 3 with AbstractProjectViewPSIPane

use of com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane in project intellij-community by JetBrains.

the class ProjectViewUpdatingTest method testStandardProviders.

public void testStandardProviders() throws Exception {
    PsiFile element = JavaDirectoryService.getInstance().getClasses(getPackageDirectory())[0].getContainingFile();
    final AbstractProjectViewPSIPane pane = myStructure.createPane();
    getProjectTreeStructure().setProviders();
    pane.select(element, element.getContainingFile().getVirtualFile(), true);
    PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" + " -PsiDirectory: standardProviders\n" + "  -PsiDirectory: src\n" + "   -PsiDirectory: com\n" + "    -PsiDirectory: package1\n" + "     Class1.java\n" + "     Class2.java\n" + "     Class4.java\n" + "     Form1.form\n" + "     Form1.java\n" + "     Form2.form\n" + getRootFiles() + " +External Libraries\n");
    final PsiClass[] classes = JavaDirectoryService.getInstance().getPackage(getContentDirectory().findSubdirectory("src").findSubdirectory("com").findSubdirectory("package1")).getClasses();
    sortClassesByName(classes);
    WriteCommandAction.runWriteCommandAction(null, () -> classes[0].delete());
    PlatformTestUtil.waitForAlarm(600);
    PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" + " -PsiDirectory: standardProviders\n" + "  -PsiDirectory: src\n" + "   -PsiDirectory: com\n" + "    -PsiDirectory: package1\n" + "     Class2.java\n" + "     Class4.java\n" + "     Form1.form\n" + "     Form1.java\n" + "     Form2.form\n" + getRootFiles() + " +External Libraries\n");
}
Also used : AbstractProjectViewPSIPane(com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane)

Example 4 with AbstractProjectViewPSIPane

use of com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane in project intellij-community by JetBrains.

the class ProjectViewUpdatingTest method testUpdatingAfterRename.

public void testUpdatingAfterRename() throws Exception {
    final NodeWrapper rootWrapper = new NodeWrapper(myProject, "1");
    final NodeWrapper wr11 = new NodeWrapper(myProject, "1.1");
    final NodeWrapper wr12 = new NodeWrapper(myProject, "1.2");
    final NodeWrapper wr13 = new NodeWrapper(myProject, "1.3");
    final NodeWrapper wr111 = new NodeWrapper(myProject, "1.1.1");
    final NodeWrapper wr112 = new NodeWrapper(myProject, "1.1.2");
    final NodeWrapper wr113 = new NodeWrapper(myProject, "1.1.3");
    final NodeWrapper wr121 = new NodeWrapper(myProject, "1.2.1");
    final NodeWrapper wr122 = new NodeWrapper(myProject, "1.2.2");
    final NodeWrapper wr123 = new NodeWrapper(myProject, "1.2.3");
    final NodeWrapper wr131 = new NodeWrapper(myProject, "1.3.1");
    final NodeWrapper wr132 = new NodeWrapper(myProject, "1.3.2");
    final NodeWrapper wr133 = new NodeWrapper(myProject, "1.3.3");
    rootWrapper.addChild(wr11);
    rootWrapper.addChild(wr12);
    rootWrapper.addChild(wr13);
    wr11.addChild(wr111);
    wr11.addChild(wr112);
    wr11.addChild(wr113);
    wr12.addChild(wr121);
    wr12.addChild(wr122);
    wr12.addChild(wr123);
    wr13.addChild(wr131);
    wr13.addChild(wr132);
    wr13.addChild(wr133);
    getProjectTreeStructure().setProviders(createWrapProvider(rootWrapper));
    final AbstractProjectViewPSIPane pane = myStructure.createPane();
    final JTree tree = pane.getTree();
    pane.getTreeBuilder().setNodeDescriptorComparator((o1, o2) -> {
        if (o1 instanceof NodeWrapper && o2 instanceof NodeWrapper) {
            return ((NodeWrapper) o1).getName().compareTo(((NodeWrapper) o2).getName());
        } else {
            return 0;
        }
    });
    tree.expandRow(2);
    TreeUtil.selectPath(tree, tree.getPathForRow(4));
    PlatformTestUtil.assertTreeEqual(tree, "-Project\n" + " -1\n" + "  +1.1\n" + "  -1.2\n" + "   1.2.1\n" + "   [1.2.2]\n" + "   1.2.3\n" + "  +1.3\n", true);
    wr12.setName("01.2");
    wr122.setName("01.2.2");
    pane.getTreeBuilder().updateFromRoot();
    PlatformTestUtil.assertTreeEqual(tree, "-Project\n" + " -1\n" + "  -01.2\n" + "   [01.2.2]\n" + "   1.2.1\n" + "   1.2.3\n" + "  +1.1\n" + "  +1.3\n", true);
}
Also used : AbstractProjectViewPSIPane(com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane)

Example 5 with AbstractProjectViewPSIPane

use of com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane in project intellij-community by JetBrains.

the class ProjectViewUpdatingTest method testAnnoyingScrolling.

public void testAnnoyingScrolling() throws Exception {
    getProjectTreeStructure().setProviders(new ClassesTreeStructureProvider(myProject));
    final AbstractProjectViewPSIPane pane = myStructure.createPane();
    final JTree tree = pane.getTree();
    myStructure.setShowMembers(true);
    PsiJavaFile classFile = (PsiJavaFile) getContentDirectory().findSubdirectory("src").findSubdirectory("com").findSubdirectory("package1").findFile("Class1.java");
    PsiClass aClass = classFile.getClasses()[0];
    PsiFile containingFile = aClass.getContainingFile();
    PsiDirectory directory = containingFile.getContainingDirectory();
    pane.select(aClass, containingFile.getVirtualFile(), true);
    Point viewPosition = ((JViewport) tree.getParent()).getViewPosition();
    for (int i = 0; i < 100; i++) {
        JavaDirectoryService.getInstance().createClass(directory, "A" + i);
    }
    PlatformTestUtil.waitForAlarm(600);
    Point viewPositionAfter = ((JViewport) tree.getParent()).getViewPosition();
    assertEquals(viewPosition, viewPositionAfter);
}
Also used : AbstractProjectViewPSIPane(com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane) ClassesTreeStructureProvider(com.intellij.ide.projectView.impl.ClassesTreeStructureProvider)

Aggregations

AbstractProjectViewPSIPane (com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane)15 ClassesTreeStructureProvider (com.intellij.ide.projectView.impl.ClassesTreeStructureProvider)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiClass (com.intellij.psi.PsiClass)2 PsiFile (com.intellij.psi.PsiFile)2 FormMergerTreeStructureProvider (com.intellij.uiDesigner.projectView.FormMergerTreeStructureProvider)2 GroupByTypeComparator (com.intellij.ide.projectView.impl.GroupByTypeComparator)1 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)1 ResourceBundleGrouper (com.intellij.lang.properties.projectView.ResourceBundleGrouper)1 Document (com.intellij.openapi.editor.Document)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiField (com.intellij.psi.PsiField)1 RenameProcessor (com.intellij.refactoring.rename.RenameProcessor)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1