Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2019-04-04 08:50:54 -0400
committerJay Arthanareeswaran2019-04-05 03:54:40 -0400
commite2903f651c95c9633ac40208e5f6c4f81c7712ff (patch)
tree49453b7ea5ee50c4afcf82baaca574260ff4962b
parentdb34b6c6d93872a5055adf9f939b44095582de53 (diff)
downloadeclipse.jdt.core-e2903f651c95c9633ac40208e5f6c4f81c7712ff.tar.gz
eclipse.jdt.core-e2903f651c95c9633ac40208e5f6c4f81c7712ff.tar.xz
eclipse.jdt.core-e2903f651c95c9633ac40208e5f6c4f81c7712ff.zip
Bug 493433 - Call Hierarchy not showing callers when called via method
reference and the method is defined in an interface Change-Id: Id3d28c26c9c024b6c94aa60339175c9259c38ee7 Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.core.tests.builder/pom.xml2
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java87
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java4
4 files changed, 89 insertions, 6 deletions
diff --git a/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF
index 587766262c..ef6269ebdf 100644
--- a/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.core.tests.builder; singleton:=true
-Bundle-Version: 3.10.500.qualifier
+Bundle-Version: 3.10.600.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.jdt.core.tests.builder
diff --git a/org.eclipse.jdt.core.tests.builder/pom.xml b/org.eclipse.jdt.core.tests.builder/pom.xml
index 3a719fa685..2228e18ba7 100644
--- a/org.eclipse.jdt.core.tests.builder/pom.xml
+++ b/org.eclipse.jdt.core.tests.builder/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core.tests.builder</artifactId>
- <version>3.10.500-SNAPSHOT</version>
+ <version>3.10.600-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
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 a07cf417f3..85c47310e6 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
@@ -49,7 +49,7 @@ public class JavaSearchBugs8Tests extends AbstractJavaSearchTests {
static {
// org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true;
-// TESTS_NAMES = new String[] {"testBug429012"};
+// TESTS_NAMES = new String[] {"testBug493433"};
}
public JavaSearchBugs8Tests(String name) {
@@ -4909,7 +4909,90 @@ public void testBug531641() throws CoreException {
deleteProject("P");
}
}
-
+public void testBug493433a() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "import java.util.stream.IntStream;\n" +
+ "public class CallerHierarchyExample {\n" +
+ " interface Interface {\n" +
+ " void method(int i);\n" +
+ " }\n" +
+ " class Implementation implements Interface {\n" +
+ " public void method(int i) {}\n" +
+ " }\n" +
+ " void caller() {\n" +
+ " Interface pred = new Implementation();\n" +
+ " IntStream.range(0, 3).forEach(pred::method);\n" +
+ " }\n" +
+ "}"
+ );
+ IType type = this.workingCopies[0].getType("CallerHierarchyExample");
+ IJavaElement[] children = type.getChildren();
+ IType memberType = null;
+ for (IJavaElement iJavaElement : children) {
+ if (iJavaElement.getElementType() == IJavaElement.TYPE &&
+ iJavaElement.getElementName().equals("Implementation")) {
+ memberType = (IType) iJavaElement;
+ break;
+ }
+ }
+ assertNotNull("type should not be null", memberType);
+ IMethod method = null;
+ IMethod[] methods = memberType.getMethods();
+ for (IMethod iMethod : methods) {
+ if (iMethod.getElementName().equals("method")) {
+ method = iMethod;
+ break;
+ }
+ }
+ assertNotNull("type should not be null", method);
+ search(method, REFERENCES, EXACT_RULE);
+ assertSearchResults(
+ "src/X.java void CallerHierarchyExample.caller() [method] EXACT_MATCH"
+ );
+}
+public void testBug493433b() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "import java.util.stream.IntStream;\n" +
+ "public class CallerHierarchyExample {\n" +
+ " interface Interface {\n" +
+ " void method(int i);\n" +
+ " }\n" +
+ " class Implementation implements Interface {\n" +
+ " public void method(int i) {}\n" +
+ " }\n" +
+ " void caller() {\n" +
+ " Interface pred = new Implementation();\n" +
+ " IntStream.range(0, 3).forEach(pred::method);\n" +
+ " }\n" +
+ "}"
+ );
+ IType type = this.workingCopies[0].getType("CallerHierarchyExample");
+ IJavaElement[] children = type.getChildren();
+ IType memberType = null;
+ for (IJavaElement iJavaElement : children) {
+ if (iJavaElement.getElementType() == IJavaElement.TYPE &&
+ iJavaElement.getElementName().equals("Interface")) {
+ memberType = (IType) iJavaElement;
+ break;
+ }
+ }
+ assertNotNull("type should not be null", memberType);
+ IMethod method = null;
+ IMethod[] methods = memberType.getMethods();
+ for (IMethod iMethod : methods) {
+ if (iMethod.getElementName().equals("method")) {
+ method = iMethod;
+ break;
+ }
+ }
+ assertNotNull("type should not be null", method);
+ search(method, REFERENCES, EXACT_RULE);
+ assertSearchResults(
+ "src/X.java void CallerHierarchyExample.caller() [method] EXACT_MATCH"
+ );
+}
// Add new tests in JavaSearchBugs8Tests
}
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java
index 12d4dc93d8..e030f240ad 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -165,7 +165,7 @@ protected ReferenceBinding checkMethodRef(MethodBinding method, ReferenceExpress
if (result) {
Expression lhs = referenceExpression.lhs;
if (lhs instanceof NameReference) {
- Binding binding = ((NameReference) lhs).binding;
+ Binding binding = ((NameReference) lhs).resolvedType;
if (binding instanceof ReferenceBinding)
return (ReferenceBinding) binding;
}

Back to the top