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.
Consider external paths in search scope (eclipse-jdt#190)
Fixes eclipse-jdt#190
- Loading branch information
1 parent
68e8c0c
commit 7b101c3
Showing
6 changed files
with
169 additions
and
1 deletion.
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
105 changes: 105 additions & 0 deletions
105
...pse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchIssue190Test.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,105 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Christopher Gerking 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 | ||
* | ||
* Contributors: | ||
* Christopher Gerking - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.core.tests.model; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.core.resources.IWorkspace; | ||
import org.eclipse.core.resources.ResourcesPlugin; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jdt.core.IJavaElement; | ||
import org.eclipse.jdt.core.IType; | ||
import org.eclipse.jdt.core.JavaCore; | ||
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.SearchRequestor; | ||
|
||
import junit.framework.Test; | ||
|
||
public class JavaSearchIssue190Test extends AbstractJavaSearchTests { | ||
|
||
public String getProjectName() { | ||
return "JavaSearchIssue190"; | ||
} | ||
|
||
public JavaSearchIssue190Test(String name) { | ||
super(name); | ||
} | ||
|
||
public static Test suite() { | ||
return buildModelTestSuite(JavaSearchIssue190Test.class, BYTECODE_DECLARATION_ORDER); | ||
} | ||
|
||
@Override | ||
public void setUpSuite() throws Exception { | ||
super.setUpSuite(); | ||
|
||
createExternalFolder("TestContainer/p"); | ||
|
||
String sourceWorkspacePath = getSourceWorkspacePath(); | ||
IWorkspace targetWorkspace = ResourcesPlugin.getWorkspace(); | ||
File targetWorkspaceLocation = new File(targetWorkspace.getRoot().getLocation().toOSString()); | ||
|
||
File javaFileSrc = new File(sourceWorkspacePath, "JavaSearchMultipleProjects2/lib/p/Y.java"); | ||
File javaFileDst = new File(targetWorkspaceLocation.getParentFile().getCanonicalFile(), "TestContainer/p/Y.java"); | ||
copy(javaFileSrc, javaFileDst); | ||
|
||
File classFileSrc = new File(sourceWorkspacePath, "JavaSearchMultipleProjects2/lib/p/Y.class"); | ||
File classFileDst = new File(targetWorkspaceLocation.getParentFile().getCanonicalFile(), "TestContainer/p/Y.class"); | ||
copy(classFileSrc, classFileDst); | ||
|
||
JAVA_PROJECT = setUpJavaProject(getProjectName(), "11"); | ||
|
||
JavaCore.setOptions(JavaCore.getDefaultOptions()); | ||
} | ||
|
||
@Override | ||
IJavaSearchScope getJavaSearchScope() { | ||
IJavaElement[] elements = new IJavaElement[] { getJavaProject(getProjectName()) }; | ||
return SearchEngine.createJavaSearchScope(elements, true); | ||
} | ||
|
||
public void testIssue190() throws CoreException, IOException { | ||
List<String> searchResults = new ArrayList<String>(); | ||
|
||
SearchRequestor searchRequestor = new SearchRequestor() { | ||
public void acceptSearchMatch(SearchMatch match) { | ||
Object element = match.getElement(); | ||
|
||
if (element instanceof IType) { | ||
String fqn = ((IType) element).getFullyQualifiedName(); | ||
searchResults.add(fqn); | ||
} | ||
} | ||
}; | ||
|
||
search("Y", IJavaSearchConstants.CLASS, | ||
IJavaSearchConstants.DECLARATIONS, getJavaSearchScope(), searchRequestor); | ||
|
||
assertTrue("Searched class not found in external classpath container", searchResults.contains("p.Y")); | ||
} | ||
|
||
@Override | ||
public void tearDownSuite() throws Exception { | ||
deleteProject(getProjectName()); | ||
deleteExternalResource("TestContainer"); | ||
super.tearDownSuite(); | ||
JAVA_PROJECT = null; | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
org.eclipse.jdt.core.tests.model/workspace/JavaSearchIssue190/.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,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.core.tests.model.TEST_EXTERNAL_LIB_CONTAINER"/> | ||
<classpathentry kind="src" path="src"> | ||
<attributes> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
17 changes: 17 additions & 0 deletions
17
org.eclipse.jdt.core.tests.model/workspace/JavaSearchIssue190/.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>org.eclipse.jdt.core.tests.model.issue190</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> |
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