diff --git a/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaAnonymousClassesNodeProvider.java b/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaAnonymousClassesNodeProvider.java index 2f41b69c8368..65bc73d12b8a 100644 --- a/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaAnonymousClassesNodeProvider.java +++ b/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaAnonymousClassesNodeProvider.java @@ -43,6 +43,7 @@ import java.util.List; */ public class JavaAnonymousClassesNodeProvider implements FileStructureNodeProvider, PropertyOwner { public static final String ID = "SHOW_ANONYMOUS"; + public static final String JAVA_ANONYMOUS_PROPERTY_NAME = "java.anonymous.provider"; @Override public Collection provideNodes(TreeElement node) { @@ -87,6 +88,6 @@ public class JavaAnonymousClassesNodeProvider implements FileStructureNodeProvid @NotNull @Override public String getPropertyName() { - return "java.anonymous.provider"; + return JAVA_ANONYMOUS_PROPERTY_NAME; } } diff --git a/java/java-tests/testData/fileStructure/selection/Constructor.java b/java/java-tests/testData/fileStructure/selection/Constructor.java new file mode 100644 index 000000000000..55a5f021dedd --- /dev/null +++ b/java/java-tests/testData/fileStructure/selection/Constructor.java @@ -0,0 +1,7 @@ +class Constructor { + int num1; + int num2; + + Constructor() {} + void foo() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/fileStructure/selection/Constructor.tree b/java/java-tests/testData/fileStructure/selection/Constructor.tree new file mode 100644 index 000000000000..92a1b45db704 --- /dev/null +++ b/java/java-tests/testData/fileStructure/selection/Constructor.tree @@ -0,0 +1,6 @@ +-Constructor.java + -Constructor + [Constructor()] + foo():void + num1:int + num2:int \ No newline at end of file diff --git a/java/java-tests/testData/fileStructure/selection/Field.java b/java/java-tests/testData/fileStructure/selection/Field.java new file mode 100644 index 000000000000..35e5fea671f7 --- /dev/null +++ b/java/java-tests/testData/fileStructure/selection/Field.java @@ -0,0 +1,7 @@ +class Field { + int num1; + int num2; + + Field() {} + void foo() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/fileStructure/selection/Field.tree b/java/java-tests/testData/fileStructure/selection/Field.tree new file mode 100644 index 000000000000..1008b5f45802 --- /dev/null +++ b/java/java-tests/testData/fileStructure/selection/Field.tree @@ -0,0 +1,6 @@ +-Field.java + -Field + Field() + foo():void + num1:int + [num2:int] diff --git a/java/java-tests/testData/fileStructure/selection/InsideClass.java b/java/java-tests/testData/fileStructure/selection/InsideClass.java new file mode 100644 index 000000000000..5fc06c0e2be5 --- /dev/null +++ b/java/java-tests/testData/fileStructure/selection/InsideClass.java @@ -0,0 +1,7 @@ +class InsideClass { + int num1; + int num2; + + InsideClass() {} + void foo() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/fileStructure/selection/InsideClass.tree b/java/java-tests/testData/fileStructure/selection/InsideClass.tree new file mode 100644 index 000000000000..96d30ca6b340 --- /dev/null +++ b/java/java-tests/testData/fileStructure/selection/InsideClass.tree @@ -0,0 +1,6 @@ +-InsideClass.java + -[InsideClass] + InsideClass() + foo():void + num1:int + num2:int \ No newline at end of file diff --git a/java/java-tests/testData/fileStructure/selection/Method.java b/java/java-tests/testData/fileStructure/selection/Method.java new file mode 100644 index 000000000000..01e47e1aaabf --- /dev/null +++ b/java/java-tests/testData/fileStructure/selection/Method.java @@ -0,0 +1,7 @@ +class Method { + int num1; + int num2; + + Method() {} + void foo() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/fileStructure/selection/Method.tree b/java/java-tests/testData/fileStructure/selection/Method.tree new file mode 100644 index 000000000000..5e868f2f9765 --- /dev/null +++ b/java/java-tests/testData/fileStructure/selection/Method.tree @@ -0,0 +1,6 @@ +-Method.java + -Method + Method() + [foo():void] + num1:int + num2:int \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/ide/fileStructure/JavaFileStructureSelectionTest.java b/java/java-tests/testSrc/com/intellij/ide/fileStructure/JavaFileStructureSelectionTest.java new file mode 100644 index 000000000000..84e971463a84 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/ide/fileStructure/JavaFileStructureSelectionTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ide.fileStructure; + +/** + * @author Konstantin Bulenkov + */ +public class JavaFileStructureSelectionTest extends JavaFileStructureTestCase { + @Override + protected String getTestDataFolderName() { + return "selection"; + } + + public void testField() throws Exception {checkTree();} + public void testMethod() throws Exception {checkTree();} + public void testConstructor() throws Exception {checkTree();} + public void testInsideClass() throws Exception {checkTree();} +} diff --git a/java/java-tests/testSrc/com/intellij/ide/fileStructure/JavaFileStructureTestCase.java b/java/java-tests/testSrc/com/intellij/ide/fileStructure/JavaFileStructureTestCase.java new file mode 100644 index 000000000000..0753206117da --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/ide/fileStructure/JavaFileStructureTestCase.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ide.fileStructure; + +import com.intellij.JavaTestUtil; +import com.intellij.ide.structureView.impl.java.JavaAnonymousClassesNodeProvider; +import com.intellij.ide.util.FileStructurePopup; +import com.intellij.ide.util.PropertiesComponent; +import com.intellij.testFramework.FileStructureTestBase; + +/** + * @author Konstantin Bulenkov + */ +public abstract class JavaFileStructureTestCase extends FileStructureTestBase { + private boolean myShowAnonymousByDefault; + + protected abstract String getTestDataFolderName(); + + @Override + public void setUp() throws Exception { + super.setUp(); + myShowAnonymousByDefault = PropertiesComponent.getInstance().getBoolean(getAnonymousPropertyName(), false); + } + + @Override + protected String getFileExtension() { + return "java"; + } + + @Override + public void tearDown() throws Exception { + PropertiesComponent.getInstance().setValue(getAnonymousPropertyName(), Boolean.toString(myShowAnonymousByDefault)); + super.tearDown(); + } + + private static String getAnonymousPropertyName() { + return FileStructurePopup.getPropertyName(JavaAnonymousClassesNodeProvider.JAVA_ANONYMOUS_PROPERTY_NAME); + } + + @Override + protected String getBasePath() { + return JavaTestUtil.getRelativeJavaTestDataPath() + "/fileStructure/" + getTestDataFolderName(); + } +} diff --git a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java index 9d885b1e49d8..39dbe47a25aa 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java +++ b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java @@ -424,7 +424,8 @@ public class FileStructurePopup implements Disposable { } } - public void selectPsiElement(PsiElement element) { + @Nullable + public FilteringTreeStructure.FilteringNode selectPsiElement(PsiElement element) { Set parents = getAllParents(element); FilteringTreeStructure.FilteringNode node = (FilteringTreeStructure.FilteringNode)myAbstractTreeBuilder.getRootElement(); @@ -443,11 +444,11 @@ public class FileStructurePopup implements Disposable { if (myAbstractTreeBuilder.getSelectedElements().isEmpty()) { TreeUtil.selectFirstNode(myTree); } - return; - + return node; } } TreeUtil.selectFirstNode(myTree); + return null; } private static Set getAllParents(PsiElement element) { @@ -721,7 +722,7 @@ public class FileStructurePopup implements Disposable { } } - private static String getPropertyName(String propertyName) { + public static String getPropertyName(String propertyName) { return propertyName + ".file.structure.state"; } diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java index 43423a359932..96560cad40a8 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java @@ -3688,7 +3688,7 @@ public class AbstractTreeUi { } public void userSelect(final Object[] elements, final Runnable onDone, final boolean addToSelection, boolean scroll) { - _select(elements, onDone, addToSelection, true, false, scroll, false, true, true); + _select(elements, onDone, addToSelection, true, false, scroll, false, true, !ApplicationManager.getApplication().isUnitTestMode()); } void _select(final Object[] elements, diff --git a/platform/platform-api/src/com/intellij/ui/treeStructure/filtered/FilteringTreeStructure.java b/platform/platform-api/src/com/intellij/ui/treeStructure/filtered/FilteringTreeStructure.java index 786ecdf73791..7a3fce1253bc 100644 --- a/platform/platform-api/src/com/intellij/ui/treeStructure/filtered/FilteringTreeStructure.java +++ b/platform/platform-api/src/com/intellij/ui/treeStructure/filtered/FilteringTreeStructure.java @@ -241,7 +241,7 @@ public class FilteringTreeStructure extends AbstractTreeStructure { } public Object[] getEqualityObjects() { - return NONE; + return new Object[]{myDelegate}; } @Override diff --git a/platform/testFramework/src/com/intellij/testFramework/FileStructureTestBase.java b/platform/testFramework/src/com/intellij/testFramework/FileStructureTestBase.java index 3f991b0cb683..5b9fe7a375cf 100644 --- a/platform/testFramework/src/com/intellij/testFramework/FileStructureTestBase.java +++ b/platform/testFramework/src/com/intellij/testFramework/FileStructureTestBase.java @@ -67,7 +67,7 @@ public abstract class FileStructureTestBase extends CodeInsightFixtureTestCase { protected void checkTree() throws Exception { final String expected = FileUtil.loadFile(new File(getTestDataPath() + "/" + getTreeFileName())); - Assert.assertEquals(expected, PlatformTestUtil.print(getTree(), true)); + Assert.assertEquals(expected.trim(), PlatformTestUtil.print(getTree(), true).trim()); } @@ -78,7 +78,8 @@ public abstract class FileStructureTestBase extends CodeInsightFixtureTestCase { getStructure().rebuild(); updateTree(); TreeUtil.expandAll(getTree()); - myPopup.selectPsiElement(getFile()); + final FilteringTreeStructure.FilteringNode node = myPopup.selectPsiElement(myPopup.getCurrentElement(getFile())); + getTree().getSelectionModel().setSelectionPath(getTree().getPath(node)); } }); }