anonymous tests
authorKonstantin Bulenkov <kb@jetbrains.com>
Tue, 31 Jan 2012 16:19:58 +0000 (17:19 +0100)
committerKonstantin Bulenkov <kb@jetbrains.com>
Tue, 31 Jan 2012 16:21:22 +0000 (17:21 +0100)
java/java-tests/testData/fileStructure/selection/Anonymous.java [new file with mode: 0644]
java/java-tests/testData/fileStructure/selection/Anonymous.tree [new file with mode: 0644]
java/java-tests/testData/fileStructure/selection/AnonymousInAnonymous.java [new file with mode: 0644]
java/java-tests/testData/fileStructure/selection/AnonymousInAnonymous.tree [new file with mode: 0644]
java/java-tests/testSrc/Anonymous.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/ide/fileStructure/JavaFileStructureSelectionTest.java
java/java-tests/testSrc/com/intellij/ide/fileStructure/JavaFileStructureTestCase.java
platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java
platform/testFramework/src/com/intellij/testFramework/FileStructureTestBase.java
platform/testFramework/src/com/intellij/testFramework/TestTreeUpdater.java [new file with mode: 0644]

diff --git a/java/java-tests/testData/fileStructure/selection/Anonymous.java b/java/java-tests/testData/fileStructure/selection/Anonymous.java
new file mode 100644 (file)
index 0000000..7504bf0
--- /dev/null
@@ -0,0 +1,8 @@
+class Anonymous {
+  int num1;
+  int num2;
+  Object o = new Object(){<caret>};
+
+  Anonymous() {}
+  void foo() {}
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/fileStructure/selection/Anonymous.tree b/java/java-tests/testData/fileStructure/selection/Anonymous.tree
new file mode 100644 (file)
index 0000000..94920b4
--- /dev/null
@@ -0,0 +1,8 @@
+-Anonymous.java
+ -Anonymous
+  Anonymous()
+  foo():void
+  num1:int
+  num2:int
+  -[o:Object = new Object() {...}]
+   $1
\ No newline at end of file
diff --git a/java/java-tests/testData/fileStructure/selection/AnonymousInAnonymous.java b/java/java-tests/testData/fileStructure/selection/AnonymousInAnonymous.java
new file mode 100644 (file)
index 0000000..5bfeff7
--- /dev/null
@@ -0,0 +1,15 @@
+class AnonymousInAnonymous {
+  int num1;
+  int num2;
+
+  AnonymousInAnonymous() {}
+  void foo() {
+    new Object() {
+       public String toString() {
+         return new Object(){
+           void method() {<caret>}
+         }.toString();
+       }
+    };
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/fileStructure/selection/AnonymousInAnonymous.tree b/java/java-tests/testData/fileStructure/selection/AnonymousInAnonymous.tree
new file mode 100644 (file)
index 0000000..1f88488
--- /dev/null
@@ -0,0 +1,10 @@
+-AnonymousInAnonymous.java
+ -AnonymousInAnonymous
+  AnonymousInAnonymous()
+  -foo():void
+   -$1
+    -toString():String
+     -Anonymous
+      [method():void]
+  num1:int
+  num2:int
\ No newline at end of file
diff --git a/java/java-tests/testSrc/Anonymous.java b/java/java-tests/testSrc/Anonymous.java
new file mode 100644 (file)
index 0000000..e72d2fb
--- /dev/null
@@ -0,0 +1,10 @@
+class Anonymous {
+  int num1;
+  int num2;
+  Object o = new Object(){
+    int num = 1;
+  };
+
+  Anonymous() {}
+  void foo() {}
+}
\ No newline at end of file
index 84e971463a84db5c830d3d75e5f9defbd19b3910..fbea9c3943bfacb5e3857187cef31c4c1549ea75 100644 (file)
@@ -24,8 +24,10 @@ public class JavaFileStructureSelectionTest extends JavaFileStructureTestCase {
     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();}
+  public void testField()                 throws Exception {checkTree();}
+  public void testMethod()                throws Exception {checkTree();}
+  public void testConstructor()           throws Exception {checkTree();}
+  public void testInsideClass()           throws Exception {checkTree();}
+  public void testAnonymous()             throws Exception {checkTree();}
+  public void testAnonymousInAnonymous()  throws Exception {checkTree();}
 }
index 0753206117daf8e84ae6df64ee1b413370a6bce9..c3559b0370f35d5cf6a3b30c353ab3772738fa45 100644 (file)
@@ -33,6 +33,9 @@ public abstract class JavaFileStructureTestCase extends FileStructureTestBase {
   public void setUp() throws Exception {
     super.setUp();
     myShowAnonymousByDefault = PropertiesComponent.getInstance().getBoolean(getAnonymousPropertyName(), false);
+    if (getTestName(false).contains("Anonymous")) {
+      setShowAnonymous(true);
+    }
   }
 
   @Override
@@ -40,6 +43,11 @@ public abstract class JavaFileStructureTestCase extends FileStructureTestBase {
     return "java";
   }
 
+  public void setShowAnonymous(boolean show) throws Exception {
+    myPopup.setTreeActionState(JavaAnonymousClassesNodeProvider.class, show);
+    update();
+  }
+
   @Override
   public void tearDown() throws Exception {
     PropertiesComponent.getInstance().setValue(getAnonymousPropertyName(), Boolean.toString(myShowAnonymousByDefault));
index 39dbe47a25aa718e29a96fad3c3096a5d0bdbf93..bc270a07174d90baa279602a02828ab7831105a7 100644 (file)
@@ -107,6 +107,7 @@ public class FileStructurePopup implements Disposable {
   private int myPreferredWidth;
   private final FilteringTreeStructure myFilteringStructure;
   private PsiElement myInitialPsiElement;
+  private Map<Class, JCheckBox> myCheckBoxes = new HashMap<Class, JCheckBox>();
 
   public FileStructurePopup(StructureViewModel structureViewModel,
                             @Nullable Editor editor,
@@ -128,7 +129,7 @@ public class FileStructurePopup implements Disposable {
 
     myTreeStructure = new SmartTreeStructure(project, myTreeModel){
       public void rebuildTree() {
-        if (!myPopup.isDisposed()) {
+        if (ApplicationManager.getApplication().isUnitTestMode() || !myPopup.isDisposed()) {
           super.rebuildTree();
         }
       }
@@ -503,7 +504,7 @@ public class FileStructurePopup implements Disposable {
     return null;
   }
 
-  protected JComponent createCenterPanel() {
+  public JComponent createCenterPanel() {
     List<FileStructureFilter> fileStructureFilters = new ArrayList<FileStructureFilter>();
     List<FileStructureNodeProvider> fileStructureNodeProviders = new ArrayList<FileStructureNodeProvider>();
     if (myTreeActionsOwner != null) {
@@ -704,6 +705,7 @@ public class FileStructurePopup implements Disposable {
     }
     chkFilter.setText(text);
     panel.add(chkFilter);
+    myCheckBoxes.put(action.getClass(), chkFilter);
   }
 
   private static boolean getDefaultValue(TreeAction action) {
@@ -742,6 +744,16 @@ public class FileStructurePopup implements Disposable {
     return myAbstractTreeBuilder;
   }
 
+  public void setTreeActionState(Class<? extends TreeAction> action, boolean state) {
+    final JCheckBox checkBox = myCheckBoxes.get(action);
+    if (checkBox != null) {
+      checkBox.setSelected(state);
+      for (ActionListener listener : checkBox.getActionListeners()) {
+        listener.actionPerformed(new ActionEvent(this, 1, ""));
+      }
+    }
+  }
+
   private class FileStructurePopupFilter implements ElementFilter {
     private String myLastFilter = null;
     private HashSet<Object> myVisibleParents = new HashSet<Object>();
index 645d6ae0192eed63f7a558e3f86cd748daea31ee..99c205834e9489db560920056cf08b2fc73b47e9 100644 (file)
@@ -36,7 +36,7 @@ import java.io.File;
  * @author Konstantin Bulenkov
  */
 public abstract class FileStructureTestBase extends CodeInsightFixtureTestCase {
-  FileStructurePopup myPopup;
+  protected FileStructurePopup myPopup;
 
   @Before
   public void setUp() throws Exception {
@@ -46,6 +46,9 @@ public abstract class FileStructureTestBase extends CodeInsightFixtureTestCase {
                                               myFixture.getProject(),
                                               null,
                                               TextEditorProvider.getInstance().getTextEditor(myFixture.getEditor()));
+    assert myPopup != null;
+    myPopup.createCenterPanel();
+    getBuilder().getUi().getUpdater().setPassThroughMode(true);
     update();
   }
 
@@ -71,15 +74,17 @@ public abstract class FileStructureTestBase extends CodeInsightFixtureTestCase {
   }
 
 
-  private void update() throws InterruptedException {
+  public void update() throws InterruptedException {
     myPopup.getTreeBuilder().refilter().doWhenProcessed(new Runnable() {
       @Override
       public void run() {
+
         getStructure().rebuild();
         updateTree();
+        getBuilder().updateFromRoot();
         TreeUtil.expandAll(getTree());
         final FilteringTreeStructure.FilteringNode node = myPopup.selectPsiElement(myPopup.getCurrentElement(getFile()));
-        getTree().getSelectionModel().setSelectionPath(getTree().getPath(node));
+        getBuilder().getUi().select(node, null);
       }
     });
   }
diff --git a/platform/testFramework/src/com/intellij/testFramework/TestTreeUpdater.java b/platform/testFramework/src/com/intellij/testFramework/TestTreeUpdater.java
new file mode 100644 (file)
index 0000000..3dfec72
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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.testFramework;
+
+import com.intellij.ide.util.treeView.AbstractTreeBuilder;
+import com.intellij.ide.util.treeView.AbstractTreeUpdater;
+
+/**
+ * @author Konstantin Bulenkov
+ */
+public class TestTreeUpdater extends AbstractTreeUpdater {
+  public TestTreeUpdater(AbstractTreeBuilder treeBuilder) {
+    super(treeBuilder);
+  }
+}