mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
cleanup
This commit is contained in:
+128
-112
@@ -25,33 +25,36 @@ import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import com.intellij.util.CommonProcessors;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ImplementationsViewTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testFromCompletion() {
|
||||
myFixture.configureByText("a.java", "public class Foo {\n" +
|
||||
" private final String text;\n" +
|
||||
"\n" +
|
||||
" public Foo(String text) {\n" +
|
||||
"// this.text = text;\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" public Foo(int i) {\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" final Foo foo = new Foo(\"\");\n" +
|
||||
" foo.to<caret>\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" @Override\n" +
|
||||
" public String toString() {\n" +
|
||||
" return \"text\";\n" +
|
||||
" }\n" +
|
||||
" public void totttt(){}" +
|
||||
"}");
|
||||
@Language("JAVA")
|
||||
String text = "public class Foo {\n" +
|
||||
" private final String text;\n" +
|
||||
"\n" +
|
||||
" public Foo(String text) {\n" +
|
||||
"// this.text = text;\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" public Foo(int i) {\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" final Foo foo = new Foo(\"\");\n" +
|
||||
" foo.to<caret>\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" @Override\n" +
|
||||
" public String toString() {\n" +
|
||||
" return \"text\";\n" +
|
||||
" }\n" +
|
||||
" public void totttt(){}" +
|
||||
"}";
|
||||
myFixture.configureByText("a.java", text);
|
||||
myFixture.completeBasic();
|
||||
|
||||
PsiElement element =
|
||||
@@ -67,21 +70,23 @@ public class ImplementationsViewTest extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testFromEditor() {
|
||||
myFixture.configureByText("a.java", "public class Foo {\n" +
|
||||
" private final String text;\n" +
|
||||
"\n" +
|
||||
" public Foo(String text) {\n" +
|
||||
"// this.text = text;\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" public Foo(int i) {\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" @Override\n" +
|
||||
" public String to<caret>String() {\n" +
|
||||
" return \"text\";\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
@Language("JAVA")
|
||||
String text = "public class Foo {\n" +
|
||||
" private final String text;\n" +
|
||||
"\n" +
|
||||
" public Foo(String text) {\n" +
|
||||
"// this.text = text;\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" public Foo(int i) {\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" @Override\n" +
|
||||
" public String to<caret>String() {\n" +
|
||||
" return \"text\";\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
myFixture.configureByText("a.java", text);
|
||||
PsiElement element =
|
||||
TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtil.getInstance().getAllAccepted());
|
||||
|
||||
@@ -109,28 +114,30 @@ public class ImplementationsViewTest extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testInnerClasses() {
|
||||
myFixture.configureByText("a.java", "abstract class AF<caret>oo{\n" +
|
||||
" abstract boolean aaa();\n" +
|
||||
" static class AFoo1 extends AFoo {\n" +
|
||||
" @Override\n" +
|
||||
" boolean aaa() {\n" +
|
||||
" return false;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" static class AFoo3 extends AFoo {\n" +
|
||||
" @Override\n" +
|
||||
" boolean aaa() {\n" +
|
||||
" return false;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" static class AFoo2 extends AFoo {\n" +
|
||||
" @Override\n" +
|
||||
" boolean aaa() {\n" +
|
||||
" return false;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" \n" +
|
||||
"}");
|
||||
@Language("JAVA")
|
||||
String text = "abstract class AF<caret>oo{\n" +
|
||||
" abstract boolean aaa();\n" +
|
||||
" static class AFoo1 extends AFoo {\n" +
|
||||
" @Override\n" +
|
||||
" boolean aaa() {\n" +
|
||||
" return false;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" static class AFoo3 extends AFoo {\n" +
|
||||
" @Override\n" +
|
||||
" boolean aaa() {\n" +
|
||||
" return false;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" static class AFoo2 extends AFoo {\n" +
|
||||
" @Override\n" +
|
||||
" boolean aaa() {\n" +
|
||||
" return false;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" \n" +
|
||||
"}";
|
||||
myFixture.configureByText("a.java", text);
|
||||
PsiClass psiClass =
|
||||
(PsiClass)TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtil.getInstance().getAllAccepted());
|
||||
|
||||
@@ -155,14 +162,16 @@ public class ImplementationsViewTest extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testFunctionalInterface() {
|
||||
myFixture.configureByText("a.java", "interface AF<caret>oo{\n" +
|
||||
" boolean aaa();\n" +
|
||||
"}\n" +
|
||||
"class AFooImpl {\n" +
|
||||
" {\n" +
|
||||
" AFoo a = () -> {return false;};\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
@Language("JAVA")
|
||||
String text = "interface AF<caret>oo{\n" +
|
||||
" boolean aaa();\n" +
|
||||
"}\n" +
|
||||
"class AFooImpl {\n" +
|
||||
" {\n" +
|
||||
" AFoo a = () -> {return false;};\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
myFixture.configureByText("a.java", text);
|
||||
PsiClass psiClass =
|
||||
(PsiClass)TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtil.getInstance().getAllAccepted());
|
||||
|
||||
@@ -176,10 +185,12 @@ public class ImplementationsViewTest extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testInterfaceConstants() {
|
||||
myFixture.configureByText("a.java", "interface AF<caret>oo{\n" +
|
||||
" AFoo IMPL = new AFoo(){};\n" +
|
||||
" boolean aaa();\n" +
|
||||
"}");
|
||||
@Language("JAVA")
|
||||
String text = "interface AF<caret>oo{\n" +
|
||||
" AFoo IMPL = new AFoo(){};\n" +
|
||||
" boolean aaa();\n" +
|
||||
"}";
|
||||
myFixture.configureByText("a.java", text);
|
||||
PsiClass psiClass =
|
||||
(PsiClass)TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtil.getInstance().getAllAccepted());
|
||||
|
||||
@@ -193,14 +204,16 @@ public class ImplementationsViewTest extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testInterfaceMethodOfFunctionalInterface() {
|
||||
myFixture.configureByText("a.java", "interface AFoo{\n" +
|
||||
" boolean a<caret>aa();\n" +
|
||||
"}\n" +
|
||||
"class AFooImpl {\n" +
|
||||
" {\n" +
|
||||
" AFoo a = () -> {return false;};\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
@Language("JAVA")
|
||||
String text = "interface AFoo{\n" +
|
||||
" boolean a<caret>aa();\n" +
|
||||
"}\n" +
|
||||
"class AFooImpl {\n" +
|
||||
" {\n" +
|
||||
" AFoo a = () -> {return false;};\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
myFixture.configureByText("a.java", text);
|
||||
PsiMethod psiMethod =
|
||||
(PsiMethod)TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtil.getInstance().getAllAccepted());
|
||||
|
||||
@@ -220,15 +233,17 @@ public class ImplementationsViewTest extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testDefaultMethodOfFunctionalInterface() {
|
||||
myFixture.configureByText("a.java", "interface AFoo{\n" +
|
||||
" default boolean a<caret>aa(){}\n" +
|
||||
" boolean bbb();" +
|
||||
"}\n" +
|
||||
"class AFooImpl {\n" +
|
||||
" {\n" +
|
||||
" AFoo a = () -> {return false;};\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
@Language("JAVA")
|
||||
String text = "interface AFoo{\n" +
|
||||
" default boolean a<caret>aa(){}\n" +
|
||||
" boolean bbb();" +
|
||||
"}\n" +
|
||||
"class AFooImpl {\n" +
|
||||
" {\n" +
|
||||
" AFoo a = () -> {return false;};\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
myFixture.configureByText("a.java", text);
|
||||
PsiMethod psiMethod =
|
||||
(PsiMethod)TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtil.getInstance().getAllAccepted());
|
||||
|
||||
@@ -242,28 +257,30 @@ public class ImplementationsViewTest extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testMethodsInInnerClasses() {
|
||||
myFixture.configureByText("a.java", "abstract class AFoo{\n" +
|
||||
" abstract boolean a<caret>aa();\n" +
|
||||
" static class AFoo1 extends AFoo {\n" +
|
||||
" @Override\n" +
|
||||
" boolean aaa() {\n" +
|
||||
" return false;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" static class AFoo3 extends AFoo {\n" +
|
||||
" @Override\n" +
|
||||
" boolean aaa() {\n" +
|
||||
" return false;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" static class AFoo2 extends AFoo {\n" +
|
||||
" @Override\n" +
|
||||
" boolean aaa() {\n" +
|
||||
" return false;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" \n" +
|
||||
"}");
|
||||
@Language("JAVA")
|
||||
String text = "abstract class AFoo{\n" +
|
||||
" abstract boolean a<caret>aa();\n" +
|
||||
" static class AFoo1 extends AFoo {\n" +
|
||||
" @Override\n" +
|
||||
" boolean aaa() {\n" +
|
||||
" return false;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" static class AFoo3 extends AFoo {\n" +
|
||||
" @Override\n" +
|
||||
" boolean aaa() {\n" +
|
||||
" return false;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" static class AFoo2 extends AFoo {\n" +
|
||||
" @Override\n" +
|
||||
" boolean aaa() {\n" +
|
||||
" return false;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" \n" +
|
||||
"}";
|
||||
myFixture.configureByText("a.java", text);
|
||||
PsiMethod psiMethod =
|
||||
(PsiMethod)TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtil.getInstance().getAllAccepted());
|
||||
|
||||
@@ -274,14 +291,13 @@ public class ImplementationsViewTest extends LightCodeInsightFixtureTestCase {
|
||||
all.addAll(methods);
|
||||
|
||||
//make sure they are in predefined order
|
||||
Collections.sort(all, (o1, o2) -> o1.getContainingClass().getQualifiedName()
|
||||
.compareTo(o2.getContainingClass().getQualifiedName()));
|
||||
Collections.sort(all, Comparator.comparing(o -> o.getContainingClass().getQualifiedName()));
|
||||
final ImplementationViewComponent component =
|
||||
new ImplementationViewComponent(all.toArray(PsiElement.EMPTY_ARRAY), 0);
|
||||
assertContent(component, new String[]{"a.java (AFoo)", "a.java (AFoo1 in AFoo)", "a.java (AFoo2 in AFoo)", "a.java (AFoo3 in AFoo)"});
|
||||
}
|
||||
|
||||
public static void assertContent(ImplementationViewComponent component, String[] expects) {
|
||||
private static void assertContent(ImplementationViewComponent component, String[] expects) {
|
||||
try {
|
||||
final String[] visibleFiles = component.getVisibleFiles();
|
||||
Assert.assertArrayEquals(Arrays.toString(visibleFiles), expects, visibleFiles);
|
||||
|
||||
Reference in New Issue
Block a user