Java: Added priorities in the completion list for arguments of getField() and getMethod() (IDEA-167250)

This commit is contained in:
Pavel Dolgov
2017-02-14 17:11:55 +03:00
parent 8754155e85
commit e4ec230e5d
23 changed files with 203 additions and 31 deletions
@@ -22,5 +22,5 @@ class DeclaredField {
class Test {
public int num;
public int num2;
int num3;
int num1;
}
@@ -22,5 +22,5 @@ class DeclaredField {
class Test {
public int num;
public int num2;
int num3;
int num1;
}
@@ -22,7 +22,7 @@ class DecalredMethod {
class Test {
public void method(){}
public void method2(A a, B b){}
public void method3(){}
void method1(){}
}
class A {}
@@ -22,7 +22,7 @@ class DecalredMethod2 {
class Test {
void method(){}
void method2(A a, B b){}
void method3(){}
void method1(){}
}
class A {}
@@ -15,14 +15,14 @@
*/
class DecalredMethod2 {
void foo() {
Test.class.getDeclaredMethod("method3");
Test.class.getDeclaredMethod("method1");
}
}
class Test {
void method(){}
void method2(A a, B b){}
void method3(){}
void method1(){}
}
class A {}
@@ -22,7 +22,7 @@ class DecalredMethod {
class Test {
public void method(){}
public void method2(A a, B b){}
public void method3(){}
void method1(){}
}
class A {}
@@ -22,5 +22,5 @@ class ForNameDeclaredField {
class Test {
public int num;
public int num2;
int num3;
int num1;
}
@@ -15,12 +15,12 @@
*/
class ForNameDeclaredField {
void foo() {
Class.forName("Test").getDeclaredField("num3");
Class.forName("Test").getDeclaredField("num1");
}
}
class Test {
public int num;
public int num2;
int num3;
int num1;
}
@@ -22,7 +22,7 @@ class ForNameDeclaredMethod {
class Test {
public void method(){}
public void method2(A a, B b){}
void method3(){}
void method1(){}
}
class A {}
@@ -22,7 +22,7 @@ class ForNameDeclaredMethod {
class Test {
public void method(){}
public void method2(A a, B b){}
void method3(){}
void method1(){}
}
class A {}
@@ -0,0 +1,17 @@
class HasConstructor {
void foo() {
Test.class.getMethod("<caret>");
}
}
class Test {
public Test() {}
Test(int n) {}
public void method(){}
public void method2(A a, B b){}
void method1(){}
}
class A {}
class B {}
class C {}
@@ -0,0 +1,17 @@
class HasConstructor {
void foo() {
Test.class.getMethod("method1");
}
}
class Test {
public Test() {}
Test(int n) {}
public void method(){}
public void method2(A a, B b){}
void method1(){}
}
class A {}
class B {}
class C {}
@@ -0,0 +1,9 @@
class Main {
void foo() {
Test.class.getMethod("<caret>");
}
}
class Test {
public void method(){}
}
@@ -0,0 +1,9 @@
class Main {
void foo() {
Test.class.getMethod("notifyAll");
}
}
class Test {
public void method(){}
}
@@ -0,0 +1,5 @@
class Main {
void foo() {
Object.class.getMethod("<caret>");
}
}
@@ -0,0 +1,5 @@
class Main {
void foo() {
Object.class.getMethod("wait", long.class);
}
}
@@ -0,0 +1,17 @@
class Main {
void foo() {
Test.class.getMethod("<caret>");
}
}
class Test {
public Test() {}
Test(int n) {}
public void method(){}
void method(A a, B b){}
public void method(C c){}
}
class A {}
class B {}
class C {}
@@ -0,0 +1,17 @@
class Main {
void foo() {
Test.class.getMethod("method", A.class, B.class);
}
}
class Test {
public Test() {}
Test(int n) {}
public void method(){}
void method(A a, B b){}
public void method(C c){}
}
class A {}
class B {}
class C {}
@@ -0,0 +1,53 @@
/*
* Copyright 2000-2017 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.codeInsight.completion
import com.intellij.JavaTestUtil
/**
* @author Pavel.Dolgov
*/
class JavaReflectionCompletionOverloadTest : LightFixtureCompletionTestCase() {
override fun getBasePath() = JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/reflectionOverload/"
fun testOverloadMethods() = doTest(2, "method()", "method(C c)", "method(A a,B b)")
fun testJavaLangObjectMethods() = doTest(6,
"method()",
"equals(java.lang.Object obj)", "hashCode()", "toString()",
"getClass()", "notify()", "notifyAll()",
"wait()", "wait(long timeout)", "wait(long timeout,int nanos)"
)
fun testJavaLangObjectOwnMethods() = doTest(9,
"clone()", "equals(java.lang.Object obj)", "hashCode()",
"toString()", "finalize()", "getClass()",
"notify()", "notifyAll()",
"wait()", "wait(long timeout)", "wait(long timeout,int nanos)",
"registerNatives()")
private fun doTest(index: Int, vararg expected: String) {
configureByFile(getTestName(false) + ".java")
val lookupItems = lookup.items
val texts = lookupItemTexts(lookupItems, expected.size)
assertOrderedEquals(texts, *expected)
if (index >= 0) selectItem(lookupItems[index])
myFixture.checkResultByFile(getTestName(false) + "_after.java")
}
}
@@ -34,15 +34,15 @@ public class JavaReflectionCompletionTest extends LightFixtureCompletionTestCase
}
public void testDeclaredField() throws Exception {
doTest(1, "num", "num2", "num3");
doTest(2, "num", "num1", "num2");
}
public void testDeclaredMethod() throws Exception {
doTest(1, "method", "method2", "method3");
doTest(2, "method", "method1", "method2");
}
public void testDeclaredMethod2() throws Exception {
doTest(2, "method", "method2", "method3");
doTest(1, "method", "method1", "method2");
}
public void testMethod() throws Exception {
@@ -50,7 +50,7 @@ public class JavaReflectionCompletionTest extends LightFixtureCompletionTestCase
}
public void testForNameDeclaredMethod() throws Exception {
doTest(1, "method", "method2", "method3");
doTest(2, "method", "method1", "method2");
}
public void testForNameMethod() throws Exception {
@@ -62,7 +62,7 @@ public class JavaReflectionCompletionTest extends LightFixtureCompletionTestCase
}
public void testForNameDeclaredField() throws Exception {
doTest(2, "num", "num2", "num3");
doTest(1, "num", "num1", "num2");
}
public void testVarargMethod() throws Exception {
@@ -135,7 +135,7 @@ public class JavaReflectionCompletionTest extends LightFixtureCompletionTestCase
}
public void testConstantGetClassField() throws Exception {
doTest(1, "num", "num2", "num3");
doTest(2, "num", "num3", "num2");
}
public void testExpressionGetClassField() throws Exception {
@@ -165,9 +165,14 @@ public class JavaReflectionCompletionTest extends LightFixtureCompletionTestCase
doTest(0, "PublicClass");
}
public void testHasConstructor() {
doTest(2, "method", "method2", "method1");
}
private void doTest(int index, String... expected) {
configureByFile(getTestName(false) + ".java");
assertStringItems(expected);
assertFirstStringItems(expected);
if (index >= 0) selectItem(getLookup().getItems().get(index));
myFixture.checkResultByFile(getTestName(false) + "_after.java");
}