-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fixes #3373] Find references for extension methods
- Loading branch information
Showing
13 changed files
with
184 additions
and
2 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
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
test/eclipse/resource/findreferences/extensionMethod/Extension.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,15 @@ | ||
package pkg; | ||
|
||
public static class Extension { | ||
public static String test(String s) { | ||
return s; | ||
} | ||
|
||
public static String test(String s, int i) { | ||
return s; | ||
} | ||
|
||
public static String test(String s, String... s2) { | ||
return s; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/eclipse/resource/findreferences/extensionMethod/Usage.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,13 @@ | ||
package pkg; | ||
|
||
import lombok.experimental.ExtensionMethod; | ||
|
||
@ExtensionMethod(Extension.class) | ||
public class Usage { | ||
public void test() { | ||
private String string; | ||
string.test(); | ||
string.test("a"); | ||
string.test(1); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/eclipse/resource/rename/extensionMethod/after/Extension.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,15 @@ | ||
package pkg; | ||
|
||
public static class Extension { | ||
public static String newTest(String s) { | ||
return s; | ||
} | ||
|
||
public static String test(String s, int i) { | ||
return s; | ||
} | ||
|
||
public static String test(String s, String... s2) { | ||
return s; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/eclipse/resource/rename/extensionMethod/after/Usage.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,13 @@ | ||
package pkg; | ||
|
||
import lombok.experimental.ExtensionMethod; | ||
|
||
@ExtensionMethod(Extension.class) | ||
public class Usage { | ||
public void test() { | ||
private String string; | ||
string.newTest(); | ||
string.test("a"); | ||
string.test(1); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/eclipse/resource/rename/extensionMethod/before/Extension.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,15 @@ | ||
package pkg; | ||
|
||
public static class Extension { | ||
public static String test(String s) { | ||
return s; | ||
} | ||
|
||
public static String test(String s, int i) { | ||
return s; | ||
} | ||
|
||
public static String test(String s, String... s2) { | ||
return s; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/eclipse/resource/rename/extensionMethod/before/Usage.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,13 @@ | ||
package pkg; | ||
|
||
import lombok.experimental.ExtensionMethod; | ||
|
||
@ExtensionMethod(Extension.class) | ||
public class Usage { | ||
public void test() { | ||
private String string; | ||
string.test(); | ||
string.test("a"); | ||
string.test(1); | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
test/eclipse/src/lombok/eclipse/references/FindReferencesTest.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,56 @@ | ||
package lombok.eclipse.references; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.IJavaElement; | ||
import org.eclipse.jdt.core.IType; | ||
import org.eclipse.jdt.core.JavaModelException; | ||
import org.eclipse.jdt.core.search.IJavaSearchConstants; | ||
import org.eclipse.jdt.core.search.SearchEngine; | ||
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.internal.corext.refactoring.CollectingSearchRequestor; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import lombok.eclipse.EclipseRunner; | ||
import lombok.eclipse.SetupSingleFileTest; | ||
|
||
@RunWith(EclipseRunner.class) | ||
public class FindReferencesTest { | ||
|
||
@Rule | ||
public SetupSingleFileTest setup = new SetupSingleFileTest(); | ||
|
||
@Test | ||
public void extensionMethod() throws Exception { | ||
ICompilationUnit extensionCu = setup.getPackageFragment().getCompilationUnit("Extension.java"); | ||
IType type = extensionCu.findPrimaryType(); | ||
List<SearchMatch> firstResult = searchInProject(type.getMethods()[0]); | ||
assertEquals(firstResult.size(), 2); | ||
|
||
ICompilationUnit usageCu = setup.getPackageFragment().getCompilationUnit("Usage.java"); | ||
List<SearchMatch> secondResult = searchInProject(usageCu.codeSelect(170, 0)[0]); | ||
assertEquals(secondResult.size(), 2); | ||
} | ||
|
||
private List<SearchMatch> searchInProject(IJavaElement element) throws CoreException, JavaModelException { | ||
CollectingSearchRequestor requestor = new CollectingSearchRequestor(); | ||
SearchEngine engine = new SearchEngine(); | ||
engine.search( | ||
SearchPattern.createPattern(element, IJavaSearchConstants.ALL_OCCURRENCES, SearchPattern.R_EXACT_MATCH), | ||
new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, | ||
SearchEngine.createJavaSearchScope(new IJavaElement[] { setup.getJavaProject() }), | ||
requestor, | ||
null | ||
); | ||
|
||
return requestor.getResults(); | ||
} | ||
} |