diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java index 227d387..583416b 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java @@ -37,6 +37,7 @@ import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jdt.internal.core.search.indexing.IndexManager; import org.eclipse.jdt.internal.core.search.matching.AndPattern; +import org.eclipse.jdt.internal.core.search.matching.MethodPattern; /** * Non-regression tests for bugs fixed in Java Search engine. @@ -45,7 +46,7 @@ static { // org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true; -// TESTS_NAMES = new String[] {"testBug400905_0002"}; +// TESTS_NAMES = new String[] {"testBug429012"}; } public JavaSearchBugs8Tests(String name) { @@ -160,6 +161,25 @@ suite.addTest(new JavaSearchBugs8Tests("test430159b")); suite.addTest(new JavaSearchBugs8Tests("test430159c")); suite.addTest(new JavaSearchBugs8Tests("test430159d")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0001")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0002")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0003")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0004")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0005")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0006")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0007")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0008")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0009")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0010")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0011")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0012")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0013")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0014")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0015")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0016")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0017")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0018")); + suite.addTest(new JavaSearchBugs8Tests("testBug429012_0019")); return suite; } class TestCollector extends JavaSearchResultCollector { @@ -3770,6 +3790,656 @@ assertSearchResults("" ); } +/** + * @bug 429012 + * @test tests search for Reference expression - super:: form, without type arguments + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0001() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "public class X extends Y {\n" + + " public static void main(String [] args) {\n" + + " new X().doit();\n" + + " }\n" + + " void doit() {\n" + + " I i = super::foo;\n" + + " i.foo(10); \n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + ); + IType type = this.workingCopies[0].getType("Y"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.doit() [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - super:: form, with type arguments + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0002() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "public class X extends Y {\n" + + " public static void main(String [] args) {\n" + + " new X().doit();\n" + + " }\n" + + " void doit() {\n" + + " I i = super::foo;\n" + + " i.foo(10); \n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + ); + IType type = this.workingCopies[0].getType("Y"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.doit() [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - SimpleName:: form, without type arguments. + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0003() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " public void doit();\n" + + "}\n" + + "class Y {\n" + + " Y() {}\n" + + " Y(int i) {}\n" + + "}\n" + + "\n" + + "public class X {\n" + + " X(int i) {} \n" + + " static void foo() {}\n" + + " static void foo(int i) {}\n" + + " I i = X :: foo;\n" + + " I j = Y :: new;\n" + + " public static void main() { \n" + + " Y y = new Y(); \n" + + " foo(); \n" + + " }\n" + + "}\n" + ); + IType type = this.workingCopies[0].getType("X"); + IMethod method = type.getMethod("foo", null); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java b429012.X.i [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - SimpleName:: form, with type arguments. + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0004() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = Y::foo;\n" + + " i.foo(10); \n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + ); + IType type = this.workingCopies[0].getType("Y"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.main(String[]) [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - QualifiedName:: form, without type arguments. + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0005() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = Y.Z::foo;\n" + + " i.foo(10); \n" + + " }\n" + + "}\n" + + "class Y {\n" + + " static class Z {\n" + + " public static void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + "}\n" + ); + IType type = this.workingCopies[0].getType("Y").getType("Z"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.main(String[]) [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - QualifiedName:: form, with type arguments. + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0006() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = Y.Z::foo;\n" + + " i.foo(10); \n" + + " }\n" + + "}\n" + + "class Y {\n" + + " static class Z {\n" + + " public static void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + "}\n" + ); + IType type = this.workingCopies[0].getType("Y").getType("Z"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.main(String[]) [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - Primary:: form, without type arguments. + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0007() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = new Y()::foo;\n" + + " i.foo(10); \n" + + " }\n" + + "}\n" + + "class Y {\n" + + " void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + ); + IType type = this.workingCopies[0].getType("Y"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.main(String[]) [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - Primary:: form, with type arguments. + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0008() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = new Y()::foo;\n" + + " i.foo(10); \n" + + " }\n" + + "}\n" + + "class Y {\n" + + " void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + ); + IType type = this.workingCopies[0].getType("Y"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.main(String[]) [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - X:: form, without type arguments + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0009() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(Y y, int x);\n" + + "}\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = Y::foo;\n" + + " i.foo(new Y(), 10);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + ); + IType type = this.workingCopies[0].getType("Y"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.main(String[]) [foo] EXACT_MATCH" + ); +} + + +/** + * @bug 429012 + * @test tests search for Reference expression - X:: form, with type arguments + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0010() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(Y y, int x);\n" + + "}\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = Y::foo;\n" + + " i.foo(new Y(), 10);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + ); + IType type = this.workingCopies[0].getType("Y"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.main(String[]) [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - X.Name :: form, without type arguments + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0011() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(Y.Z z, int x);\n" + + "}\n" + + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " public static void main(String [] args) {\n" + + " I i = Y.Z::foo;\n" + + " i.foo(new Y().new Z(), 10); \n" + + " }\n" + + "}\n" + + "class Y {\n" + + " class Z {\n" + + " void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + ); + IType type = this.workingCopies[0].getType("Y"); + type = type.getType("Z"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.main(String[]) [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - X.Name :: form, with type arguments + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0012() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(Y.Z z, int x);\n" + + "}\n" + + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " public static void main(String [] args) {\n" + + " I i = Y.Z::foo;\n" + + " i.foo(new Y().new Z(), 10); \n" + + " }\n" + + "}\n" + + "class Y {\n" + + " class Z {\n" + + " void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + ); + IType type = this.workingCopies[0].getType("Y"); + type = type.getType("Z"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.main(String[]) [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - X.Y :: form, without type arguments + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0013() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(Y.Z z, int x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = Y.Z::foo;\n" + + " i.foo(new Y().new Z(), 10); \n" + + " }\n" + + "}\n" + + "class Y {\n" + + " class Z {\n" + + " void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + ); + IType type = this.workingCopies[0].getType("Y"); + type = type.getType("Z"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, ERASURE_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.main(String[]) [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - X.Y :: form, with type arguments + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0014() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(Y.Z z, int x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = Y.Z::foo;\n" + + " i.foo(new Y().new Z(), 10); \n" + + " }\n" + + "}\n" + + "class Y {\n" + + " class Z {\n" + + " void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + ); + IType type = this.workingCopies[0].getType("Y"); + type = type.getType("Z"); + IMethod method = type.getMethod("foo", new String[] {"I"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.main(String[]) [foo] EXACT_MATCH" + ); +} + +/** + * @bug 429012 + * @test tests search for Reference expression - X.Y :: new form, with type arguments + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012" + * + */ +public void testBug429012_0015() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429012/X.java", + "interface I {\n" + + " void foo(Y y);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = Y.Z::new;\n" + + " i.foo(new Y()); \n" + + " }\n" + + "}\n" + + "class Y {\n" + + " class Z {\n" + + " Z(Y y) {\n" + + " System.out.println(\"Y.Z::new\");\n" + + " }\n" + + " Z1(Y y) {\n" + + " System.out.println(\"Y.Z::new\");\n" + + " }\n" + + " }\n" + + "}\n" + ); + IType type = this.workingCopies[0].getType("Y"); + type = type.getType("Z"); + IMethod method = type.getMethod("Z", new String[] {"QY;"}); + search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE); + assertSearchResults( + "src/b429012/X.java void b429012.X.main(String[]) [Y.Z::new] EXACT_MATCH" + ); +}// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012, [1.8][search] Add finegrain (limitTo) option for method reference expressions +public void testBug429012_0016() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429498/X.java", + "interface I {\n" + + " public void doit();\n" + + "}\n" + + "public class X {\n" + + " static void foo() {}\n" + + " static void foo(int i) {}\n" + + " I i = X :: foo;\n" + + " static void bar() {foo();}\n" + + "}\n" + ); + String str = this.workingCopies[0].getSource(); + String selection = "foo"; + int start = str.indexOf(selection); + int length = selection.length(); + + IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); + MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], METHOD_REFERENCE_EXPRESSION, ERASURE_RULE); + + new SearchEngine(this.workingCopies).search(pattern, + new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, + getJavaSearchWorkingCopiesScope(), + this.resultCollector, + null); + assertSearchResults( + "src/b429498/X.java b429498.X.i [foo] EXACT_MATCH" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012, [1.8][search] Add finegrain (limitTo) option for method reference expressions +public void testBug429012_0017() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/test/Test.java", + "interface I { \n" + + " int thrice(int p);\n" + + "}\n" + + "class Y {\n" + + " int goo(int x) { return 3 * x; } \n" + + "}\n" + + "public class X extends Y {\n" + + " public void main(String[] args) { \n" + + " I i = this::goo;\n" + + " i = super::goo;\n" + + " }\n" + + "}\n" + ); + + search(this.workingCopies[0].getType("Y").getMethod("goo", new String[] { "I" }), METHOD_REFERENCE_EXPRESSION); + assertSearchResults( + "src/test/Test.java void test.X.main(String[]) [goo] EXACT_MATCH\n" + + "src/test/Test.java void test.X.main(String[]) [goo] EXACT_MATCH" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012, [1.8][search] Add finegrain (limitTo) option for method reference expressions +public void testBug429012_0018() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/test/Test.java", + "interface I { \n" + + " int thrice(int p);\n" + + "}\n" + + "class Y {\n" + + " int goo(int x) { return 3 * x; } \n" + + "}\n" + + "public class X extends Y {\n" + + " public void main(String[] args) { \n" + + " I i = this::goo;\n" + + " i = super::goo;\n" + + " }\n" + + "}\n" + ); + + search(this.workingCopies[0].getType("Y").getMethod("goo", new String[] { "I" }), THIS_REFERENCE | METHOD_REFERENCE_EXPRESSION); + assertSearchResults( + "src/test/Test.java void test.X.main(String[]) [goo] EXACT_MATCH\n" + + "src/test/Test.java void test.X.main(String[]) [goo] EXACT_MATCH" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012, [1.8][search] Add finegrain (limitTo) option for method reference expressions +public void testBug429012_0019() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/test/Test.java", + "interface I { \n" + + " int thrice(int p);\n" + + "}\n" + + "class Y {\n" + + " static class Z {\n" + + " static int goo(int x) { return 3 * x; } \n" + + " I i = Z::goo;\n" + + " }\n" + + "}\n" + + "public class X extends Y.Z {\n" + + " public void main(String[] args) { \n" + + " I i = Y.Z::goo;\n" + + " }\n" + + "}\n" + ); + + search(this.workingCopies[0].getType("Y").getType("Z").getMethod("goo", new String[] { "I" }), METHOD_REFERENCE_EXPRESSION); + assertSearchResults( + "src/test/Test.java test.Y$Z.i [goo] EXACT_MATCH\n" + + "src/test/Test.java void test.X.main(String[]) [goo] EXACT_MATCH" +); +} // Add new tests in JavaSearchBugs8Tests } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SearchTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SearchTests.java index c295e36..6b4fe09 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SearchTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SearchTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1050,7 +1050,7 @@ "QUALIFIED_REFERENCE | " + "THIS_REFERENCE | " + "IMPLICIT_THIS_REFERENCE | " + - " | " + // unused slots + "METHOD_REFERENCE_EXPRESSION | " + // unused slots " | " + " | ", searchPattern); diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/IJavaSearchConstants.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/IJavaSearchConstants.java index 2a731fb..77f77cd 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/IJavaSearchConstants.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/IJavaSearchConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -466,6 +466,17 @@ */ int IMPLICIT_THIS_REFERENCE = 0x8000000; + /** + * Return only method reference expressions, e.g. A::foo. + *

+ * When this flag is set, only {@link MethodReferenceMatch} matches will be + * returned. + *

+ * @since 3.10 + * @category limitTo + */ + int METHOD_REFERENCE_EXPRESSION = 0x10000000; + /* Syntactic match modes */ /** diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/SearchPattern.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/SearchPattern.java index bd1f4a7..802b4f8 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/SearchPattern.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/SearchPattern.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1544,6 +1544,9 @@ * * {@link IJavaSearchConstants#IMPLICIT_THIS_REFERENCE IMPLICIT_THIS_REFERENCE} * Return only field accesses or method invocations without any qualification. + * + * {@link IJavaSearchConstants#METHOD_REFERENCE_EXPRESSION METHOD_REFERENCE_EXPRESSION} + * Return only method reference expressions (e.g. A :: foo). * * * @@ -1721,7 +1724,10 @@ * * {@link IJavaSearchConstants#IMPLICIT_THIS_REFERENCE IMPLICIT_THIS_REFERENCE} * Return only field accesses or method invocations without any qualification. - * +* + * {@link IJavaSearchConstants#METHOD_REFERENCE_EXPRESSION METHOD_REFERENCE_EXPRESSION} + * Return only method reference expressions (e.g. A :: foo). +* * * * @return a search pattern for a Java element or null if the given element is ill-formed @@ -1830,6 +1836,9 @@ * * {@link IJavaSearchConstants#IMPLICIT_THIS_REFERENCE IMPLICIT_THIS_REFERENCE} * Return only field accesses or method invocations without any qualification. + * + * {@link IJavaSearchConstants#METHOD_REFERENCE_EXPRESSION METHOD_REFERENCE_EXPRESSION} + * Return only method reference expressions (e.g. A :: foo). * * * diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorPattern.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorPattern.java index 2cdb4a3..a15d400 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorPattern.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorPattern.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -52,7 +52,8 @@ IJavaSearchConstants.SUPER_REFERENCE | IJavaSearchConstants.QUALIFIED_REFERENCE | IJavaSearchConstants.THIS_REFERENCE | - IJavaSearchConstants.IMPLICIT_THIS_REFERENCE; + IJavaSearchConstants.IMPLICIT_THIS_REFERENCE | + IJavaSearchConstants.METHOD_REFERENCE_EXPRESSION; /** diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchPattern.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchPattern.java index f53e2e2..41001c7 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchPattern.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchPattern.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -157,6 +157,9 @@ case IJavaSearchConstants.IMPLICIT_THIS_REFERENCE: buffer.append("IMPLICIT_THIS_REFERENCE"); //$NON-NLS-1$ break; + case IJavaSearchConstants.METHOD_REFERENCE_EXPRESSION: + buffer.append("METHOD_REFERENCE_EXPRESSION"); //$NON-NLS-1$ + break; } } return buffer.toString(); diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java index 7dbd0b4..76339da 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java @@ -524,6 +524,8 @@ super.consumeReferenceExpression(referenceExpression); if (this.patternFineGrain == 0) { this.patternLocator.match(referenceExpression, this.nodeSet); + } else if ((this.patternFineGrain & IJavaSearchConstants.METHOD_REFERENCE_EXPRESSION) != 0) { + this.patternLocator.match(referenceExpression, this.nodeSet); } else if (referenceExpression.lhs.isThis()) { if ((this.patternFineGrain & IJavaSearchConstants.THIS_REFERENCE) != 0) { this.patternLocator.match(referenceExpression, this.nodeSet); diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java index e746a32..ea4899a 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -56,7 +56,8 @@ IJavaSearchConstants.SUPER_REFERENCE | IJavaSearchConstants.QUALIFIED_REFERENCE | IJavaSearchConstants.THIS_REFERENCE | - IJavaSearchConstants.IMPLICIT_THIS_REFERENCE; + IJavaSearchConstants.IMPLICIT_THIS_REFERENCE | + IJavaSearchConstants.METHOD_REFERENCE_EXPRESSION; /** * Method entries are encoded as selector '/' Arity: