Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Reference-Searcher for fields and lombok generated method…
- Loading branch information
1 parent
769c9ba
commit 57c46f6
Showing
25 changed files
with
450 additions
and
92 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
76 changes: 0 additions & 76 deletions
76
...ain/java/de/plushnikov/intellij/plugin/extension/LombokFieldFindUsagesHandlerFactory.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/main/java/de/plushnikov/intellij/plugin/extension/LombokReferenceSearcher.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
package de.plushnikov.intellij.plugin.extension; | |||
|
|||
import com.intellij.openapi.application.QueryExecutorBase; | |||
import com.intellij.psi.PsiClass; | |||
import com.intellij.psi.PsiElement; | |||
import com.intellij.psi.PsiField; | |||
import com.intellij.psi.PsiReference; | |||
import com.intellij.psi.search.SearchRequestCollector; | |||
import com.intellij.psi.search.UsageSearchContext; | |||
import com.intellij.psi.search.searches.ReferencesSearch; | |||
import com.intellij.util.Processor; | |||
import de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder; | |||
import org.jetbrains.annotations.NotNull; | |||
|
|||
import java.util.Arrays; | |||
|
|||
public class LombokReferenceSearcher extends QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> { | |||
|
|||
public LombokReferenceSearcher() { | |||
super(true); | |||
} | |||
|
|||
@Override | |||
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) { | |||
PsiElement refElement = queryParameters.getElementToSearch(); | |||
|
|||
if (refElement instanceof PsiField) { | |||
processPsiField((PsiField) refElement, queryParameters.getOptimizer()); | |||
} | |||
} | |||
|
|||
private void processPsiField(final PsiField refPsiField, final SearchRequestCollector collector) { | |||
final PsiClass containingClass = refPsiField.getContainingClass(); | |||
if (null != containingClass) { | |||
processClassMethods(refPsiField, collector, containingClass); | |||
|
|||
Arrays.stream(containingClass.getInnerClasses()) | |||
.forEach(psiClass -> processClassMethods(refPsiField, collector, psiClass)); | |||
} | |||
} | |||
|
|||
private void processClassMethods(PsiField refPsiField, SearchRequestCollector collector, PsiClass containingClass) { | |||
Arrays.stream(containingClass.getMethods()) | |||
.filter(LombokLightMethodBuilder.class::isInstance) | |||
.filter(psiMethod -> psiMethod.getNavigationElement() == refPsiField) | |||
.forEach(psiMethod -> { | |||
collector.searchWord(psiMethod.getName(), psiMethod.getUseScope(), UsageSearchContext.IN_CODE, true, psiMethod); | |||
}); | |||
} | |||
|
|||
} |
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
55 changes: 55 additions & 0 deletions
55
src/test/java/de/plushnikov/intellij/plugin/usage/LombokUsageTest.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,55 @@ | |||
package de.plushnikov.intellij.plugin.usage; | |||
|
|||
import com.intellij.usageView.UsageInfo; | |||
import de.plushnikov.intellij.plugin.AbstractLombokLightCodeInsightTestCase; | |||
import org.jetbrains.annotations.NotNull; | |||
|
|||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
import java.util.List; | |||
|
|||
/** | |||
* Test for lombok find usage extension | |||
*/ | |||
public class LombokUsageTest extends AbstractLombokLightCodeInsightTestCase { | |||
|
|||
public void testFindUsageGetterSetter() { | |||
final Collection<UsageInfo> usages = loadTestClass(); | |||
assertUsages(usages, "findUsageGetterSetter.setBar", "findUsageGetterSetter.getBar"); | |||
} | |||
|
|||
public void testFindUsageAccessors() { | |||
final Collection<UsageInfo> usages = loadTestClass(); | |||
assertUsages(usages, "findUsageAccessors.setBar", "findUsageAccessors.getBar"); | |||
} | |||
|
|||
public void testFindUsageWither() { | |||
final Collection<UsageInfo> usages = loadTestClass(); | |||
assertUsages(usages, "findUsageWither\n .withBar", "findUsageWither.getBar"); | |||
} | |||
|
|||
public void testFindUsageBuilder() { | |||
final Collection<UsageInfo> usages = loadTestClass(); | |||
assertUsages(usages, "FindUsageBuilder.builder()\n .bar", "findUsageBuilder.getBar"); | |||
} | |||
|
|||
private void assertUsages(Collection<UsageInfo> usages, String... usageTexts) { | |||
assertEquals(usageTexts.length, usages.size()); | |||
List<UsageInfo> sortedUsages = new ArrayList<UsageInfo>(usages); | |||
Collections.sort(sortedUsages, UsageInfo::compareToByStartOffset); | |||
for (int i = 0; i < usageTexts.length; i++) { | |||
assertEquals(usageTexts[i], sortedUsages.get(i).getElement().getText()); | |||
} | |||
} | |||
|
|||
@NotNull | |||
private Collection<UsageInfo> loadTestClass() { | |||
return myFixture.testFindUsages(getBasePath() + getTestName(false) + ".java"); | |||
} | |||
|
|||
@Override | |||
protected String getBasePath() { | |||
return super.getBasePath() + "/usage/"; | |||
} | |||
} |
21 changes: 21 additions & 0 deletions
21
test-manual/src/main/java/de/plushnikov/builder/issue450/BuilderWithDeprecatedField.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
package de.plushnikov.builder.issue450; | |||
|
|||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
import java.util.List; | |||
|
|||
@lombok.Builder | |||
public class BuilderWithDeprecatedField { | |||
private String bar; | |||
|
|||
@Deprecated | |||
private String foo; | |||
|
|||
@Deprecated | |||
private List<String> xyzs; | |||
|
|||
public static void main(String[] args) { | |||
System.out.println(BuilderWithDeprecatedField.builder().bar("bar").foo("foo").xyzs(Collections.singletonList("yxzx")).clearXyzs().xyz("xyz").build()); | |||
} | |||
} |
13 changes: 13 additions & 0 deletions
13
test-manual/src/main/java/de/plushnikov/builder/issue450/BuilderWithDeprecatedParam.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
package de.plushnikov.builder.issue450; | |||
|
|||
public class BuilderWithDeprecatedParam { | |||
|
|||
@lombok.Builder | |||
private static java.util.Collection<String> creator(String bar, @Deprecated String foo) { | |||
return java.util.Arrays.asList(bar, foo); | |||
} | |||
|
|||
public static void main(String[] args) { | |||
System.out.println(BuilderWithDeprecatedParam.builder().bar("bar").foo("foo").build()); | |||
} | |||
} |
15 changes: 15 additions & 0 deletions
15
test-manual/src/main/java/de/plushnikov/builder/issue499/TestClass.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
package de.plushnikov.builder.issue499; | |||
|
|||
import lombok.Builder; | |||
import lombok.experimental.Accessors; | |||
|
|||
@Builder | |||
public class TestClass { | |||
@Accessors(prefix = "m") | |||
private String mSample = "sample 1"; | |||
|
|||
public static void main(String[] args) { | |||
TestClass.builder().sample("sample 2").build(); | |||
builder().sample("").build(); | |||
} | |||
} |
37 changes: 37 additions & 0 deletions
37
test-manual/src/main/java/de/plushnikov/findusages/DataItem.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,37 @@ | |||
package de.plushnikov.findusages; | |||
|
|||
import lombok.*; | |||
import lombok.experimental.Accessors; | |||
import sun.security.util.Password; | |||
|
|||
import java.time.Instant; | |||
|
|||
@Value | |||
@ToString | |||
@Accessors(fluent = true) | |||
@Builder | |||
public class DataItem { | |||
@NonNull | |||
String name; | |||
String anotherName; | |||
@NonNull | |||
Instant createTimestamp; | |||
@NonNull | |||
String content; | |||
|
|||
@Getter | |||
@Accessors(fluent = true) | |||
final Password password; | |||
|
|||
public static void main(String[] args) { | |||
DataItem item = DataItem.builder() | |||
.name("a") | |||
.anotherName("a") | |||
.createTimestamp(Instant.now()) | |||
.content("content") | |||
.build(); | |||
System.out.println("Item.name = " + item.name()); | |||
System.out.println("Item.name = " + item.anotherName()); | |||
System.out.println(item.password()); | |||
} | |||
} |
23 changes: 23 additions & 0 deletions
23
test-manual/src/main/java/de/plushnikov/findusages/FindUsageAccessors.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
package de.plushnikov.findusages; | |||
|
|||
import lombok.Data; | |||
import lombok.experimental.Accessors; | |||
|
|||
@Data | |||
@Accessors(prefix = "m", fluent = true) | |||
public class FindUsageAccessors { | |||
private int mFoo; | |||
|
|||
@Accessors(prefix = "_") | |||
private String _Bar; | |||
|
|||
private String bMar; | |||
|
|||
public static void main(String[] args) { | |||
FindUsageAccessors findUsageAccessors = new FindUsageAccessors(); | |||
findUsageAccessors.setBar("myBar"); | |||
findUsageAccessors.foo(1981); | |||
System.out.println("Bar is: " + findUsageAccessors.getBar()); | |||
System.out.println("Foo is: " + findUsageAccessors.foo()); | |||
} | |||
} |
Oops, something went wrong.