*/
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) {
@NotNull
@Override
public String getPropertyName() {
- return "java.anonymous.provider";
+ return JAVA_ANONYMOUS_PROPERTY_NAME;
}
}
--- /dev/null
+class Constructor {
+ int num1;
+ int num2;
+
+ Constructor() {<caret>}
+ void foo() {}
+}
\ No newline at end of file
--- /dev/null
+-Constructor.java
+ -Constructor
+ [Constructor()]
+ foo():void
+ num1:int
+ num2:int
\ No newline at end of file
--- /dev/null
+class Field {
+ int num1;
+ int <caret>num2;
+
+ Field() {}
+ void foo() {}
+}
\ No newline at end of file
--- /dev/null
+-Field.java
+ -Field
+ Field()
+ foo():void
+ num1:int
+ [num2:int]
--- /dev/null
+class InsideClass {
+ int num1;
+ int num2;
+ <caret>
+ InsideClass() {}
+ void foo() {}
+}
\ No newline at end of file
--- /dev/null
+-InsideClass.java
+ -[InsideClass]
+ InsideClass()
+ foo():void
+ num1:int
+ num2:int
\ No newline at end of file
--- /dev/null
+class Method {
+ int num1;
+ int num2;
+
+ Method() {}
+ void foo() {<caret>}
+}
\ No newline at end of file
--- /dev/null
+-Method.java
+ -Method
+ Method()
+ [foo():void]
+ num1:int
+ num2:int
\ No newline at end of file
--- /dev/null
+/*
+ * 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();}
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
}
}
- public void selectPsiElement(PsiElement element) {
+ @Nullable
+ public FilteringTreeStructure.FilteringNode selectPsiElement(PsiElement element) {
Set<PsiElement> parents = getAllParents(element);
FilteringTreeStructure.FilteringNode node = (FilteringTreeStructure.FilteringNode)myAbstractTreeBuilder.getRootElement();
if (myAbstractTreeBuilder.getSelectedElements().isEmpty()) {
TreeUtil.selectFirstNode(myTree);
}
- return;
-
+ return node;
}
}
TreeUtil.selectFirstNode(myTree);
+ return null;
}
private static Set<PsiElement> getAllParents(PsiElement element) {
}
}
- private static String getPropertyName(String propertyName) {
+ public static String getPropertyName(String propertyName) {
return propertyName + ".file.structure.state";
}
}
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,
}
public Object[] getEqualityObjects() {
- return NONE;
+ return new Object[]{myDelegate};
}
@Override
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());
}
getStructure().rebuild();
updateTree();
TreeUtil.expandAll(getTree());
- myPopup.selectPsiElement(getFile());
+ final FilteringTreeStructure.FilteringNode node = myPopup.selectPsiElement(myPopup.getCurrentElement(getFile()));
+ getTree().getSelectionModel().setSelectionPath(getTree().getPath(node));
}
});
}