mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
selection tests
This commit is contained in:
+2
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Constructor {
|
||||
int num1;
|
||||
int num2;
|
||||
|
||||
Constructor() {<caret>}
|
||||
void foo() {}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
-Constructor.java
|
||||
-Constructor
|
||||
[Constructor()]
|
||||
foo():void
|
||||
num1:int
|
||||
num2:int
|
||||
@@ -0,0 +1,7 @@
|
||||
class Field {
|
||||
int num1;
|
||||
int <caret>num2;
|
||||
|
||||
Field() {}
|
||||
void foo() {}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
-Field.java
|
||||
-Field
|
||||
Field()
|
||||
foo():void
|
||||
num1:int
|
||||
[num2:int]
|
||||
@@ -0,0 +1,7 @@
|
||||
class InsideClass {
|
||||
int num1;
|
||||
int num2;
|
||||
<caret>
|
||||
InsideClass() {}
|
||||
void foo() {}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
-InsideClass.java
|
||||
-[InsideClass]
|
||||
InsideClass()
|
||||
foo():void
|
||||
num1:int
|
||||
num2:int
|
||||
@@ -0,0 +1,7 @@
|
||||
class Method {
|
||||
int num1;
|
||||
int num2;
|
||||
|
||||
Method() {}
|
||||
void foo() {<caret>}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
-Method.java
|
||||
-Method
|
||||
Method()
|
||||
[foo():void]
|
||||
num1:int
|
||||
num2:int
|
||||
+31
@@ -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();}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
+1
-1
@@ -241,7 +241,7 @@ public class FilteringTreeStructure extends AbstractTreeStructure {
|
||||
}
|
||||
|
||||
public Object[] getEqualityObjects() {
|
||||
return NONE;
|
||||
return new Object[]{myDelegate};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user