aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2012-07-16 08:22:43 (EDT)
committerJayaprakash Arthanareeswaran2012-08-10 02:57:15 (EDT)
commita8db9d6e29539ad424b2aeb72ada09e6eab41c24 (patch)
tree8e679161a3096d73c3d1e6b7a7ac196eaa89f0f1
parent71a2279542d7f81c81ac185c946009de95de9746 (diff)
downloadeclipse.jdt.core-a8db9d6e29539ad424b2aeb72ada09e6eab41c24.zip
eclipse.jdt.core-a8db9d6e29539ad424b2aeb72ada09e6eab41c24.tar.gz
eclipse.jdt.core-a8db9d6e29539ad424b2aeb72ada09e6eab41c24.tar.bz2
Fixed bug 382778: Call hierarchy missing valid callers probably because
java search marks exact matches as potential
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java97
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java27
2 files changed, 122 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java
index 34f79f6..9229071 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java
@@ -132,7 +132,7 @@ public class JavaSearchBugsTests2 extends AbstractJavaSearchTests {
deleteProject(project);
}
}
- // Search for a non-overriden method with same name as which could have been overriden should
+ // Search for a non-overridden method with same name as which could have been overridden should
// not have results
public void testBug123836b() throws CoreException {
IJavaProject project = null;
@@ -1287,6 +1287,101 @@ public class JavaSearchBugsTests2 extends AbstractJavaSearchTests {
deleteProject("P");
}
}
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=382778, Call hierarchy missing valid callers probably because java search marks exact matches as potential
+ public void testBug382778() throws CoreException {
+ try {
+ IJavaProject p = createJavaProject("P", new String[] { "src" },
+ new String[] {"JCL_LIB"}, "bin");
+ createFolder("/P/src/b382778");
+ createFile("/P/src/b382778/Impl2.java",
+ "package b382778;\n" +
+ "public class Impl2 implements PublicInterface2 {\n" +
+ " private final String name;\n" +
+ " public Impl2(String name) {\n" +
+ " this.name = name;\n" +
+ " }\n" +
+ " public String getName() {\n" +
+ " return name;\n" +
+ " }\n" +
+ "}\n"
+ );
+ createFile("/P/src/b382778/Main.java",
+ "package b382778;\n" +
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " broken();\n" +
+ " ok();\n" +
+ " }\n" +
+ " private static void broken() {\n" +
+ " PublicInterface2 impl2 = new Impl2(\"Name Broken\");\n" +
+ " Static.printIt(impl2.getName());\n" +
+ " }\n" +
+ " private static void ok() {\n" +
+ " PublicInterface2 impl2 = new Impl2(\"Name OK\");\n" +
+ " String name = impl2.getName();\n" +
+ " Static.printIt(name);\n" +
+ " }\n" +
+ "}\n"
+ );
+ createFile("/P/src/b382778/MainBroken.java",
+ "package b382778;\n" +
+ "public class MainBroken {\n" +
+ " public static void main(String[] args) {\n" +
+ " PublicInterface2 impl2 = new Impl2(\"Name Broken\");\n" +
+ " Static.printIt(impl2.getName());\n" +
+ " }\n" +
+ "}\n"
+ );
+ createFile("/P/src/b382778/MainOK.java",
+ "package b382778;\n" +
+ "public class MainOK {\n" +
+ " public static void main(String[] args) {\n" +
+ " PublicInterface2 impl2 = new Impl2(\"Name OK\");\n" +
+ " String name = impl2.getName();\n" +
+ " Static.printIt(name);\n" +
+ " }\n" +
+ "}\n"
+ );
+ createFile("/P/src/b382778/PublicInterface1.java",
+ "package b382778;\n" +
+ "public interface PublicInterface1 extends PackageInterface1Getters {\n" +
+ "}\n" +
+ "/* package */interface PackageInterface1Getters {\n" +
+ "String getName();\n" +
+ "}"
+ );
+ createFile("/P/src/b382778/PublicInterface2.java",
+ "package b382778;\n" +
+ "public interface PublicInterface2 extends PackageInterface2Getters {\n" +
+ "}\n" +
+ "/* package */interface PackageInterface2Getters extends PackageInterface1Getters {\n" +
+ "}\n"
+ );
+ createFile("/P/src/b382778/Static.java",
+ "package b382778;\n" +
+ "public class Static {\n" +
+ "public static void printIt(String it) {\n" +
+ "System.out.println(it);\n" +
+ "}\n" +
+ "}"
+ );
+ waitUntilIndexesReady();
+ ICompilationUnit unit = getCompilationUnit("/P/src/b382778/Static.java");
+ IMethod method = unit.getType("Static").getMethod("printIt",
+ new String[] { "QString;" });
+ IJavaSearchScope scope = SearchEngine
+ .createJavaSearchScope(new IJavaElement[] { p }, IJavaSearchScope.SOURCES);
+
+ search(method, REFERENCES, scope, this.resultCollector);
+
+ assertSearchResults("src/b382778/Main.java void b382778.Main.broken() [printIt(impl2.getName())] EXACT_MATCH\n"
+ + "src/b382778/Main.java void b382778.Main.ok() [printIt(name)] EXACT_MATCH\n"
+ + "src/b382778/MainBroken.java void b382778.MainBroken.main(String[]) [printIt(impl2.getName())] EXACT_MATCH\n"
+ + "src/b382778/MainOK.java void b382778.MainOK.main(String[]) [printIt(name)] EXACT_MATCH");
+ } finally {
+ deleteProject("P");
+ }
+ }
public void testBug383315a() throws CoreException {
try {
IJavaProject p = createJavaProject("P", new String[] {}, new String[] { "JCL15_LIB" }, "", "1.5");
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java
index 9fd34c6..e60c625 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 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
@@ -10,13 +10,21 @@
*******************************************************************************/
package org.eclipse.jdt.internal.core.search.matching;
+import java.util.Iterator;
+import java.util.Map;
+
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
+import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jdt.internal.core.builder.ClasspathLocation;
import org.eclipse.jdt.internal.core.util.ResourceCompilationUnit;
import org.eclipse.jdt.internal.core.util.Util;
@@ -63,6 +71,23 @@ SimpleLookupTable directoryTable(String qualifiedPackageName) {
}
}
}
+ // look for secondary types, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=382778
+ IJavaProject project = JavaCore.create(container.getProject());
+ Map secondaryTypePaths = JavaModelManager.getJavaModelManager().secondaryTypes(project, false, null);
+ if (secondaryTypePaths.size() > 0) {
+ Map typesInPackage = (Map) secondaryTypePaths.get(qualifiedPackageName);
+ if (typesInPackage != null && typesInPackage.size() > 0) {
+ for (Iterator j = typesInPackage.keySet().iterator(); j.hasNext();) {
+ String secondaryTypeName = (String) j.next();
+ IType secondaryType = (IType) typesInPackage.get(secondaryTypeName);
+ IJavaElement parent = secondaryType.getParent();
+ String fullPath = parent.getResource().getFullPath().toString();
+ if (!org.eclipse.jdt.internal.compiler.util.Util.isExcluded(fullPath.toCharArray(), this.fulInclusionPatternChars, this.fullExclusionPatternChars, false/*not a folder path*/)) {
+ dirTable.put(secondaryTypeName, parent.getResource());
+ }
+ }
+ }
+ }
this.directoryCache.put(qualifiedPackageName, dirTable);
return dirTable;
}