-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow overriding the Java search logic with a custom implementation (#…
…3701) - Move test to end Signed-off-by: Rob Stryker <[email protected]>
- Loading branch information
1 parent
5f438d7
commit 1426f4d
Showing
14 changed files
with
455 additions
and
8 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
64 changes: 64 additions & 0 deletions
64
...se.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchExtensionTest.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,64 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Red Hat Inc 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: | ||
* Red Hat Inc - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.core.tests.model; | ||
|
||
import junit.framework.Test; | ||
import org.eclipse.jdt.core.JavaModelException; | ||
import org.eclipse.jdt.core.search.IJavaSearchDelegate; | ||
import org.eclipse.jdt.internal.core.search.matching.JavaSearchDelegateDiscovery; | ||
|
||
public class JavaSearchExtensionTest extends AbstractJavaSearchTests { | ||
private static final String DELEGATE_SYSPROP = "IJavaSearchDelegate"; | ||
public JavaSearchExtensionTest(String name) { | ||
super(name); | ||
} | ||
public static Test suite() { | ||
return buildModelTestSuite(JavaSearchExtensionTest.class, ALPHABETICAL_SORT); | ||
} | ||
@Override | ||
public void setUpSuite() throws Exception { | ||
super.setUpSuite(); | ||
} | ||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
} | ||
@Override | ||
protected void tearDown() throws Exception { | ||
super.tearDown(); | ||
} | ||
public void testDelegateFound() throws JavaModelException { | ||
String oldSystemProperty = System.getProperty(DELEGATE_SYSPROP); | ||
|
||
try { | ||
System.setProperty(DELEGATE_SYSPROP, "org.eclipse.jdt.core.tests.model.TestJavaSearchDelegate"); | ||
IJavaSearchDelegate del = JavaSearchDelegateDiscovery.getInstance(); | ||
assertNotNull(del); | ||
assertTrue(del instanceof TestJavaSearchDelegate); | ||
|
||
System.clearProperty(DELEGATE_SYSPROP); | ||
del = JavaSearchDelegateDiscovery.getInstance(); | ||
assertNull(del); | ||
|
||
System.setProperty(DELEGATE_SYSPROP, "unknownVal"); | ||
del = JavaSearchDelegateDiscovery.getInstance(); | ||
assertNull(del); | ||
} finally { | ||
if( oldSystemProperty != null ) | ||
System.setProperty(DELEGATE_SYSPROP, oldSystemProperty); | ||
else | ||
System.clearProperty(DELEGATE_SYSPROP); | ||
} | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
...pse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TestJavaSearchDelegate.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,34 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Red Hat Inc 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: | ||
* Red Hat Inc - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.core.tests.model; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jdt.core.search.IJavaSearchDelegate; | ||
import org.eclipse.jdt.internal.core.search.matching.MatchLocator; | ||
import org.eclipse.jdt.internal.core.search.matching.PossibleMatch; | ||
|
||
public class TestJavaSearchDelegate implements IJavaSearchDelegate { | ||
|
||
public TestJavaSearchDelegate() { | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
@Override | ||
public void locateMatches(MatchLocator locator, IJavaProject javaProject, PossibleMatch[] possibleMatches, | ||
int start, int length) throws CoreException { | ||
// do nothing, stub | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!-- Schema file written by PDE --> | ||
<schema targetNamespace="org.eclipse.jdt.core" xmlns="http://www.w3.org/2001/XMLSchema"> | ||
<annotation> | ||
<appInfo> | ||
<meta.schema plugin="org.eclipse.jdt.core" id="javaSearchDelegate" name="Java Search Delegate"/> | ||
</appInfo> | ||
<documentation> | ||
This extension point provides the ability to replace the Java Search functionality. The resolver will be instantiated on-demand based on the value of the system property `IJavaSearchDelegate`, which must be set to the id of an implementing extension. This extension point is not intended to be implemented by clients. This extension point is not considered API. This extension point may be modified or removed at any moment. | ||
</documentation> | ||
</annotation> | ||
|
||
<element name="extension"> | ||
<annotation> | ||
<appInfo> | ||
<meta.element /> | ||
</appInfo> | ||
</annotation> | ||
<complexType> | ||
<sequence> | ||
<element ref="searchDelegate" minOccurs="0" maxOccurs="1"/> | ||
</sequence> | ||
<attribute name="point" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="id" type="string"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="name" type="string"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
<appInfo> | ||
<meta.attribute translatable="true"/> | ||
</appInfo> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
<element name="searchDelegate"> | ||
<annotation> | ||
<documentation> | ||
Definition of a Java Search Delegate. | ||
</documentation> | ||
</annotation> | ||
<complexType> | ||
<attribute name="class" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
The class that implements this Java Search Delegate. This class must implement the <code>org.eclipse.jdt.core.search.IJavaSearchDelegate</code> interface with a public 0-arg constructor. | ||
</documentation> | ||
<appInfo> | ||
<meta.attribute kind="java" basedOn=":org.eclipse.jdt.core.search.IJavaSearchDelegate"/> | ||
</appInfo> | ||
</annotation> | ||
</attribute> | ||
<attribute name="id" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
A unique identifier for this search delegate | ||
</documentation> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
<annotation> | ||
<appInfo> | ||
<meta.section type="since"/> | ||
</appInfo> | ||
<documentation> | ||
3.38 | ||
</documentation> | ||
</annotation> | ||
|
||
<annotation> | ||
<appInfo> | ||
<meta.section type="examples"/> | ||
</appInfo> | ||
<documentation> | ||
Example of a declaration of a <code>IJavaSearchDelegate</code>: <pre> | ||
<extension | ||
point="org.eclipse.jdt.core.javaSearchDelegate"> | ||
<resolver | ||
class="org.eclipse.jdt.core.MySearchDelegate" | ||
id="org.eclipse.jdt.core.MySearchDelegate"> | ||
</resolver> | ||
</extension> | ||
</pre> | ||
</documentation> | ||
</annotation> | ||
|
||
|
||
|
||
<annotation> | ||
<appInfo> | ||
<meta.section type="copyright"/> | ||
</appInfo> | ||
<documentation> | ||
Copyright (c) 2025 Red Hat, Inc. and others.<br> | ||
|
||
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 | ||
<a href="https://www.eclipse.org/legal/epl-2.0">https://www.eclipse.org/legal/epl-v20.html</a>/ | ||
|
||
SPDX-License-Identifier: EPL-2.0 | ||
</documentation> | ||
</annotation> | ||
|
||
</schema> |
44 changes: 44 additions & 0 deletions
44
org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/IJavaSearchDelegate.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,44 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Red Hat Inc 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: | ||
* Red Hat Inc - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.core.search; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jdt.internal.core.search.matching.MatchLocator; | ||
import org.eclipse.jdt.internal.core.search.matching.PossibleMatch; | ||
|
||
/** | ||
* This interface represents a delegate that can take over the discovery of search results | ||
* for java-based searches. | ||
* | ||
* This interface makes use of internal classes and is not considered stable or API. | ||
* | ||
* @since 3.41 | ||
*/ | ||
public interface IJavaSearchDelegate { | ||
|
||
/** | ||
* Fill the PossibleMatch objects' state with confirmed and possible results using the | ||
* search strategy that this delegate employs. | ||
* | ||
* @param locator The MatchLocator initiating the request | ||
* @param javaProject The context in which the search is being performed | ||
* @param possibleMatches An array of possible matches | ||
* @param start The start index with which to begin searching | ||
* @param length The length of matches with which to search | ||
* @throws CoreException | ||
*/ | ||
void locateMatches(MatchLocator locator, IJavaProject javaProject, PossibleMatch[] possibleMatches, int start, int length) throws CoreException; | ||
|
||
} |
Oops, something went wrong.