Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2019-05-08 09:23:52 -0400
committerAndrey Loskutov2019-05-08 09:23:52 -0400
commita0eca8b50fc813cb95b189171f5872e3c1c42852 (patch)
tree62f4238f9e3fa010d52b2f3333c13212582723a1
parent5faa7c5f1d6ced2be62840ecfb39438169bffa16 (diff)
downloadeclipse.jdt.core-a0eca8b50fc813cb95b189171f5872e3c1c42852.tar.gz
eclipse.jdt.core-a0eca8b50fc813cb95b189171f5872e3c1c42852.tar.xz
eclipse.jdt.core-a0eca8b50fc813cb95b189171f5872e3c1c42852.zip
Bug 547051 - Java search with HierarchyScope does not find JDK classes
on modular JVM Updated focusPath and resourcePaths to consider module name of the requested type. Change-Id: Id5b8565ac280af7f4f1abdd56edaa82d83de79b4 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.java25
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java28
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/HierarchyScope.java40
3 files changed, 83 insertions, 10 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 94486dec84..5e5de35370 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
@@ -14,9 +14,11 @@
package org.eclipse.jdt.core.tests.model;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
@@ -37,6 +39,7 @@ import org.eclipse.jdt.core.search.SearchMatch;
import org.eclipse.jdt.core.search.SearchParticipant;
import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.core.search.TypeReferenceMatch;
+import org.eclipse.jdt.internal.core.search.BasicSearchEngine;
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
import junit.framework.Test;
@@ -4628,5 +4631,27 @@ public void testBug545293() throws Exception {
}
}
+public void testBug547051_modular() 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 = null;
+ 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");
+ }
+}
+
// Add more tests here
} \ No newline at end of file
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 e00f8b46d8..66cc595b96 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
@@ -18,8 +18,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-
-import junit.framework.Test;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -32,6 +31,7 @@ import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
@@ -90,6 +90,8 @@ import org.eclipse.jdt.internal.core.search.matching.PatternLocator;
import org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern;
import org.eclipse.jdt.internal.core.search.matching.TypeReferencePattern;
+import junit.framework.Test;
+
/**
* Non-regression tests for bugs fixed in Java Search engine.
*/
@@ -15138,5 +15140,27 @@ public void testBug521240_001() throws CoreException {
"src/pack1/X.java void pack1.X.foo(Y) [foo] EXACT_MATCH"
);
}
+public void testBug547051_nonModular() 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 = null;
+ 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");
+ }
+}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/HierarchyScope.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/HierarchyScope.java
index 2d3709eed5..5b5c3ff002 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/HierarchyScope.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/HierarchyScope.java
@@ -113,11 +113,23 @@ public class HierarchyScope extends AbstractSearchScope implements SuffixConstan
} else {
return; // unknown target
}
- this.focusPath =
- zipFileName
- + JAR_FILE_ENTRY_SEPARATOR
- + type.getFullyQualifiedName().replace('.', '/')
- + SUFFIX_STRING_class;
+ IModuleDescription md = root.getModuleDescription();
+ if(md != null) {
+ String module = md.getElementName();
+ this.focusPath =
+ zipFileName
+ + JAR_FILE_ENTRY_SEPARATOR
+ + module
+ + JAR_FILE_ENTRY_SEPARATOR
+ + type.getFullyQualifiedName().replace('.', '/')
+ + SUFFIX_STRING_class;
+ } else {
+ this.focusPath =
+ zipFileName
+ + JAR_FILE_ENTRY_SEPARATOR
+ + type.getFullyQualifiedName().replace('.', '/')
+ + SUFFIX_STRING_class;
+ }
} else {
this.focusPath = type.getPath().toString();
}
@@ -169,12 +181,24 @@ public class HierarchyScope extends AbstractSearchScope implements SuffixConstan
} else {
continue; // unknown target
}
- String resourcePath =
- zipFileName
+ String resourcePath;
+ IModuleDescription md = root.getModuleDescription();
+ if(md != null) {
+ String module = md.getElementName();
+ resourcePath =
+ zipFileName
+ + JAR_FILE_ENTRY_SEPARATOR
+ + module
+ + JAR_FILE_ENTRY_SEPARATOR
+ + type.getFullyQualifiedName().replace('.', '/')
+ + SUFFIX_STRING_class;
+ } else {
+ resourcePath =
+ zipFileName
+ JAR_FILE_ENTRY_SEPARATOR
+ type.getFullyQualifiedName().replace('.', '/')
+ SUFFIX_STRING_class;
-
+ }
this.resourcePaths.add(resourcePath);
paths.put(jarPath, type);
} else {

Back to the top