diff options
author | Manoj Palat | 2017-09-08 03:22:33 +0000 |
---|---|---|
committer | Manoj Palat | 2017-09-08 03:32:41 +0000 |
commit | a6ac586eddf581750bdde0cff974177944429f4b (patch) | |
tree | 41ed39c1b669d6008a754bbacd1231947c1634d8 | |
parent | 44c3522e5259e25f9b607e9ab760cd16382d194e (diff) | |
download | eclipse.jdt.core-a6ac586eddf581750bdde0cff974177944429f4b.tar.gz eclipse.jdt.core-a6ac586eddf581750bdde0cff974177944429f4b.tar.xz eclipse.jdt.core-a6ac586eddf581750bdde0cff974177944429f4b.zip |
Fix for MCF addition for bug 501162 : [9][search] find constructs in
module-info (ref comment 32)
Change-Id: I36fb8639a6eee4ec5efc87e2d5763ad63ea9bf42
7 files changed, 842 insertions, 6 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 deb56a8ef9..4a20b81af0 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 @@ -1036,13 +1036,544 @@ public void testBug501162_018() throws Exception { deleteProject("second"); } } +public void testBug501162_019() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("pack.one", + IJavaSearchConstants.PACKAGE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "src/pack1/X.java [pack.one] EXACT_MATCH\n" + + "lib/bzero501162.jar zero [No source] EXACT_MATCH\n" + + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_020() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("pack.two", + IJavaSearchConstants.PACKAGE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "src/pack1/X.java [pack.two] EXACT_MATCH\n" + + "lib/bzero501162.jar zero [No source] EXACT_MATCH\n" + + "lib/bzero501162.jar zero [No source] EXACT_MATCH\n" + + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_021() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("pack.three", + IJavaSearchConstants.PACKAGE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "lib/bzero501162.jar zero [No source] EXACT_MATCH\n" + + "lib/bzero501162.jar zero [No source] EXACT_MATCH\n" + + "lib/bzero501162.jar zero [No source] EXACT_MATCH\n" + + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_022() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("java.base", + IJavaSearchConstants.MODULE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_023() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("zerotest", + IJavaSearchConstants.MODULE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "lib/bzero501162.jar zero [No source] EXACT_MATCH\n" + + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_024() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("first", + IJavaSearchConstants.MODULE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_025() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("four", + IJavaSearchConstants.MODULE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_026() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("nomodule", + IJavaSearchConstants.MODULE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_027() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("XOne", + IJavaSearchConstants.TYPE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "src/pack1/X.java [XOne] EXACT_MATCH\n" + + "src/pack1/X.java pack1.X.X1 [XOne] EXACT_MATCH\n" + + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_028() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("XFourOne", + IJavaSearchConstants.TYPE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_029() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("ITwo", + IJavaSearchConstants.TYPE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "src/pack1/X.java [ITwo] EXACT_MATCH\n" + + "src/pack1/X.java pack1.X.i2 [ITwo] EXACT_MATCH\n" + + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_030() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("IThreeOne", + IJavaSearchConstants.TYPE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_031() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("XThreeOne", + IJavaSearchConstants.TYPE, IJavaSearchConstants.REFERENCES, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} +public void testBug501162_032() throws Exception { + try { + IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); + String fileContent = + "module zerotest {\n" + + " requires zero;\n" + + "}\n"; + createFile("/JavaSearchBugs9/src/module-info.java", fileContent); + createFolder("/JavaSearchBugs9/src/pack1"); + createFile("/JavaSearchBugs9/src/pack1/X.java", + "package pack1;\n" + + "import pack.one.XOne;\n" + + "import pack.two.ITwo;\n" + + "public class X {\n" + + " public ITwo i2;\n" + + " public XOne X1;\n" + + "}\n"); + addLibraryEntry(project1, "/JavaSearchBugs/lib/bzero501162.jar", false); + project1.close(); // sync + project1.open(null); + SearchPattern pattern = SearchPattern.createPattern("zero", + IJavaSearchConstants.MODULE, IJavaSearchConstants.DECLARATIONS, EXACT_RULE); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {getJavaProject("JavaSearchBugs9")}); + + search(pattern, scope, this.resultCollector); + + assertSearchResults( + "lib/bzero501162.jar zero [No source] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("JavaSearchBugs9"); + } +} public void testBug519211_001() throws CoreException { try { IJavaProject project1 = createJavaProject("JavaSearchBugs9", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); project1.open(null); addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH"))); - String fileContent = + String fileContent = "module first {\n" + " requires second;" + " provides pack22.I22 with pack1.X11;" + diff --git a/org.eclipse.jdt.core.tests.model/workspace/JavaSearchBugs/lib/bzero501162.jar b/org.eclipse.jdt.core.tests.model/workspace/JavaSearchBugs/lib/bzero501162.jar Binary files differnew file mode 100644 index 0000000000..e831bd46fc --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/workspace/JavaSearchBugs/lib/bzero501162.jar diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/ModuleReferenceMatch.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/ModuleReferenceMatch.java new file mode 100644 index 0000000000..0c1caa5d6f --- /dev/null +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/ModuleReferenceMatch.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2017 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.search; + +import org.eclipse.core.resources.IResource; +import org.eclipse.jdt.core.IJavaElement; + +/** + * A Java search match that represents a module reference. + * The element is the innermost enclosing member (mostly module declaration) that references this module reference. + * <p> + * This class is intended to be instantiated and subclassed by clients. + * </p> + * @since 3.13 BETA_JAVA9 + */ +public class ModuleReferenceMatch extends ReferenceMatch { + + /** + * Creates a new module reference match. + * + * @param enclosingElement the inner-most enclosing member that references this module reference + * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE} + * @param offset the offset the match starts at, or -1 if unknown + * @param length the length of the match, or -1 if unknown + * @param insideDocComment <code>true</code> if this search match is inside a doc + * comment, and <code>false</code> otherwise + * @param participant the search participant that created the match + * @param resource the resource of the element + */ + public ModuleReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, + boolean insideDocComment, SearchParticipant participant, IResource resource) { + super(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource); + } + +} diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java index 63ae87c8de..ac30c09419 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java @@ -80,6 +80,7 @@ import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jdt.internal.core.JavaProject; import org.eclipse.jdt.internal.core.LambdaFactory; import org.eclipse.jdt.internal.core.LocalVariable; +import org.eclipse.jdt.internal.core.ModularClassFile; import org.eclipse.jdt.internal.core.NameLookup; import org.eclipse.jdt.internal.core.Openable; import org.eclipse.jdt.internal.core.PackageFragment; @@ -746,6 +747,8 @@ protected IJavaElement createImportHandle(ImportReference importRef) { if (openable instanceof CompilationUnit) return ((CompilationUnit) openable).getImport(new String(importName)); + if (openable instanceof ModularClassFile) + return openable; // binary types do not contain import statements so just answer the top-level type as the element IType binaryType = ((ClassFile) openable).getType(); String typeName = binaryType.getElementName(); @@ -1761,7 +1764,7 @@ public PackageReferenceMatch newPackageReferenceMatch( ASTNode reference) { SearchParticipant participant = getParticipant(); IResource resource = this.currentPossibleMatch.resource; - boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0; + boolean insideDocComment = reference != null && (reference.bits & ASTNode.InsideJavadoc) != 0; return new PackageReferenceMatch(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource); } @@ -1787,7 +1790,7 @@ public TypeReferenceMatch newTypeReferenceMatch( ASTNode reference) { SearchParticipant participant = getParticipant(); IResource resource = this.currentPossibleMatch.resource; - boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0; + boolean insideDocComment = reference != null && (reference.bits & ASTNode.InsideJavadoc) != 0; if (enclosingBinding != null) enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding); return new TypeReferenceMatch(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource); @@ -1801,6 +1804,28 @@ public TypeReferenceMatch newTypeReferenceMatch( return newTypeReferenceMatch(enclosingElement, enclosingBinding, accuracy, reference.sourceStart, reference.sourceEnd-reference.sourceStart+1, reference); } +public ModuleReferenceMatch newModuleReferenceMatch( + IJavaElement enclosingElement, + Binding enclosingBinding, + int accuracy, + int offset, + int length, + ASTNode reference) { + SearchParticipant participant = getParticipant(); + IResource resource = this.currentPossibleMatch.resource; + boolean insideDocComment = reference != null ? (reference.bits & ASTNode.InsideJavadoc) != 0 : false; + if (enclosingBinding != null) + enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding); + return new ModuleReferenceMatch(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource); +} + +public ModuleReferenceMatch newModuleReferenceMatch( + IJavaElement enclosingElement, + Binding enclosingBinding, + int accuracy, + ASTNode reference) { + return newModuleReferenceMatch(enclosingElement, enclosingBinding, accuracy, reference.sourceStart, reference.sourceEnd-reference.sourceStart+1, reference); +} /** * Add the possibleMatch to the loop * -> build compilation unit declarations, their bindings and record their results. @@ -1873,6 +1898,16 @@ protected void process(PossibleMatch possibleMatch, boolean bindingsWereCreated) this.patternLocator.mayBeGeneric = mayBeGeneric; } } + } else if (this.currentPossibleMatch.openable instanceof ModularClassFile) { + boolean mayBeGeneric = this.patternLocator.mayBeGeneric; + this.patternLocator.mayBeGeneric = false; // there's no longer generic in class files + try { + new ModularClassFileMatchLocator().locateMatches(this, (ModularClassFile) this.currentPossibleMatch.openable); + } + finally { + this.patternLocator.mayBeGeneric = mayBeGeneric; + } + return; } if (!unit.isModuleInfo()) return; @@ -2360,7 +2395,6 @@ protected void reportBinaryMemberDeclaration(IResource resource, IMember binaryM SearchMatch match = newDeclarationMatch(binaryMember, binaryMemberBinding, accuracy, range.getOffset(), range.getLength(), getParticipant(), resource); report(match); } - protected void reportMatching(LambdaExpression lambdaExpression, IJavaElement parent, int accuracy, MatchingNodeSet nodeSet, boolean typeInHierarchy) throws CoreException { IJavaElement enclosingElement = null; // Report the lambda declaration itself. diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ModularClassFileMatchLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ModularClassFileMatchLocator.java new file mode 100644 index 0000000000..77ee29c566 --- /dev/null +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ModularClassFileMatchLocator.java @@ -0,0 +1,224 @@ +/******************************************************************************* + * Copyright (c) 2017 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.core.search.matching; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.IModuleDescription; +import org.eclipse.jdt.core.search.ModuleReferenceMatch; +import org.eclipse.jdt.core.search.PackageReferenceMatch; +import org.eclipse.jdt.core.search.SearchMatch; +import org.eclipse.jdt.core.search.SearchPattern; +import org.eclipse.jdt.core.search.TypeReferenceMatch; +import org.eclipse.jdt.internal.compiler.env.IBinaryModule; +import org.eclipse.jdt.internal.compiler.env.IModule.IPackageExport; +import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding; +import org.eclipse.jdt.internal.compiler.lookup.PackageBinding; +import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; +import org.eclipse.jdt.internal.core.ModularClassFile; +import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants; + +public class ModularClassFileMatchLocator implements IIndexConstants { + + private IBinaryModule binaryModule; + private ModularClassFile modularClassFile; + private IModuleDescription moduleDesc; + private char[] moduleName; + private ModuleBinding module; + + public void locateMatches(MatchLocator locator, ModularClassFile mClassFile) throws CoreException { + SearchPattern pattern = locator.pattern; + this.modularClassFile = mClassFile; + this.binaryModule = this.modularClassFile.getBinaryModuleInfo(); + if (this.binaryModule == null) return; + + // cache all the details + this.moduleDesc = mClassFile.getModule(); + this.moduleName = this.binaryModule.name(); + this.module = locator.lookupEnvironment.getModule(this.moduleName); + + matchModuleDeclaration(pattern, locator); + matchModuleReferences(pattern, locator); + matchPackageReferences(pattern, locator); + matchTypeReferences(pattern, locator); + } + private void matchModuleDeclaration(SearchPattern pattern, MatchLocator locator) throws CoreException { + switch (pattern.kind) { + case MODULE_PATTERN: + break; + case OR_PATTERN: + SearchPattern[] patterns = ((OrPattern) pattern).patterns; + for (int i = 0, length = patterns.length; i < length; i++) { + SearchPattern p = patterns[i]; + if (p.kind == MODULE_PATTERN) + matchModuleReferences(patterns[i], locator); + } + // $FALL-THROUGH$ - fall through default to return + default: + return; + } + ModulePattern modulePattern = (ModulePattern) pattern; + if (!locator.patternLocator.matchesName(modulePattern.name, this.moduleName)) + return; + ModuleBinding moduleBinding = null; + int level = PatternLocator.ACCURATE_MATCH; + if (locator.patternLocator.mustResolve) { + moduleBinding = locator.lookupEnvironment.getModule(this.moduleName); + level = locator.patternLocator.resolveLevel(moduleBinding); + } + if (level == PatternLocator.IMPOSSIBLE_MATCH) + return; + int accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE : SearchMatch.A_INACCURATE; + SearchMatch match = locator.newDeclarationMatch(this.moduleDesc, moduleBinding, accuracy, -1, 0); + locator.report(match); + } + private void matchModuleReferences(SearchPattern pattern, MatchLocator locator) throws CoreException { + // Only process Module patterns + switch (pattern.kind) { + case MODULE_PATTERN: + break; + case OR_PATTERN: + SearchPattern[] patterns = ((OrPattern) pattern).patterns; + for (int i = 0, length = patterns.length; i < length; i++) { + SearchPattern p = patterns[i]; + if (p.kind == MODULE_PATTERN) + matchModuleReferences(patterns[i], locator); + } + // $FALL-THROUGH$ - fall through default to return + default: + return; + } + ModulePattern modulePattern = (ModulePattern) pattern; + matchModuleReferences(locator, modulePattern, this.binaryModule.exports()); + matchModuleReferences(locator, modulePattern, this.binaryModule.opens()); + matchModuleReferences(locator, modulePattern, this.module.getAllRequiredModules()); + } + private void matchModuleReference(MatchLocator locator, ModulePattern modulePattern, + char[][] modules, boolean isTarget) throws CoreException { + if (modules == null) + return; + for (char[] module1 : modules) { + if (module1 == null || module1.length == 0) continue; + if (!locator.patternLocator.matchesName(modulePattern.name, module1)) continue; + // no resolve for target modules - report accurate match else resolve + ModuleReferenceMatch match = locator.newModuleReferenceMatch(this.moduleDesc, null, isTarget ? SearchMatch.A_ACCURATE : SearchMatch.A_INACCURATE, -1, 0, null); + locator.report(match); + } + } + private void matchModuleReferences(MatchLocator locator, ModulePattern modulePattern, + IPackageExport[] pvs) throws CoreException { + if (pvs == null) return; + for (IPackageExport pv : pvs) { + matchModuleReference(locator, modulePattern, pv.targets(), true /* isTarget */); + } + } + private void matchModuleReferences(MatchLocator locator, ModulePattern modulePattern, + ModuleBinding[] refs) throws CoreException { + if (refs == null) return; + for (ModuleBinding ref : refs) { + char[] name = ref.name(); + if (name == null) continue; + int level = locator.patternLocator.resolveLevel(ref); + if (level == PatternLocator.IMPOSSIBLE_MATCH) continue; + int accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE : SearchMatch.A_INACCURATE; + ModuleReferenceMatch match = locator.newModuleReferenceMatch(this.moduleDesc, null, accuracy, -1, 0, null); + locator.report(match); + } + } + private void matchPackageReferences(SearchPattern pattern, MatchLocator locator) throws CoreException { + // Only process PackageReference patterns + switch (pattern.kind) { + case PKG_REF_PATTERN: + break; + case OR_PATTERN: + SearchPattern[] patterns = ((OrPattern) pattern).patterns; + for (int i = 0, length = patterns.length; i < length; i++) { + SearchPattern p = patterns[i]; + if (p.kind == PKG_REF_PATTERN) + matchPackageReferences(patterns[i], locator); + } + // $FALL-THROUGH$ - fall through default to return + default: + return; + } + matchPackReferences(locator, (PackageReferencePattern) pattern, this.module.getExports()); + matchPackReferences(locator, (PackageReferencePattern) pattern, this.module.getOpens()); + matchPackReferences(locator, (PackageReferencePattern) pattern, this.module.getUses()); + TypeBinding[] services = this.module.getServices(); + if (services != null) { + matchPackReferences(locator, (PackageReferencePattern) pattern, services); + for (TypeBinding service : services) { + matchPackReferences(locator, (PackageReferencePattern) pattern, this.module.getImplementations(service)); + } + } + } + private void matchPackReferences(MatchLocator locator, PackageReferencePattern packReferencePattern, + PackageBinding[] packBindings) throws CoreException { + if (packBindings == null) return; + for (PackageBinding pb : packBindings) { + reportPackageMatch(locator, pb); + } + } + private void reportPackageMatch(MatchLocator locator, PackageBinding packageBinding) throws CoreException{ + if (packageBinding == null) return; + int level = locator.patternLocator.resolveLevel(packageBinding); + if (level == PatternLocator.IMPOSSIBLE_MATCH) return; + int accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE : SearchMatch.A_INACCURATE; + PackageReferenceMatch match = locator.newPackageReferenceMatch(this.moduleDesc, accuracy, -1, 0, null); + locator.report(match); + } + private void matchPackReferences(MatchLocator locator, PackageReferencePattern packReferencePattern, + TypeBinding[] types) throws CoreException { + if (types == null) return; + for (TypeBinding type : types) { + reportPackageMatch(locator, type.getPackage()); + } + } + private void matchTypeReferences(SearchPattern pattern, MatchLocator locator) throws CoreException { + // Only process TypeReference patterns + switch (pattern.kind) { + case TYPE_REF_PATTERN: + break; + case OR_PATTERN: + SearchPattern[] patterns = ((OrPattern) pattern).patterns; + for (int i = 0, length = patterns.length; i < length; i++) { + SearchPattern p = patterns[i]; + if (p.kind == TYPE_REF_PATTERN) + matchTypeReferences(patterns[i], locator); + } + // $FALL-THROUGH$ - fall through default to return + default: + return; + } + matchTypeReferences(locator, (TypeReferencePattern) pattern, this.module.getUses()); + TypeBinding[] services = this.module.getServices(); + if (services != null) { + matchTypeReferences(locator, (TypeReferencePattern) pattern, services); + for (TypeBinding service : services) { + matchTypeReferences(locator, (TypeReferencePattern) pattern, this.module.getImplementations(service)); + } + } + } + private void matchTypeReferences(MatchLocator locator, TypeReferencePattern typeReferencePattern, + TypeBinding[] types) throws CoreException { + if (types == null) return; + for (TypeBinding type : types) { + int level = locator.patternLocator.resolveLevel(type); + if (level == PatternLocator.IMPOSSIBLE_MATCH) continue; + int accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE : SearchMatch.A_INACCURATE; + TypeReferenceMatch match = locator.newTypeReferenceMatch(this.moduleDesc, null, accuracy, -1, 0, null); + locator.report(match); + } + } +} diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ModuleLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ModuleLocator.java index 2de123650e..9180d6fefd 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ModuleLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ModuleLocator.java @@ -79,10 +79,10 @@ public class ModuleLocator extends PatternLocator { protected int referenceType() { return IJavaElement.JAVA_MODULE; } + @Override public int resolveLevel(Binding binding) { if (binding == null) return INACCURATE_MATCH; if (!(binding instanceof ModuleBinding)) return IMPOSSIBLE_MATCH; return (matchesName(this.pattern.name, binding.readableName())) ? ACCURATE_MATCH : IMPOSSIBLE_MATCH; - } } diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java index dfb079babf..51da1efc61 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java @@ -431,7 +431,7 @@ protected void matchReportReference(ASTNode reference, IJavaElement element, Bin this.match = locator.newTypeParameterReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, reference); break; case IJavaElement.JAVA_MODULE: - this.match = locator.newTypeReferenceMatch(element, elementBinding, accuracy, offset, reference.sourceEnd-offset+1, reference); + this.match = locator.newModuleReferenceMatch(element, elementBinding, accuracy, offset, reference.sourceEnd-offset+1, reference); break; } if (this.match != null) { |