mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
project view tests partially moved to community
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package com.intellij.projectView;
|
||||
|
||||
import com.intellij.ide.projectView.PresentationData;
|
||||
import com.intellij.ide.projectView.ProjectViewNode;
|
||||
import com.intellij.ide.projectView.TreeStructureProvider;
|
||||
import com.intellij.ide.projectView.ViewSettings;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
class ClassNameConvertor implements TreeStructureProvider {
|
||||
|
||||
private final Project myProject;
|
||||
|
||||
public ClassNameConvertor(Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
public Collection<AbstractTreeNode> modify(AbstractTreeNode parent, Collection<AbstractTreeNode> children, ViewSettings settings) {
|
||||
ArrayList<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
|
||||
|
||||
for (final AbstractTreeNode aChildren : children) {
|
||||
ProjectViewNode treeNode = (ProjectViewNode)aChildren;
|
||||
Object o = treeNode.getValue();
|
||||
if (o instanceof PsiFile && ((PsiFile)o).getVirtualFile().getExtension().equals("java")) {
|
||||
final String name = ((PsiFile)o).getName();
|
||||
ProjectViewNode viewNode = new ProjectViewNode<PsiFile>(myProject, (PsiFile)o, settings) {
|
||||
@NotNull
|
||||
public Collection<AbstractTreeNode> getChildren() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public String getTestPresentation() {
|
||||
return name + " converted";
|
||||
}
|
||||
|
||||
public boolean contains(@NotNull VirtualFile file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void update(PresentationData presentation) {
|
||||
}
|
||||
|
||||
};
|
||||
result.add(viewNode);
|
||||
}
|
||||
else {
|
||||
result.add(treeNode);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Object getData(Collection<AbstractTreeNode> selected, String dataName) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2004 JetBrains s.r.o. All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* -Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* -Redistribution in binary form must reproduct the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of JetBrains or IntelliJ IDEA
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* This software is provided "AS IS," without a warranty of any kind. ALL
|
||||
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
|
||||
* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. JETBRAINS AND ITS LICENSORS SHALL NOT
|
||||
* BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
|
||||
* OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
|
||||
* DERIVATIVES. IN NO EVENT WILL JETBRAINS OR ITS LICENSORS BE LIABLE FOR ANY LOST
|
||||
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
|
||||
* INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
|
||||
* OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
|
||||
* IF JETBRAINS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
*/
|
||||
package com.intellij.projectView;
|
||||
|
||||
import com.intellij.ide.actions.ViewStructureAction;
|
||||
import com.intellij.ide.commander.CommanderPanel;
|
||||
import com.intellij.ide.structureView.StructureViewBuilder;
|
||||
import com.intellij.ide.structureView.StructureViewModel;
|
||||
import com.intellij.ide.structureView.TreeBasedStructureViewBuilder;
|
||||
import com.intellij.ide.util.FileStructureDialog;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.JavaDirectoryService;
|
||||
import com.intellij.psi.PsiClass;
|
||||
|
||||
public class FileStructureDialogTest extends BaseProjectViewTestCase {
|
||||
public void testFileStructureForClass() throws Exception {
|
||||
final PsiClass psiClass = JavaDirectoryService.getInstance().getPackage(getPackageDirectory()).getClasses()[0];
|
||||
final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
|
||||
final StructureViewBuilder structureViewBuilder =
|
||||
StructureViewBuilder.PROVIDER.getStructureViewBuilder(virtualFile.getFileType(), virtualFile, myProject);
|
||||
final StructureViewModel structureViewModel = ((TreeBasedStructureViewBuilder)structureViewBuilder).createStructureViewModel();
|
||||
|
||||
Editor editor = null;
|
||||
FileStructureDialog dialog = null;
|
||||
try {
|
||||
editor = EditorFactory.getInstance().createEditor(FileDocumentManager.getInstance().getDocument(virtualFile));
|
||||
dialog = ViewStructureAction.createStructureViewBasedDialog(structureViewModel, editor, myProject, psiClass, new Disposable() {
|
||||
public void dispose() {
|
||||
structureViewModel.dispose();
|
||||
}
|
||||
});
|
||||
final CommanderPanel panel = dialog.getPanel();
|
||||
assertListsEqual(panel.getModel(), "Inner1\n" + "Inner2\n" + "__method():void\n" + "_myField1:int\n" + "_myField2:String\n");
|
||||
}
|
||||
finally {
|
||||
if (dialog != null) dialog.close(0);
|
||||
if (editor != null) EditorFactory.getInstance().releaseEditor(editor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright (c) 2004 JetBrains s.r.o. All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* -Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* -Redistribution in binary form must reproduct the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of JetBrains or IntelliJ IDEA
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* This software is provided "AS IS," without a warranty of any kind. ALL
|
||||
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
|
||||
* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. JETBRAINS AND ITS LICENSORS SHALL NOT
|
||||
* BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
|
||||
* OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
|
||||
* DERIVATIVES. IN NO EVENT WILL JETBRAINS OR ITS LICENSORS BE LIABLE FOR ANY LOST
|
||||
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
|
||||
* INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
|
||||
* OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
|
||||
* IF JETBRAINS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
*/
|
||||
package com.intellij.projectView;
|
||||
|
||||
import com.intellij.ide.structureView.impl.java.InheritedMembersFilter;
|
||||
import com.intellij.ide.structureView.impl.java.PublicElementsFilter;
|
||||
import com.intellij.ide.structureView.impl.java.VisibilitySorter;
|
||||
import com.intellij.ide.structureView.newStructureView.StructureViewComponent;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.JavaDirectoryService;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.testFramework.TestSourceBasedTestCase;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class JavaTreeStructureTest extends TestSourceBasedTestCase {
|
||||
protected String getTestPath() {
|
||||
return "structureView";
|
||||
}
|
||||
|
||||
public void testJavaClassStructure() throws Exception {
|
||||
dotest(new CheckAction() {
|
||||
public void testClassStructure(StructureViewComponent structureViewComponent) {
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" +
|
||||
" -Class1\n" +
|
||||
" getValue():int\n" +
|
||||
" hashCode():int\n" +
|
||||
" finalize():void\n" +
|
||||
" notify():void\n" +
|
||||
" notifyAll():void\n" +
|
||||
" wait():void\n" +
|
||||
" wait(long):void\n" +
|
||||
" wait(long, int):void\n" +
|
||||
" getClass():Class\n" +
|
||||
" clone():Object\n" +
|
||||
" equals(Object):boolean\n" +
|
||||
" toString():String\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n");
|
||||
|
||||
structureViewComponent.setActionActive(InheritedMembersFilter.ID, true);
|
||||
structureViewComponent.setActionActive(InheritedMembersFilter.ID, false);
|
||||
structureViewComponent.setActionActive(InheritedMembersFilter.ID, true);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" +
|
||||
" -Class1\n" +
|
||||
" getValue():int\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n");
|
||||
|
||||
structureViewComponent.setActionActive(PublicElementsFilter.ID, true);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" +
|
||||
" -Class1\n" +
|
||||
" getValue():int\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n");
|
||||
|
||||
structureViewComponent.setActionActive(PublicElementsFilter.ID, false);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" +
|
||||
" -Class1\n" +
|
||||
" getValue():int\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testShowClassMembers() throws Exception {
|
||||
dotest(new CheckAction() {
|
||||
public void testClassStructure(StructureViewComponent structureViewComponent) {
|
||||
final JTree tree = structureViewComponent.getTree();
|
||||
tree.collapseRow(2);
|
||||
IdeaTestUtil.assertTreeEqual(tree, "-Class2.java\n" +
|
||||
" -Class2\n" +
|
||||
" +InnerClass1\n" +
|
||||
" +InnerClass2\n" +
|
||||
" getValue():int\n" +
|
||||
" hashCode():int\n" +
|
||||
" finalize():void\n" +
|
||||
" notify():void\n" +
|
||||
" notifyAll():void\n" +
|
||||
" wait():void\n" +
|
||||
" wait(long):void\n" +
|
||||
" wait(long, int):void\n" +
|
||||
" getClass():Class\n" +
|
||||
" clone():Object\n" +
|
||||
" equals(Object):boolean\n" +
|
||||
" toString():String\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n" +
|
||||
" myField3:boolean\n" +
|
||||
" myField4:boolean\n");
|
||||
|
||||
structureViewComponent.setActionActive(InheritedMembersFilter.ID, true);
|
||||
|
||||
IdeaTestUtil.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");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void _testVisibilitySorter() throws Exception {
|
||||
dotest(new CheckAction() {
|
||||
public void testClassStructure(StructureViewComponent structureViewComponent) {
|
||||
structureViewComponent.setActionActive(InheritedMembersFilter.ID, true);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
|
||||
" -Class2\n" +
|
||||
" __myPrivateFiield:int\n" +
|
||||
" _myProtectedField:int\n" +
|
||||
" myPublicField:int\n");
|
||||
|
||||
structureViewComponent.setActionActive(VisibilitySorter.ID, true);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
|
||||
" -Class2\n" +
|
||||
" myPublicField:int\n" +
|
||||
" _myProtectedField:int\n" +
|
||||
" __myPrivateFiield:int\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testMembersOrder() throws Exception {
|
||||
dotest(new CheckAction() {
|
||||
public void testClassStructure(StructureViewComponent structureViewComponent) {
|
||||
structureViewComponent.setActionActive(InheritedMembersFilter.ID, true);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
|
||||
" -Class2\n" +
|
||||
" Class2()\n" +
|
||||
" af():void\n" +
|
||||
" zf():void\n" +
|
||||
" ab:int\n" +
|
||||
" z:int\n"
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
interface CheckAction {
|
||||
void testClassStructure(StructureViewComponent structureViewComponent);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2004 JetBrains s.r.o. All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* -Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* -Redistribution in binary form must reproduct the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of JetBrains or IntelliJ IDEA
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* This software is provided "AS IS," without a warranty of any kind. ALL
|
||||
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
|
||||
* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. JETBRAINS AND ITS LICENSORS SHALL NOT
|
||||
* BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
|
||||
* OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
|
||||
* DERIVATIVES. IN NO EVENT WILL JETBRAINS OR ITS LICENSORS BE LIABLE FOR ANY LOST
|
||||
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
|
||||
* INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
|
||||
* OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
|
||||
* IF JETBRAINS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
*/
|
||||
package com.intellij.projectView;
|
||||
|
||||
import com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.JavaDirectoryService;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiJavaFile;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
public class NavigateFromSourceTest extends BaseProjectViewTestCase {
|
||||
public void testShowClassMembers() throws Exception {
|
||||
useStandardProviders();
|
||||
PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory())[0];
|
||||
|
||||
final AbstractProjectViewPSIPane pane = createPane();
|
||||
final PsiFile containingFile = psiClass.getContainingFile();
|
||||
final VirtualFile virtualFile = containingFile.getVirtualFile();
|
||||
|
||||
checkNavigateFromSourceBehaviour(psiClass, virtualFile, pane);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" +
|
||||
" -PsiDirectory: showClassMembers\n" +
|
||||
" -PsiDirectory: src\n" +
|
||||
" -PsiDirectory: com\n" +
|
||||
" -PsiDirectory: package1\n" +
|
||||
" [Class1]\n" +
|
||||
" Class2\n" +
|
||||
getRootFiles() +
|
||||
" +External Libraries\n"
|
||||
, true);
|
||||
|
||||
changeClassTextAndTryToNavigate("class Class11 {}", (PsiJavaFile)containingFile, pane, "-Project\n" +
|
||||
" -PsiDirectory: showClassMembers\n" +
|
||||
" -PsiDirectory: src\n" +
|
||||
" -PsiDirectory: com\n" +
|
||||
" -PsiDirectory: package1\n" +
|
||||
" [Class11]\n" +
|
||||
" Class2\n" +
|
||||
getRootFiles() +
|
||||
" +External Libraries\n");
|
||||
|
||||
changeClassTextAndTryToNavigate("class Class1 {}", (PsiJavaFile)containingFile, pane, "-Project\n" +
|
||||
" -PsiDirectory: showClassMembers\n" +
|
||||
" -PsiDirectory: src\n" +
|
||||
" -PsiDirectory: com\n" +
|
||||
" -PsiDirectory: package1\n" +
|
||||
" [Class1]\n" +
|
||||
" Class2\n" +
|
||||
getRootFiles() +
|
||||
" +External Libraries\n");
|
||||
|
||||
doTestMultipleSelection(pane, ((PsiJavaFile)containingFile).getClasses()[0]);
|
||||
}
|
||||
|
||||
private static void doTestMultipleSelection(final AbstractProjectViewPSIPane pane, final PsiClass psiClass) {
|
||||
JTree tree = pane.getTree();
|
||||
int rowCount = tree.getRowCount();
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
tree.addSelectionRow(i);
|
||||
}
|
||||
|
||||
pane.select(psiClass, psiClass.getContainingFile().getVirtualFile(), true);
|
||||
|
||||
assertEquals(1, tree.getSelectionCount());
|
||||
}
|
||||
|
||||
private void changeClassTextAndTryToNavigate(final String newClassString,
|
||||
PsiJavaFile psiFile,
|
||||
final AbstractProjectViewPSIPane pane,
|
||||
final String expected) throws IOException, InterruptedException {
|
||||
PsiClass psiClass = psiFile.getClasses()[0];
|
||||
final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
|
||||
final JTree tree = pane.getTree();
|
||||
writeToFile(virtualFile, newClassString.getBytes());
|
||||
|
||||
IdeaTestUtil.waitForAlarm(600);
|
||||
|
||||
pane.select(psiClass, virtualFile, true);
|
||||
IdeaTestUtil.assertTreeEqual(tree, expected, true);
|
||||
}
|
||||
|
||||
private static void writeToFile(final VirtualFile virtualFile, final byte[] b) throws IOException {
|
||||
virtualFile.setBinaryContent(b);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.intellij.projectView;
|
||||
|
||||
import com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane;
|
||||
import com.intellij.ide.structureView.impl.java.InheritedMembersFilter;
|
||||
import com.intellij.ide.structureView.newStructureView.StructureViewComponent;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.JavaDirectoryService;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ProjectTreeBuilderTest extends BaseProjectViewTestCase {
|
||||
public void testStandardProviders() throws Exception {
|
||||
getProjectTreeStructure().setProviders();
|
||||
|
||||
final PsiClass aClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory())[0];
|
||||
|
||||
PsiFile element = aClass.getContainingFile();
|
||||
|
||||
checkNavigateFromSourceBehaviour(element, element.getVirtualFile(), createPane());
|
||||
}
|
||||
|
||||
public void testShowClassMembers() throws IncorrectOperationException, IOException {
|
||||
myShowMembers = true;
|
||||
useStandardProviders();
|
||||
PsiClass aClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory())[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 = createPane();
|
||||
|
||||
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(isExpanded(innerClass15.getFields()[0], pane));
|
||||
assertFalse(isExpanded(innerClass1Field, pane));
|
||||
assertTrue(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);
|
||||
structureViewComponent.setActionActive(InheritedMembersFilter.ID, true);
|
||||
|
||||
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(InheritedMembersFilter.ID, true);
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent2.getTree(), expected);
|
||||
}
|
||||
finally {
|
||||
fileEditorManager.closeFile(virtualFile);
|
||||
if (structureViewComponent2 != null) {
|
||||
Disposer.dispose(structureViewComponent2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.intellij.projectView;
|
||||
|
||||
public class ProjectTreeStructureTest extends BaseProjectViewTestCase {
|
||||
|
||||
public void test1() {
|
||||
getProjectTreeStructure().setProviders(new SameNamesJoiner(), new ClassNameConvertor(myProject));
|
||||
assertStructureEqual(getPackageDirectory(), "PsiDirectory: package1\n" +
|
||||
" Class2.java converted\n" +
|
||||
" Form1 joined\n" +
|
||||
" Form1.java converted\n" +
|
||||
" PsiFile(plain text):Form1.form\n" +
|
||||
" PsiFile(plain text):Form2.form\n");
|
||||
}
|
||||
|
||||
public void testStandardProviders() {
|
||||
useStandardProviders();
|
||||
|
||||
assertStructureEqual(getPackageDirectory(), "PsiDirectory: package1\n" +
|
||||
" PsiClass:Class1\n" +
|
||||
" PsiClass:Form1\n" +
|
||||
" PsiFile(plain text):Form1.form\n" +
|
||||
" PsiFile(plain text):Form2.form\n" +
|
||||
" PsiJavaFile:Class2.java\n" +
|
||||
" PsiClass:Class2\n" +
|
||||
" PsiClass:Class3\n" +
|
||||
" PsiJavaFile:Class4.java\n");
|
||||
assertStructureEqual("Project\n" +
|
||||
" External Libraries\n" +
|
||||
" Library: < java 1.4 >\n" +
|
||||
" PsiDirectory: jsp-api.jar\n" +
|
||||
" PsiDirectory: META-INF\n" +
|
||||
" PsiFile(plain text):MANIFEST.MF\n" +
|
||||
" PsiDirectory: javax\n" +
|
||||
" PsiDirectory: servlet\n" +
|
||||
" PsiDirectory: jsp\n" +
|
||||
" PsiClass:ErrorData\n" +
|
||||
" PsiClass:HttpJspPage\n" +
|
||||
" PsiClass:JspContext\n" +
|
||||
" PsiClass:JspEngineInfo\n" +
|
||||
" PsiClass:JspException\n" +
|
||||
" PsiClass:JspFactory\n" +
|
||||
" PsiClass:JspPage\n" +
|
||||
" PsiClass:JspTagException\n"
|
||||
);
|
||||
|
||||
getProjectTreeStructure().setProviders();
|
||||
|
||||
assertStructureEqual(getPackageDirectory(), "PsiDirectory: package1\n" +
|
||||
" PsiFile(plain text):Form1.form\n" +
|
||||
" PsiFile(plain text):Form2.form\n" +
|
||||
" PsiJavaFile:Class1.java\n" +
|
||||
" PsiJavaFile:Class2.java\n" +
|
||||
" PsiJavaFile:Class4.java\n" +
|
||||
" PsiJavaFile:Form1.java\n");
|
||||
|
||||
assertStructureEqual("Project\n" +
|
||||
" External Libraries\n" +
|
||||
" Library: < java 1.4 >\n" +
|
||||
" PsiDirectory: jsp-api.jar\n" +
|
||||
" PsiDirectory: META-INF\n" +
|
||||
" PsiFile(plain text):MANIFEST.MF\n" +
|
||||
" PsiDirectory: javax\n" +
|
||||
" PsiDirectory: servlet\n" +
|
||||
" PsiDirectory: jsp\n" +
|
||||
" PsiDirectory: el\n" +
|
||||
" PsiFile:ELException.class\n" +
|
||||
" PsiFile:ELParseException.class\n" +
|
||||
" PsiFile:Expression.class\n" +
|
||||
" PsiFile:ExpressionEvaluator.class\n" +
|
||||
" PsiFile:FunctionMapper.class\n" +
|
||||
" PsiFile:VariableResolver.class\n" +
|
||||
" PsiDirectory: resources\n");
|
||||
}
|
||||
|
||||
public void testShowClassMembers() {
|
||||
useStandardProviders();
|
||||
|
||||
myShowMembers = false;
|
||||
assertStructureEqual(getPackageDirectory(), "PsiDirectory: package1\n" +
|
||||
" PsiClass:Class1\n" +
|
||||
" PsiClass:Class2\n");
|
||||
|
||||
myShowMembers = true;
|
||||
assertStructureEqual(getPackageDirectory(), "PsiDirectory: package1\n" +
|
||||
" PsiClass:Class1\n" +
|
||||
" PsiClass:InnerClass\n" +
|
||||
" PsiField:myInnerClassField\n" +
|
||||
" PsiField:myField1\n" +
|
||||
" PsiField:myField2\n" +
|
||||
" PsiMethod:getValue\n" +
|
||||
" PsiClass:Class2\n" +
|
||||
" PsiClass:InnerClass1\n" +
|
||||
" PsiClass:InnerClass12\n" +
|
||||
" PsiClass:InnerClass13\n" +
|
||||
" PsiClass:InnerClass14\n" +
|
||||
" PsiClass:InnerClass15\n" +
|
||||
" PsiField:myInnerClassField\n" +
|
||||
" PsiField:myInnerClassField\n" +
|
||||
" PsiField:myInnerClassField\n" +
|
||||
" PsiField:myInnerClassField\n" +
|
||||
" PsiField:myInnerClassField\n" +
|
||||
" PsiClass:InnerClass2\n" +
|
||||
" PsiClass:InnerClass22\n" +
|
||||
" PsiClass:InnerClass23\n" +
|
||||
" PsiClass:InnerClass24\n" +
|
||||
" PsiClass:InnerClass25\n" +
|
||||
" PsiField:myInnerClassField\n" +
|
||||
" PsiField:myFieldToSelect\n" +
|
||||
" PsiField:myInnerClassField\n" +
|
||||
" PsiField:myInnerClassField\n" +
|
||||
" PsiField:myInnerClassField\n" +
|
||||
" PsiField:myField1\n" +
|
||||
" PsiField:myField2\n" +
|
||||
" PsiField:myField3\n" +
|
||||
" PsiField:myField4\n" +
|
||||
" PsiMethod:getValue\n", 100);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testGetParentObject(){
|
||||
useStandardProviders();
|
||||
myShowMembers = true;
|
||||
assertStructureEqual(getContentDirectory(), "PsiDirectory: getParentObject\n" +
|
||||
" PsiDirectory: src\n" +
|
||||
" PsiDirectory: com\n" +
|
||||
" PsiDirectory: package1\n" +
|
||||
" PsiClass:Class1\n" +
|
||||
" PsiField:myField\n" +
|
||||
" PsiMethod:method\n" +
|
||||
" PsiClass:Form1\n" +
|
||||
" PsiFile(plain text):Form1.form\n" +
|
||||
" PsiFile(plain text):Form2.form\n" +
|
||||
" PsiJavaFile:Class2.java\n" +
|
||||
" PsiClass:Class2\n" +
|
||||
" PsiClass:Class3\n" +
|
||||
" PsiJavaFile:Class4.java\n");
|
||||
|
||||
|
||||
checkContainsMethod(myStructure.getRootElement(), myStructure);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.intellij.projectView;
|
||||
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesProjectViewPane;
|
||||
import com.intellij.ide.projectView.ProjectView;
|
||||
import com.intellij.ide.projectView.impl.AbstractProjectViewPane;
|
||||
import com.intellij.ide.projectView.impl.ProjectViewImpl;
|
||||
import com.intellij.ide.projectView.impl.ProjectViewPane;
|
||||
import com.intellij.testFramework.TestSourceBasedTestCase;
|
||||
|
||||
public class ProjectViewSwitchingTest extends TestSourceBasedTestCase {
|
||||
protected String getTestPath() {
|
||||
return "projectView";
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
((ProjectViewImpl)ProjectView.getInstance(getProject())).setupImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runStartupActivities() {
|
||||
FavoritesManager.getInstance(getProject()).projectOpened();
|
||||
super.runStartupActivities();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
FavoritesManager.getInstance(getProject()).projectClosed();
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testSelectProject() {
|
||||
ProjectView projectView = ProjectView.getInstance(getProject());
|
||||
projectView.changeView(ProjectViewPane.ID);
|
||||
|
||||
assertEquals(ProjectViewPane.ID, projectView.getCurrentViewId());
|
||||
|
||||
FavoritesManager favoritesManager = FavoritesManager.getInstance(getProject());
|
||||
favoritesManager.createNewList("xxxx");
|
||||
|
||||
AbstractProjectViewPane currentPane = projectView.getCurrentProjectViewPane();
|
||||
assertEquals(FavoritesProjectViewPane.ID, currentPane.getId());
|
||||
assertEquals("xxxx", currentPane.getSubId());
|
||||
|
||||
favoritesManager.createNewList("yyyy");
|
||||
currentPane = projectView.getCurrentProjectViewPane();
|
||||
assertEquals(FavoritesProjectViewPane.ID, currentPane.getId());
|
||||
assertEquals("yyyy", currentPane.getSubId());
|
||||
|
||||
favoritesManager.removeFavoritesList("xxxx");
|
||||
currentPane = projectView.getCurrentProjectViewPane();
|
||||
assertEquals(FavoritesProjectViewPane.ID, currentPane.getId());
|
||||
assertEquals("yyyy", currentPane.getSubId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.intellij.projectView;
|
||||
|
||||
import com.intellij.ide.projectView.PresentationData;
|
||||
import com.intellij.ide.projectView.ProjectViewNode;
|
||||
import com.intellij.ide.projectView.TreeStructureProvider;
|
||||
import com.intellij.ide.projectView.ViewSettings;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.util.MultiValuesMap;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
class SameNamesJoiner implements TreeStructureProvider {
|
||||
public Collection<AbstractTreeNode> modify(AbstractTreeNode parent, Collection<AbstractTreeNode> children, ViewSettings settings) {
|
||||
if (parent instanceof JoinedNode) return children;
|
||||
|
||||
ArrayList<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
|
||||
|
||||
MultiValuesMap<Object, AbstractTreeNode> executed = new MultiValuesMap<Object, AbstractTreeNode>();
|
||||
for (Iterator<AbstractTreeNode> iterator = children.iterator(); iterator.hasNext();) {
|
||||
ProjectViewNode treeNode = (ProjectViewNode)iterator.next();
|
||||
Object o = treeNode.getValue();
|
||||
if (o instanceof PsiFile) {
|
||||
String name = ((PsiFile)o).getVirtualFile().getNameWithoutExtension();
|
||||
executed.put(name, treeNode);
|
||||
}
|
||||
else {
|
||||
executed.put(o, treeNode);
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<Object> keys = executed.keySet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
Object each = keys.next();
|
||||
Collection<AbstractTreeNode> objects = executed.get(each);
|
||||
if (objects.size() > 1) {
|
||||
result.add(new JoinedNode(objects, new Joined(findPsiFileIn(objects))));
|
||||
}
|
||||
else if (objects.size() == 1) {
|
||||
result.add(objects.iterator().next());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Object getData(Collection<AbstractTreeNode> selected, String dataName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PsiElement getTopLevelElement(final PsiElement element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private PsiFile findPsiFileIn(Collection<AbstractTreeNode> objects) {
|
||||
for (Iterator<AbstractTreeNode> iterator = objects.iterator(); iterator.hasNext();) {
|
||||
AbstractTreeNode treeNode = iterator.next();
|
||||
if (treeNode.getValue() instanceof PsiFile) return (PsiFile)treeNode.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean hasElementWithTheSameName(PsiFile element) {
|
||||
PsiDirectory psiDirectory = ((PsiDirectory)element.getParent());
|
||||
PsiElement[] children = psiDirectory.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
PsiElement child = children[i];
|
||||
|
||||
if (child != element && element.getVirtualFile().getNameWithoutExtension().equals(((PsiFile)child).getVirtualFile().getNameWithoutExtension())){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private class Joined{
|
||||
private final String myName;
|
||||
private final PsiFile myFile;
|
||||
|
||||
public Joined(PsiFile file) {
|
||||
myFile = file;
|
||||
myName = file.getName();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return myFile.getVirtualFile().getNameWithoutExtension();
|
||||
}
|
||||
|
||||
public PsiFile getPsiFile() {
|
||||
return myFile;
|
||||
}
|
||||
|
||||
public boolean equals(Object object) {
|
||||
if (!(object instanceof Joined)) return false;
|
||||
return myFile.getVirtualFile().getNameWithoutExtension()
|
||||
.equals(((Joined)object).myFile.getVirtualFile().getNameWithoutExtension());
|
||||
}
|
||||
}
|
||||
|
||||
private class JoinedNode extends ProjectViewNode<Joined>{
|
||||
Collection<AbstractTreeNode> myChildren;
|
||||
|
||||
@NotNull
|
||||
public Collection<AbstractTreeNode> getChildren() {
|
||||
return myChildren;
|
||||
}
|
||||
|
||||
public JoinedNode(Collection<AbstractTreeNode> children, Joined formFile) {
|
||||
super(null, formFile, null);
|
||||
myChildren = children;
|
||||
}
|
||||
|
||||
public String getTestPresentation() {
|
||||
return getValue().toString() + " joined";
|
||||
}
|
||||
|
||||
public boolean contains(@NotNull VirtualFile file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void update(PresentationData presentation) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Copyright (c) 2004 JetBrains s.r.o. All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* -Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* -Redistribution in binary form must reproduct the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of JetBrains or IntelliJ IDEA
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* This software is provided "AS IS," without a warranty of any kind. ALL
|
||||
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
|
||||
* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. JETBRAINS AND ITS LICENSORS SHALL NOT
|
||||
* BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
|
||||
* OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
|
||||
* DERIVATIVES. IN NO EVENT WILL JETBRAINS OR ITS LICENSORS BE LIABLE FOR ANY LOST
|
||||
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
|
||||
* INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
|
||||
* OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
|
||||
* IF JETBRAINS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
*/
|
||||
package com.intellij.projectView;
|
||||
|
||||
import com.intellij.ide.structureView.impl.java.InheritedMembersFilter;
|
||||
import com.intellij.ide.structureView.newStructureView.StructureViewComponent;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.JavaDirectoryService;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.testFramework.TestSourceBasedTestCase;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class StructureViewUpdatingTest extends TestSourceBasedTestCase {
|
||||
protected String getTestPath() {
|
||||
return "structureView";
|
||||
}
|
||||
|
||||
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());
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + " -Class1\n" + " getValue():int\n" +
|
||||
" hashCode():int\n" + " finalize():void\n" + " notify():void\n" +
|
||||
" notifyAll():void\n" + " wait():void\n" + " wait(long):void\n" +
|
||||
" wait(long, int):void\n" + " getClass():Class\n" +
|
||||
" clone():Object\n" + " equals(Object):boolean\n" +
|
||||
" toString():String\n" + " myField1:boolean\n" +
|
||||
" myField2:boolean\n");
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
|
||||
public void run() {
|
||||
|
||||
final int offset = document.getLineStartOffset(5);
|
||||
document.insertString(offset, " boolean myNewField = false;\n");
|
||||
}
|
||||
}, null, null);
|
||||
|
||||
PsiDocumentManager.getInstance(myProject).commitDocument(document);
|
||||
|
||||
IdeaTestUtil.waitForAlarm(600);
|
||||
|
||||
//TreeUtil.expand(structureViewComponent.getTree(), 3);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" +
|
||||
" -Class1\n" + " getValue():int\n" +
|
||||
" hashCode():int\n" +
|
||||
" finalize():void\n" +
|
||||
" notify():void\n" +
|
||||
" notifyAll():void\n" +
|
||||
" wait():void\n" +
|
||||
" wait(long):void\n" +
|
||||
" wait(long, int):void\n" +
|
||||
" getClass():Class\n" +
|
||||
" clone():Object\n" +
|
||||
" equals(Object):boolean\n" +
|
||||
" toString():String\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n" +
|
||||
" myNewField:boolean = false\n");
|
||||
|
||||
Disposer.dispose(structureViewComponent);
|
||||
|
||||
}
|
||||
finally {
|
||||
fileEditorManager.closeFile(virtualFile);
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
structureViewComponent.setActionActive(InheritedMembersFilter.ID, true);
|
||||
|
||||
IdeaTestUtil.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);
|
||||
|
||||
IdeaTestUtil.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, new Runnable() {
|
||||
public void run() {
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
innerClassField.delete();
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
assertTrue(e.getLocalizedMessage(), false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, null, null);
|
||||
|
||||
IdeaTestUtil.waitForAlarm(600);
|
||||
|
||||
IdeaTestUtil.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);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
IdeaTestUtil.assertTreeEqual(tree, "-test.xml\n" +
|
||||
" -test\n" +
|
||||
" +level1\n" +
|
||||
" +level1\n" +
|
||||
" +level1\n" +
|
||||
" +level1\n");
|
||||
|
||||
tree.expandPath(tree.getPathForRow(3));
|
||||
|
||||
IdeaTestUtil.waitForAlarm(600);
|
||||
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(tree,
|
||||
"-test.xml\n" +
|
||||
" -test\n" +
|
||||
" +level1\n" +
|
||||
" -level1\n" +
|
||||
" +level2\n" +
|
||||
" +level1\n" +
|
||||
" +level1\n");
|
||||
|
||||
Disposer.dispose(structureViewComponent);
|
||||
}
|
||||
finally {
|
||||
fileEditorManager.closeFile(xmlVirtualFile);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.intellij.projectView;
|
||||
|
||||
import com.intellij.ide.todo.AllTodosTreeBuilder;
|
||||
import com.intellij.ide.todo.CurrentFileTodosTreeBuilder;
|
||||
import com.intellij.ide.todo.TodoTreeStructure;
|
||||
import com.intellij.ide.todo.nodes.TodoItemNode;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
|
||||
public class ToDoTreeStructureTest extends BaseProjectViewTestCase {
|
||||
|
||||
public void testToDo1() throws Exception {
|
||||
AllTodosTreeBuilder all = new AllTodosTreeBuilder(new JTree(), new DefaultTreeModel(new DefaultMutableTreeNode()), myProject);
|
||||
all.init();
|
||||
|
||||
myStructure = all.getTreeStructure();
|
||||
((TodoTreeStructure)myStructure).setFlattenPackages(true);
|
||||
assertStructureEqual("Root\n" +
|
||||
" Summary\n" +
|
||||
" PsiPackage: package1.package2 (2 items in 1 file)\n" +
|
||||
" PsiJavaFile:JavaClass.java\n" +
|
||||
" Item: (62,78)\n" +
|
||||
" Item: (145,162)\n", null);
|
||||
|
||||
checkOccurances(all, new String[]{"Item: (62,78)", "Item: (145,162)"});
|
||||
Disposer.dispose(all);
|
||||
}
|
||||
|
||||
//todo kirillk
|
||||
public void _testToDo() throws Exception {
|
||||
AllTodosTreeBuilder all = new AllTodosTreeBuilder(new JTree(), new DefaultTreeModel(new DefaultMutableTreeNode()), myProject);
|
||||
all.init();
|
||||
|
||||
myStructure = all.getTreeStructure();
|
||||
assertStructureEqual("Root\n" +
|
||||
" Summary\n" +
|
||||
" PsiDirectory: toDo\n" +
|
||||
" XmlFile:xmlFile.xml\n"+
|
||||
" Item: (12,16)\n" +
|
||||
" PsiPackage: package1 (4 items in 2 files)\n" +
|
||||
" PsiPackage: package2 (2 items in 1 file)\n" +
|
||||
" PsiJavaFile:JavaClass.java\n" +
|
||||
" Item: (62,78)\n" +
|
||||
" Item: (145,162)\n" +
|
||||
" PsiJavaFile:JavaClass.java\n" +
|
||||
" Item: (52,68)\n" +
|
||||
" Item: (134,151)\n" +
|
||||
" PsiPackage: package3 (2 items in 1 file)\n" +
|
||||
" PsiJavaFile:JavaClass.java\n" +
|
||||
" Item: (53,69)\n" +
|
||||
" Item: (136,153)\n", null);
|
||||
|
||||
checkOccurances(all, new String[]{"Item: (12,16)","Item: (62,78)", "Item: (145,162)", "Item: (52,68)", "Item: (134,151)",
|
||||
"Item: (53,69)", "Item: (136,153)"});
|
||||
|
||||
|
||||
final DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
|
||||
final JTree currentFileTree = new JTree(treeModel);
|
||||
CurrentFileTodosTreeBuilder builder = new CurrentFileTodosTreeBuilder(currentFileTree,
|
||||
treeModel,
|
||||
myProject);
|
||||
|
||||
builder.init();
|
||||
builder.setFile(getSrcDirectory().findSubdirectory("package1").findFile("JavaClass.java"));
|
||||
builder.updateFromRoot();
|
||||
myStructure = builder.getTreeStructure();
|
||||
assertStructureEqual("PsiJavaFile:JavaClass.java\n" +
|
||||
" PsiJavaFile:JavaClass.java\n" +
|
||||
" Item: (52,68)\n" +
|
||||
" Item: (134,151)\n", null);
|
||||
|
||||
TreeUtil.expandAll(currentFileTree);
|
||||
|
||||
currentFileTree.getSelectionModel().setSelectionPath(currentFileTree.getPathForRow(4));
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(currentFileTree, "-Root\n" +
|
||||
" -Summary\n" +
|
||||
" -JavaClass.java\n" +
|
||||
" Item: (52,68)\n" +
|
||||
" [Item: (134,151)]\n", true);
|
||||
|
||||
IdeaTestUtil.waitForAlarm(600);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(currentFileTree, "-Root\n" +
|
||||
" -Summary\n" +
|
||||
" -JavaClass.java\n" +
|
||||
" Item: (52,68)\n" +
|
||||
" [Item: (134,151)]\n", true);
|
||||
Disposer.dispose(builder);
|
||||
Disposer.dispose(all);
|
||||
}
|
||||
|
||||
private void checkOccurances(final AllTodosTreeBuilder all, final String[] strings) {
|
||||
TodoItemNode current = all.getFirstPointerForElement(myStructure.getRootElement());
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
String string = strings[i];
|
||||
assertNotNull(current);
|
||||
assertEquals(string, current.getTestPresentation());
|
||||
current = all.getNextPointer(current);
|
||||
}
|
||||
|
||||
assertNull(current);
|
||||
|
||||
current = all.getLastPointerForElement(myStructure.getRootElement());
|
||||
for (int i = strings.length - 1; i >= 0; i--) {
|
||||
String string = strings[i];
|
||||
assertNotNull(current);
|
||||
assertEquals(string, current.getTestPresentation());
|
||||
current = all.getPreviousPointer(current);
|
||||
}
|
||||
assertNull(current);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user