Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2019-05-11 15:04:23 -0400
committerAndrey Loskutov2019-05-11 15:04:23 -0400
commit97d56a861f97b4c7ba07d96dd452a88dcff1c1c9 (patch)
tree038e98a80a943a8dd1d7d9a28aa493e891cec041
parent66765d11a86c7477838a39eafba6169fca506ed3 (diff)
downloadeclipse.jdt.core-97d56a861f97b4c7ba07d96dd452a88dcff1c1c9.tar.gz
eclipse.jdt.core-97d56a861f97b4c7ba07d96dd452a88dcff1c1c9.tar.xz
eclipse.jdt.core-97d56a861f97b4c7ba07d96dd452a88dcff1c1c9.zip
Bug 547051 - subclass search with patterns doesn't work for modulesI20190511-1800
Updated IndexBasedHierarchyBuilder.createInfoFromClassFileInJar() to include module name of the given type. Change-Id: I3e1a2842728b7e576472ea9534a0ea3753e3b73d Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs9Tests.java51
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java54
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/IndexBasedHierarchyBuilder.java11
3 files changed, 104 insertions, 12 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs9Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs9Tests.java
index 20381fa9a6..10b1f65708 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs9Tests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs9Tests.java
@@ -4650,10 +4650,50 @@ public void testBug547051_modular() throws Exception {
AtomicBoolean r = new AtomicBoolean(false);
engine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH,
typeName, SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH,
- TYPE, scope,
- (modifiers, packageName1, simpleTypeName, enclosingTypeNames, path, access) -> r.set(true),
+ TYPE, scope,
+ (modifiers, packageName1, simpleTypeName, enclosingTypeNames, path, access) -> r.set(true),
+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
+ assertTrue("Type search has no matches for subtypes of " + type, r.get());
+ }
+ finally {
+ deleteProject("P");
+ }
+}
+
+public void testBug547051_modular2() throws Exception {
+ try {
+ IJavaProject project = createJava9Project("P");
+ IType type = project.findType("java.util.Collection");
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(project, type, Boolean.TRUE, Boolean.TRUE, null);
+ BasicSearchEngine engine = new BasicSearchEngine();
+ char[] packageName = null;
+ char[] typeName = "HashSe".toCharArray();
+ AtomicBoolean r = new AtomicBoolean(false);
+ engine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH,
+ typeName, SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH,
+ TYPE, scope,
+ (modifiers, packageName1, simpleTypeName, enclosingTypeNames, path, access) -> r.set(true),
+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
+ assertTrue("Type search has no matches for subtypes of " + type, r.get());
+ }
+ finally {
+ deleteProject("P");
+ }
+}
+public void testBug547051_modular3() throws Exception {
+ try {
+ IJavaProject project = createJava9Project("P");
+ IType type = project.findType("java.util.Collection");
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(project, type, Boolean.TRUE, Boolean.TRUE, null);
+ BasicSearchEngine engine = new BasicSearchEngine();
+ char[] packageName = "java.util".toCharArray();
+ char[] typeName = "HashSet".toCharArray();
+ AtomicBoolean r = new AtomicBoolean(false);
+ engine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH,
+ typeName, SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH,
+ TYPE, scope,
+ (modifiers, packageName1, simpleTypeName, enclosingTypeNames, path, access) -> r.set(true),
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
-
assertTrue("Type search has no matches for subtypes of " + type, r.get());
}
finally {
@@ -4665,9 +4705,8 @@ public void testBug547095_local_variables_search_modular() throws Exception {
try {
IJavaProject project = createJava9Project("P");
IType type = project.findType("java.util.Collection");
-
IMethod method = type.getMethod("equals", new String[] {"Ljava.lang.Object;" });
- LocalVariable lv = new LocalVariable(((JavaElement)method), "o", 0, 0, 0, 0, "QObject;", null, 0, true);
+ LocalVariable lv = new LocalVariable(((JavaElement)method), "o", 0, 0, 0, 0, "QObject;", null, 0, true);
SearchPattern pattern = SearchPattern.createPattern(lv, REFERENCES, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_ERASURE_MATCH);
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, SYSTEM_LIBRARIES | APPLICATION_LIBRARIES | REFERENCED_PROJECTS | SOURCES);
search(pattern, scope, this.resultCollector);
@@ -4682,7 +4721,7 @@ public void testBug547095_type_patter_search_modular() throws Exception {
try {
IJavaProject project = createJava9Project("P");
IType type = project.findType("java.util.Collection");
- TypeParameter tp = new TypeParameter(((JavaElement)type), "E");
+ TypeParameter tp = new TypeParameter(((JavaElement)type), "E");
SearchPattern pattern = SearchPattern.createPattern(tp, REFERENCES, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_ERASURE_MATCH);
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, SYSTEM_LIBRARIES | APPLICATION_LIBRARIES | REFERENCED_PROJECTS | SOURCES);
search(pattern, scope, this.resultCollector);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
index 3051fe8f0c..9d74b767a2 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
@@ -15160,8 +15160,8 @@ public void testBug547051_nonModular() throws Exception {
AtomicBoolean r = new AtomicBoolean(false);
engine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH,
typeName, SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH,
- TYPE, scope,
- (modifiers, packageName1, simpleTypeName, enclosingTypeNames, path, access) -> r.set(true),
+ TYPE, scope,
+ (modifiers, packageName1, simpleTypeName, enclosingTypeNames, path, access) -> r.set(true),
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
assertTrue("Type search has no matches for subtypes of " + type, r.get());
@@ -15171,14 +15171,58 @@ public void testBug547051_nonModular() throws Exception {
}
}
+public void testBug547051_nonModular2() throws Exception {
+ try {
+ IJavaProject project = createJavaProject("P");
+ setUpProjectCompliance(project, "1.8", true);
+ IType type = project.findType("java.util.Collection");
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(project, type, Boolean.TRUE, Boolean.TRUE, null);
+ BasicSearchEngine engine = new BasicSearchEngine();
+ char[] packageName = null;
+ char[] typeName = "HashSe".toCharArray();
+ AtomicBoolean r = new AtomicBoolean(false);
+ engine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH,
+ typeName, SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH,
+ TYPE, scope,
+ (modifiers, packageName1, simpleTypeName, enclosingTypeNames, path, access) -> r.set(true),
+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
+
+ assertTrue("Type search has no matches for subtypes of " + type, r.get());
+ }
+ finally {
+ deleteProject("P");
+ }
+}
+public void testBug547051_nonModular3() throws Exception {
+ try {
+ IJavaProject project = createJavaProject("P");
+ setUpProjectCompliance(project, "1.8", true);
+ IType type = project.findType("java.util.Collection");
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(project, type, Boolean.TRUE, Boolean.TRUE, null);
+ BasicSearchEngine engine = new BasicSearchEngine();
+ char[] packageName = "java.util".toCharArray();
+ char[] typeName = "HashSet".toCharArray();
+ AtomicBoolean r = new AtomicBoolean(false);
+ engine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH,
+ typeName, SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH,
+ TYPE, scope,
+ (modifiers, packageName1, simpleTypeName, enclosingTypeNames, path, access) -> r.set(true),
+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
+ assertTrue("Type search has no matches for subtypes of " + type, r.get());
+ }
+ finally {
+ deleteProject("P");
+ }
+}
+
+
public void testBug547095_local_variables_search_non_modular() throws Exception {
try {
IJavaProject project = createJavaProject("P");
setUpProjectCompliance(project, "1.8", true);
IType type = project.findType("java.util.Collection");
-
IMethod method = type.getMethod("equals", new String[] {"Ljava.lang.Object;" });
- LocalVariable lv = new LocalVariable(((JavaElement)method), "o", 0, 0, 0, 0, "QObject;", null, 0, true);
+ LocalVariable lv = new LocalVariable(((JavaElement)method), "o", 0, 0, 0, 0, "QObject;", null, 0, true);
SearchPattern pattern = SearchPattern.createPattern(lv, REFERENCES, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_ERASURE_MATCH);
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, SYSTEM_LIBRARIES | APPLICATION_LIBRARIES | REFERENCED_PROJECTS | SOURCES);
search(pattern, scope, this.resultCollector);
@@ -15194,7 +15238,7 @@ public void testBug547095_type_pattern_search_non_modular() throws Exception {
IJavaProject project = createJavaProject("P");
setUpProjectCompliance(project, "1.8", true);
IType type = project.findType("java.util.Collection");
- TypeParameter tp = new TypeParameter(((JavaElement)type), "E");
+ TypeParameter tp = new TypeParameter(((JavaElement)type), "E");
SearchPattern pattern = SearchPattern.createPattern(tp, REFERENCES, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_ERASURE_MATCH);
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, SYSTEM_LIBRARIES | APPLICATION_LIBRARIES | REFERENCED_PROJECTS | SOURCES);
search(pattern, scope, this.resultCollector);
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/IndexBasedHierarchyBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/IndexBasedHierarchyBuilder.java
index 3ff7bca478..7ec88709e6 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/IndexBasedHierarchyBuilder.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/IndexBasedHierarchyBuilder.java
@@ -32,6 +32,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IModuleDescription;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
@@ -427,7 +428,15 @@ protected IBinaryType createInfoFromClassFileInJar(Openable classFile) {
IPath path = root.getPath();
// take the OS path for external jars, and the forward slash path for internal jars
String rootPath = path.getDevice() == null ? path.toString() : path.toOSString();
- String documentPath = rootPath + IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR + filePath;
+ IModuleDescription md = root.getModuleDescription();
+ String documentPath;
+ if(md != null) {
+ String module = md.getElementName();
+ documentPath = rootPath + IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR
+ + module + IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR + filePath;
+ } else {
+ documentPath = rootPath + IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR + filePath;
+ }
IBinaryType binaryType = (IBinaryType)this.binariesFromIndexMatches.get(documentPath);
if (binaryType != null) {
this.infoToHandle.put(binaryType, classFile);

Back to the top