selection tests
authorKonstantin Bulenkov <kb@jetbrains.com>
Mon, 30 Jan 2012 15:11:34 +0000 (16:11 +0100)
committerKonstantin Bulenkov <kb@jetbrains.com>
Mon, 30 Jan 2012 15:14:24 +0000 (16:14 +0100)
15 files changed:
java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaAnonymousClassesNodeProvider.java
java/java-tests/testData/fileStructure/selection/Constructor.java [new file with mode: 0644]
java/java-tests/testData/fileStructure/selection/Constructor.tree [new file with mode: 0644]
java/java-tests/testData/fileStructure/selection/Field.java [new file with mode: 0644]
java/java-tests/testData/fileStructure/selection/Field.tree [new file with mode: 0644]
java/java-tests/testData/fileStructure/selection/InsideClass.java [new file with mode: 0644]
java/java-tests/testData/fileStructure/selection/InsideClass.tree [new file with mode: 0644]
java/java-tests/testData/fileStructure/selection/Method.java [new file with mode: 0644]
java/java-tests/testData/fileStructure/selection/Method.tree [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/ide/fileStructure/JavaFileStructureSelectionTest.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/ide/fileStructure/JavaFileStructureTestCase.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java
platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java
platform/platform-api/src/com/intellij/ui/treeStructure/filtered/FilteringTreeStructure.java
platform/testFramework/src/com/intellij/testFramework/FileStructureTestBase.java

index 2f41b69c8368fe31c1f89fb619226eaf4d9a92fb..65bc73d12b8abdb6427e37114bcc3842a9082c9f 100644 (file)
@@ -43,6 +43,7 @@ import java.util.List;
  */
 public class JavaAnonymousClassesNodeProvider implements FileStructureNodeProvider<JavaAnonymousClassTreeElement>, PropertyOwner {
   public static final String ID = "SHOW_ANONYMOUS";
+  public static final String JAVA_ANONYMOUS_PROPERTY_NAME = "java.anonymous.provider";
 
   @Override
   public Collection<JavaAnonymousClassTreeElement> 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 (file)
index 0000000..55a5f02
--- /dev/null
@@ -0,0 +1,7 @@
+class Constructor {
+  int num1;
+  int num2;
+
+  Constructor() {<caret>}
+  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 (file)
index 0000000..92a1b45
--- /dev/null
@@ -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 (file)
index 0000000..35e5fea
--- /dev/null
@@ -0,0 +1,7 @@
+class Field {
+  int num1;
+  int <caret>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 (file)
index 0000000..1008b5f
--- /dev/null
@@ -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 (file)
index 0000000..5fc06c0
--- /dev/null
@@ -0,0 +1,7 @@
+class InsideClass {
+  int num1;
+  int num2;
+  <caret>
+  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 (file)
index 0000000..96d30ca
--- /dev/null
@@ -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 (file)
index 0000000..01e47e1
--- /dev/null
@@ -0,0 +1,7 @@
+class Method {
+  int num1;
+  int num2;
+
+  Method() {}
+  void foo() {<caret>}
+}
\ 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 (file)
index 0000000..5e868f2
--- /dev/null
@@ -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 (file)
index 0000000..84e9714
--- /dev/null
@@ -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 (file)
index 0000000..0753206
--- /dev/null
@@ -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();
+  }
+}
index 9d885b1e49d8444373a55afe5be95360ddb19f78..39dbe47a25aa718e29a96fad3c3096a5d0bdbf93 100644 (file)
@@ -424,7 +424,8 @@ public class FileStructurePopup implements Disposable {
     }
   }
 
-  public void selectPsiElement(PsiElement element) {
+  @Nullable
+  public FilteringTreeStructure.FilteringNode selectPsiElement(PsiElement element) {
     Set<PsiElement> 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<PsiElement> 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";
   }
 
index 43423a3599326a448abfe5bbde0bc7795a08f4d9..96560cad40a8996ccd1825a2e6de87b3029d3fa4 100644 (file)
@@ -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,
index 786ecdf73791f12bc32c73903e5c120e99538769..7a3fce1253bc2fc95d4883f4dd655b31893e3e13 100644 (file)
@@ -241,7 +241,7 @@ public class FilteringTreeStructure extends AbstractTreeStructure {
     }
 
     public Object[] getEqualityObjects() {
-      return NONE;
+      return new Object[]{myDelegate};
     }
 
     @Override
index 3f991b0cb683a6820109ecbc489e2a3d4fc9b4a5..5b9fe7a375cf904c4f14b15caf54d54d6197be0a 100644 (file)
@@ -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));
       }
     });
   }