forked from eclipse-jdt/eclipse.jdt.core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[23] Search support for module imports (eclipse-jdt#2855)
+ several locations to generalize from isStatic to modifiers + remove bogus subarray() calls "extracting" the entire array fixes eclipse-jdt#2852
- Loading branch information
1 parent
2246806
commit 4e4e4fd
Showing
15 changed files
with
201 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...ipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs23Tests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 GK Software SE and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* 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: | ||
* Stephan Herrmann - Initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.core.tests.model; | ||
|
||
import java.io.IOException; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jdt.core.IModuleDescription; | ||
import org.eclipse.jdt.core.JavaCore; | ||
import org.eclipse.jdt.core.JavaModelException; | ||
import org.eclipse.jdt.core.WorkingCopyOwner; | ||
import org.eclipse.jdt.core.search.IJavaSearchConstants; | ||
import org.eclipse.jdt.core.search.IJavaSearchScope; | ||
import org.eclipse.jdt.core.search.SearchEngine; | ||
import org.eclipse.jdt.core.search.SearchMatch; | ||
import org.eclipse.jdt.core.search.SearchPattern; | ||
|
||
import junit.framework.Test; | ||
|
||
public class JavaSearchBugs23Tests extends AbstractJavaSearchTests { | ||
|
||
public JavaSearchBugs23Tests(String name) { | ||
super(name); | ||
} | ||
|
||
public static Test suite() { | ||
return buildModelTestSuite(JavaSearchBugs23Tests.class, BYTECODE_DECLARATION_ORDER); | ||
} | ||
|
||
class TestCollector extends JavaSearchResultCollector { | ||
@Override | ||
public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException { | ||
super.acceptSearchMatch(searchMatch); | ||
} | ||
} | ||
|
||
@Override | ||
IJavaSearchScope getJavaSearchScope() { | ||
return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs23")}); | ||
} | ||
IJavaSearchScope getJavaSearchScopeBugs(String packageName, boolean addSubpackages) throws JavaModelException { | ||
if (packageName == null) return getJavaSearchScope(); | ||
return getJavaSearchPackageScope("JavaSearchBugs", packageName, addSubpackages); | ||
} | ||
@Override | ||
public ICompilationUnit getWorkingCopy(String path, String source) throws JavaModelException { | ||
if (this.wcOwner == null) { | ||
this.wcOwner = new WorkingCopyOwner() {}; | ||
} | ||
return getWorkingCopy(path, source, this.wcOwner); | ||
} | ||
@Override | ||
public void setUpSuite() throws Exception { | ||
super.setUpSuite(); | ||
JAVA_PROJECT = setUpJavaProject("JavaSearchBugs23", "23"); | ||
JAVA_PROJECT.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); | ||
} | ||
@Override | ||
public void tearDownSuite() throws Exception { | ||
deleteProject("JavaSearchBugs23"); | ||
super.tearDownSuite(); | ||
} | ||
@Override | ||
protected void setUp () throws Exception { | ||
super.setUp(); | ||
this.resultCollector = new TestCollector(); | ||
this.resultCollector.showAccuracy(true); | ||
} | ||
|
||
public void testModuleImport() throws CoreException, IOException { | ||
IModuleDescription module = JAVA_PROJECT.findModule("mod.one", this.wcOwner); | ||
search(module, ALL_OCCURRENCES, EXACT_RULE); | ||
assertSearchResults(""" | ||
src/modimp/X.java [mod.one] EXACT_MATCH | ||
lib/mod.one.jar mod.one [No source] EXACT_MATCH"""); | ||
} | ||
|
||
public void testModuleImportPatternReferences() throws CoreException, IOException { | ||
SearchPattern pattern = SearchPattern.createPattern("*od.*", IJavaSearchConstants.MODULE, REFERENCES, SearchPattern.R_EXACT_MATCH); | ||
search(pattern, getJavaSearchScope(), this.resultCollector); | ||
assertSearchResults(""" | ||
src/modimp/X.java [mod.one] EXACT_MATCH"""); | ||
} | ||
|
||
public void testModuleImportPrefixDeclaration() throws CoreException, IOException { | ||
SearchPattern pattern = SearchPattern.createPattern("mod", IJavaSearchConstants.MODULE, DECLARATIONS, SearchPattern.R_PREFIX_MATCH); | ||
search(pattern, getJavaSearchScope(), this.resultCollector); | ||
assertSearchResults(""" | ||
lib/mod.one.jar mod.one [No source] EXACT_MATCH"""); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
org.eclipse.jdt.core.tests.model/workspace/JavaSearchBugs23/.classpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="var" path="JCL_23_LIB" sourcepath="JCL_23_SRC" rootpath="JCL_SRCROOT"/> | ||
<classpathentry kind="lib" path="lib/mod.one.jar"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
17 changes: 17 additions & 0 deletions
17
org.eclipse.jdt.core.tests.model/workspace/JavaSearchBugs23/.project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>JavaSearchBugs23</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
Binary file added
BIN
+257 Bytes
org.eclipse.jdt.core.tests.model/workspace/JavaSearchBugs23/lib/mod.one.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
org.eclipse.jdt.core.tests.model/workspace/JavaSearchBugs23/src/mod/Y.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package mod; | ||
|
||
import mod.one.*; // try to confuse the search for module 'mod.one' | ||
|
||
public class Y {} |
3 changes: 3 additions & 0 deletions
3
org.eclipse.jdt.core.tests.model/workspace/JavaSearchBugs23/src/mod/one/Z.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package mod.one; | ||
|
||
public class Z {} |
5 changes: 5 additions & 0 deletions
5
org.eclipse.jdt.core.tests.model/workspace/JavaSearchBugs23/src/modimp/X.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package modimp; | ||
|
||
import module mod.one; | ||
|
||
public class X {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters