Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorM N Palat2014-04-25 13:38:23 +0000
committerM N Palat2014-04-25 13:38:23 +0000
commitbf2199048d434ee8a7461950468d3a2335a30990 (patch)
treee22a4470468ade375b9367783c591a771cc2e7c0
parentb6e21c793f3617f9c60f843e02a0537d5bd09d93 (diff)
downloadeclipse.jdt.core-bf2199048d434ee8a7461950468d3a2335a30990.tar.gz
eclipse.jdt.core-bf2199048d434ee8a7461950468d3a2335a30990.tar.xz
eclipse.jdt.core-bf2199048d434ee8a7461950468d3a2335a30990.zip
Fix (additional) for Bug 429012 [1.8][search] Add finegrain (limitTo)
option for method reference expressions
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java85
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java3
2 files changed, 39 insertions, 49 deletions
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 583416b8a2..210a80298d 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
@@ -179,7 +179,6 @@ public static Test suite() {
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 {
@@ -3805,7 +3804,8 @@ public void testBug429012_0001() throws CoreException {
"}\n" +
"public class X extends Y {\n" +
" public static void main(String [] args) {\n" +
- " new X().doit();\n" +
+ " new X().doit();\n" +
+ " new X().foo(0);\n" +
" }\n" +
" void doit() {\n" +
" I i = super::foo;\n" +
@@ -3841,7 +3841,8 @@ public void testBug429012_0002() throws CoreException {
"}\n" +
"public class X extends Y {\n" +
" public static void main(String [] args) {\n" +
- " new X().doit();\n" +
+ " new X().doit();\n" +
+ " new X().foo(0);\n" +
" }\n" +
" void doit() {\n" +
" I i = super::<String>foo;\n" +
@@ -3916,6 +3917,7 @@ public void testBug429012_0004() throws CoreException {
"public class X {\n" +
" public static void main(String [] args) {\n" +
" I i = Y::<String>foo;\n" +
+ " new Y().foo(0);\n" +
" i.foo(10); \n" +
" }\n" +
"}\n" +
@@ -3949,6 +3951,7 @@ public void testBug429012_0005() throws CoreException {
"public class X {\n" +
" public static void main(String [] args) {\n" +
" I i = Y.Z::foo;\n" +
+ " Y.Z.foo(0);\n" +
" i.foo(10); \n" +
" }\n" +
"}\n" +
@@ -3984,6 +3987,7 @@ public void testBug429012_0006() throws CoreException {
"public class X {\n" +
" public static void main(String [] args) {\n" +
" I i = Y.Z::<String>foo;\n" +
+ " Y.Z.foo(0);\n" +
" i.foo(10); \n" +
" }\n" +
"}\n" +
@@ -4019,6 +4023,7 @@ public void testBug429012_0007() throws CoreException {
"public class X {\n" +
" public static void main(String [] args) {\n" +
" I i = new Y()::foo;\n" +
+ " new Y().foo(0);\n" +
" i.foo(10); \n" +
" }\n" +
"}\n" +
@@ -4052,6 +4057,7 @@ public void testBug429012_0008() throws CoreException {
"public class X {\n" +
" public static void main(String [] args) {\n" +
" I i = new Y()::<String>foo;\n" +
+ " new Y().foo(0);\n" +
" i.foo(10); \n" +
" }\n" +
"}\n" +
@@ -4088,6 +4094,7 @@ public void testBug429012_0009() throws CoreException {
" }\n" +
" public static void main(String[] args) {\n" +
" I i = Y<String>::foo;\n" +
+ " new Y<String>().foo(0);\n" +
" i.foo(new Y<String>(), 10);\n" +
" }\n" +
"}\n" +
@@ -4128,6 +4135,7 @@ public void testBug429012_0010() throws CoreException {
" }\n" +
" public static void main(String[] args) {\n" +
" I i = Y<String>::<String>foo;\n" +
+ " new Y<String>().foo(0);\n" +
" i.foo(new Y<String>(), 10);\n" +
" }\n" +
"}\n" +
@@ -4164,6 +4172,7 @@ public void testBug429012_0011() throws CoreException {
"public class X {\n" +
" @SuppressWarnings(\"unused\")\n" +
" public static void main(String [] args) {\n" +
+ " new Y<String>().new Z().foo(0);\n" +
" I i = Y<String>.Z::foo;\n" +
" i.foo(new Y<String>().new Z(), 10); \n" +
" }\n" +
@@ -4203,6 +4212,7 @@ public void testBug429012_0012() throws CoreException {
" @SuppressWarnings(\"unused\")\n" +
" public static void main(String [] args) {\n" +
" I i = Y<String>.Z::<String>foo;\n" +
+ " new Y<String>().new Z().foo(0);\n" +
" i.foo(new Y<String>().new Z(), 10); \n" +
" }\n" +
"}\n" +
@@ -4240,6 +4250,7 @@ public void testBug429012_0013() throws CoreException {
"public class X {\n" +
" public static void main(String [] args) {\n" +
" I i = Y<String>.Z<String>::foo;\n" +
+ " new Y<String>().new Z<String>().foo(0);\n" +
" i.foo(new Y<String>().new Z<String>(), 10); \n" +
" }\n" +
"}\n" +
@@ -4277,6 +4288,7 @@ public void testBug429012_0014() throws CoreException {
"public class X {\n" +
" public static void main(String [] args) {\n" +
" I i = Y<String>.Z<String>::<String>foo;\n" +
+ " new Y<String>().new Z<String>().foo(0);\n" +
" i.foo(new Y<String>().new Z<String>(), 10); \n" +
" }\n" +
"}\n" +
@@ -4308,32 +4320,29 @@ public void testBug429012_0014() throws CoreException {
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<String> y);\n" +
- "}\n" +
- "public class X {\n" +
- " public static void main(String [] args) {\n" +
- " I i = Y<String>.Z<String>::<String>new;\n" +
- " i.foo(new Y<String>()); \n" +
- " }\n" +
- "}\n" +
- "class Y<T> {\n" +
- " class Z<K> {\n" +
- " Z(Y<String> y) {\n" +
- " System.out.println(\"Y<T>.Z<K>::new\");\n" +
- " }\n" +
- " Z1(Y<String> y) {\n" +
- " System.out.println(\"Y<T>.Z<K>::new\");\n" +
- " }\n" +
- " }\n" +
+ "interface I<T> {\n"+
+ " T get();\n"+
+ "}\n"+
+ "/**\n"+
+ " * @see Y#Y()\n"+
+ " */\n"+
+ "public class X {\n"+
+ " public static void main(String [] args) {\n"+
+ " I<Y<String>> s = Y<String>::<Integer>new;\n"+
+ " s.get().equals(new Y<String>()); \n"+
+ " }\n"+
+ "}\n"+
+ "class Y<E> {\n"+
+ " <T> Y() {\n"+
+ " System.out.println(\"Y<E>::<T>new\");\n"+
+ " }\n"+
"}\n"
);
IType type = this.workingCopies[0].getType("Y");
- type = type.getType("Z");
- IMethod method = type.getMethod("Z", new String[] {"QY<QString;>;"});
- search(method, METHOD_REFERENCE_EXPRESSION, EXACT_RULE);
+ IMethod method = type.getMethod("Y", new String[] {});
+ search(method, METHOD_REFERENCE_EXPRESSION, ERASURE_RULE);
assertSearchResults(
- "src/b429012/X.java void b429012.X.main(String[]) [Y<String>.Z<String>::<String>new] EXACT_MATCH"
+ "src/b429012/X.java void b429012.X.main(String[]) [Y<String>::<Integer>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 {
@@ -4380,6 +4389,7 @@ public void testBug429012_0017() throws CoreException {
" public void main(String[] args) { \n" +
" I i = this::goo;\n" +
" i = super::goo;\n" +
+ " new Y().goo(0);\n" +
" }\n" +
"}\n"
);
@@ -4398,30 +4408,6 @@ public void testBug429012_0018() throws CoreException {
" 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" +
@@ -4430,6 +4416,7 @@ public void testBug429012_0019() throws CoreException {
"public class X extends Y.Z {\n" +
" public void main(String[] args) { \n" +
" I i = Y.Z::goo;\n" +
+ " Y.Z.goo(0);\n" +
" }\n" +
"}\n"
);
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java
index e60ac37a18..a234f403ee 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java
@@ -32,6 +32,9 @@ public ConstructorLocator(ConstructorPattern pattern) {
this.pattern = pattern;
}
+protected int fineGrain() {
+ return this.pattern.fineGrain;
+}
public int match(ASTNode node, MatchingNodeSet nodeSet) { // interested in ExplicitConstructorCall
if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH;
if (!(node instanceof ExplicitConstructorCall)) return IMPOSSIBLE_MATCH;

Back to the top