Search in sources :

Example 21 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class StructureViewUpdatingTest method testExpandElementWithExitingName.

public void testExpandElementWithExitingName() throws InterruptedException {
    final VirtualFile xmlVirtualFile = getContentRoot().findFileByRelativePath("test.xml");
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    FileEditor[] fileEditors = fileEditorManager.openFile(xmlVirtualFile, false);
    final FileEditor fileEditor = fileEditors[0];
    try {
        final StructureViewComponent structureViewComponent = (StructureViewComponent) fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
        final JTree tree = structureViewComponent.getTree();
        PlatformTestUtil.assertTreeEqual(tree, "-test.xml\n" + " -test\n" + "  +level1\n" + "  +level1\n" + "  +level1\n" + "  +level1\n");
        tree.expandPath(tree.getPathForRow(3));
        PlatformTestUtil.waitForAlarm(600);
        PlatformTestUtil.assertTreeEqual(tree, "-test.xml\n" + " -test\n" + "  +level1\n" + "  -level1\n" + "   +level2\n" + "  +level1\n" + "  +level1\n");
        Disposer.dispose(structureViewComponent);
    } finally {
        fileEditorManager.closeFile(xmlVirtualFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent)

Example 22 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class StructureViewUpdatingTest method testShowClassMembers.

public void testShowClassMembers() 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];
    final StructureViewComponent structureViewComponent = (StructureViewComponent) fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
    try {
        PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + " -Class2\n" + "  +InnerClass1\n" + "  +InnerClass2\n" + "  getValue(): int\n" + "  myField1: boolean\n" + "  myField2: boolean\n" + "  myField3: boolean\n" + "  myField4: boolean\n");
        final PsiField innerClassField = psiClass.getInnerClasses()[0].getFields()[0];
        structureViewComponent.select(innerClassField, true);
        PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + " -Class2\n" + "  -InnerClass1\n" + "   +InnerClass12\n" + "   myInnerClassField: int\n" + "  +InnerClass2\n" + "  getValue(): int\n" + "  myField1: boolean\n" + "  myField2: boolean\n" + "  myField3: boolean\n" + "  myField4: boolean\n");
        CommandProcessor.getInstance().executeCommand(myProject, () -> WriteCommandAction.runWriteCommandAction(null, () -> {
            try {
                innerClassField.delete();
            } catch (IncorrectOperationException e) {
                fail(e.getLocalizedMessage());
            }
        }), null, null);
        PlatformTestUtil.waitForAlarm(600);
        PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + " -Class2\n" + "  -InnerClass1\n" + "   +InnerClass12\n" + "  +InnerClass2\n" + "  getValue(): int\n" + "  myField1: boolean\n" + "  myField2: boolean\n" + "  myField3: boolean\n" + "  myField4: boolean\n");
    } finally {
        Disposer.dispose(structureViewComponent);
        fileEditorManager.closeFile(virtualFile);
    }
}
Also used : 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) IncorrectOperationException(com.intellij.util.IncorrectOperationException) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent)

Example 23 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager 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 24 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager 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 25 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class EditorFixture method moveToAndClick.

/**
   * Moves the caret to the given caret offset (0-based).
   *
   * @param offset the character offset.
   */
public EditorFixture moveToAndClick(final int offset, MouseButton button) {
    assertThat(offset).isGreaterThanOrEqualTo(0);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
            Editor editor = manager.getSelectedTextEditor();
            assert editor != null;
            VisualPosition visualPosition = editor.offsetToVisualPosition(offset);
            Point point = editor.visualPositionToXY(visualPosition);
            Component editorComponent = robot.finder().find(editor.getComponent(), component -> component instanceof EditorComponentImpl);
            robot.click(editorComponent, point, button, 1);
        }
    });
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Condition(org.fest.swing.timing.Condition) GuiQuery(org.fest.swing.edt.GuiQuery) KeymapManager(com.intellij.openapi.keymap.KeymapManager) ComponentDriver(org.fest.swing.driver.ComponentDriver) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) com.intellij.openapi.editor(com.intellij.openapi.editor) GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) MouseButton(org.fest.swing.core.MouseButton) GuiActionRunner.execute(org.fest.swing.edt.GuiActionRunner.execute) Strings.quote(org.fest.util.Strings.quote) Keymap(com.intellij.openapi.keymap.Keymap) ArrayList(java.util.ArrayList) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Reflection.method(org.fest.reflect.core.Reflection.method) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) Project(com.intellij.openapi.project.Project) TextHitInfo(java.awt.font.TextHitInfo) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) JBList(com.intellij.ui.components.JBList) FocusManager(javax.swing.FocusManager) GuiTestUtil(com.intellij.testGuiFramework.framework.GuiTestUtil) TextRange(com.intellij.openapi.util.TextRange) AttributedString(java.text.AttributedString) KeyEvent(java.awt.event.KeyEvent) FileEditor(com.intellij.openapi.fileEditor.FileEditor) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) DialogFixture(org.fest.swing.fixture.DialogFixture) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) InputMethodEvent(java.awt.event.InputMethodEvent) AttributedCharacterIterator(java.text.AttributedCharacterIterator) GuiTask(org.fest.swing.edt.GuiTask) Pause.pause(org.fest.swing.timing.Pause.pause) EditorComponentImpl(com.intellij.openapi.editor.impl.EditorComponentImpl) Robot(org.fest.swing.core.Robot) NotNull(org.jetbrains.annotations.NotNull) Assert(org.junit.Assert) Ref(com.intellij.openapi.util.Ref) javax.swing(javax.swing) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) EditorComponentImpl(com.intellij.openapi.editor.impl.EditorComponentImpl) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Aggregations

FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)66 VirtualFile (com.intellij.openapi.vfs.VirtualFile)35 FileEditor (com.intellij.openapi.fileEditor.FileEditor)29 Editor (com.intellij.openapi.editor.Editor)22 Project (com.intellij.openapi.project.Project)21 TextEditor (com.intellij.openapi.fileEditor.TextEditor)12 PsiFile (com.intellij.psi.PsiFile)10 Document (com.intellij.openapi.editor.Document)9 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)9 Nullable (org.jetbrains.annotations.Nullable)8 TextRange (com.intellij.openapi.util.TextRange)6 NotNull (org.jetbrains.annotations.NotNull)6 FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)5 PsiElement (com.intellij.psi.PsiElement)5 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 GuiTask (org.fest.swing.edt.GuiTask)4 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)3 ResourceBundleAsVirtualFile (com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)3 PsiClass (com.intellij.psi.PsiClass)3