diff options
author | Rawi01 <Rawi01@users.noreply.github.com> | 2023-03-20 21:46:25 +0100 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2023-03-22 22:57:52 +0100 |
commit | afceb138e6e4ca2dca0f16fd5297d7451f5f4e80 (patch) | |
tree | ea8d5ddd944809b92f9a9ed857da90c00b521ac7 /test/eclipse/src | |
parent | d56b576c26d6e6a0621997a9758151cf41e7a74e (diff) | |
download | lombok-afceb138e6e4ca2dca0f16fd5297d7451f5f4e80.tar.gz lombok-afceb138e6e4ca2dca0f16fd5297d7451f5f4e80.tar.bz2 lombok-afceb138e6e4ca2dca0f16fd5297d7451f5f4e80.zip |
[fixes #3373] Find references for extension methods
Diffstat (limited to 'test/eclipse/src')
4 files changed, 74 insertions, 2 deletions
diff --git a/test/eclipse/src/lombok/eclipse/EclipseTests.java b/test/eclipse/src/lombok/eclipse/EclipseTests.java index ba017fd2..b293b8ae 100644 --- a/test/eclipse/src/lombok/eclipse/EclipseTests.java +++ b/test/eclipse/src/lombok/eclipse/EclipseTests.java @@ -8,9 +8,10 @@ import lombok.eclipse.cleanup.CleanupTest; import lombok.eclipse.edit.SelectTest; import lombok.eclipse.refactoring.ExtractInterfaceTest; import lombok.eclipse.refactoring.RenameTest; +import lombok.eclipse.references.FindReferencesTest; @RunWith(Suite.class) -@SuiteClasses({ExtractInterfaceTest.class, RenameTest.class, SelectTest.class, CleanupTest.class}) +@SuiteClasses({ExtractInterfaceTest.class, RenameTest.class, SelectTest.class, CleanupTest.class, FindReferencesTest.class}) public class EclipseTests { } diff --git a/test/eclipse/src/lombok/eclipse/SetupBeforeAfterTest.java b/test/eclipse/src/lombok/eclipse/SetupBeforeAfterTest.java index 96e21d4b..05deabde 100644 --- a/test/eclipse/src/lombok/eclipse/SetupBeforeAfterTest.java +++ b/test/eclipse/src/lombok/eclipse/SetupBeforeAfterTest.java @@ -32,7 +32,7 @@ public class SetupBeforeAfterTest extends SetupTest { protected void succeeded(Description description) { try { compareWithAfter(); - } catch (Throwable e) { + } catch (Exception e) { throw new RuntimeException(e); } } diff --git a/test/eclipse/src/lombok/eclipse/refactoring/RenameTest.java b/test/eclipse/src/lombok/eclipse/refactoring/RenameTest.java index c1a86736..fe7136a7 100644 --- a/test/eclipse/src/lombok/eclipse/refactoring/RenameTest.java +++ b/test/eclipse/src/lombok/eclipse/refactoring/RenameTest.java @@ -4,8 +4,11 @@ import static lombok.eclipse.RefactoringUtils.performRefactoring; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IField; +import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor; +import org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor; +import org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -68,4 +71,16 @@ public class RenameTest { performRefactoring(renameFieldProcessor); } + + @Test + public void extensionMethod() throws Exception { + ICompilationUnit cu = setup.getPackageFragment().getCompilationUnit("Extension.java"); + IType type = cu.findPrimaryType(); + IMethod method = type.getMethods()[0]; + + RenameMethodProcessor renameMethodProcessor = new RenameNonVirtualMethodProcessor(method); + renameMethodProcessor.setNewElementName("newTest"); + + performRefactoring(renameMethodProcessor); + } } diff --git a/test/eclipse/src/lombok/eclipse/references/FindReferencesTest.java b/test/eclipse/src/lombok/eclipse/references/FindReferencesTest.java new file mode 100644 index 00000000..a4668088 --- /dev/null +++ b/test/eclipse/src/lombok/eclipse/references/FindReferencesTest.java @@ -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(); + } +} |