From 5483d473dae590154f1347111b881905da21d83e Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Wed, 30 Oct 2019 20:41:02 +0100 Subject: [PATCH 01/12] fixing test for different versions --- .../inspection/DataFlowInspectionTest.java | 9 +++++++- testData/inspection/diverse/Issue440.java | 2 +- .../inspection/diverse/Issue440Prior183.java | 22 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 testData/inspection/diverse/Issue440Prior183.java diff --git a/src/test/java/de/plushnikov/intellij/plugin/inspection/DataFlowInspectionTest.java b/src/test/java/de/plushnikov/intellij/plugin/inspection/DataFlowInspectionTest.java index d9684885e..605bac9e0 100644 --- a/src/test/java/de/plushnikov/intellij/plugin/inspection/DataFlowInspectionTest.java +++ b/src/test/java/de/plushnikov/intellij/plugin/inspection/DataFlowInspectionTest.java @@ -2,6 +2,8 @@ import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.dataFlow.DataFlowInspection; +import com.intellij.openapi.application.ApplicationInfo; +import com.intellij.openapi.util.BuildNumber; public class DataFlowInspectionTest extends LombokInspectionTest { @@ -16,7 +18,12 @@ protected InspectionProfileEntry getInspection() { } public void testIssue440() { - doTest(); + final BuildNumber buildNumber = ApplicationInfo.getInstance().getBuild(); + if (183 <= buildNumber.getBaselineVersion()) { + doTest(); + } else { + doNamedTest("Issue440Prior183"); + } } } diff --git a/testData/inspection/diverse/Issue440.java b/testData/inspection/diverse/Issue440.java index 855532ee5..650a11986 100644 --- a/testData/inspection/diverse/Issue440.java +++ b/testData/inspection/diverse/Issue440.java @@ -6,7 +6,7 @@ public class Issue440 { private Car car; - private final String carString = car.toString(); + private final String carString = car.toString(); public Issue440(Bar bar) { this.bar = bar; diff --git a/testData/inspection/diverse/Issue440Prior183.java b/testData/inspection/diverse/Issue440Prior183.java new file mode 100644 index 000000000..95ba98565 --- /dev/null +++ b/testData/inspection/diverse/Issue440Prior183.java @@ -0,0 +1,22 @@ +public class Issue440Prior183 { + private Bar bar; + + @lombok.Getter(lazy = true) + private final String barString = bar.toString(); + + private Car car; + + private final String carString = car.toString(); + + public Issue440Prior183(Bar bar) { + this.bar = bar; + } + + private static class Bar { + + } + + private static class Car { + + } +} From 099870604570fc7d34831ab43ff6b74441867a9d Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Thu, 31 Oct 2019 20:42:41 +0100 Subject: [PATCH 02/12] updated idea version --- .travis.yml | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6c08627d9..d9ca7ebe5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ before_cache: env: - IDEA_VERSION=LATEST-EAP-SNAPSHOT UPLOAD_BUILD=true - - IDEA_VERSION=2019.2.3 UPLOAD_BUILD=false + - IDEA_VERSION=2019.2.4 UPLOAD_BUILD=false - IDEA_VERSION=2019.2 UPLOAD_BUILD=true before_install: diff --git a/gradle.properties b/gradle.properties index 43c6d5b96..a82031140 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ # https://www.jetbrains.com/intellij-repository/snapshots # ideaVersion=2019.2 -#ideaVersion=2019.2.3 +#ideaVersion=2019.2.4 #ideaVersion=LATEST-EAP-SNAPSHOT #ideaVersion = LATEST-TRUNK-SNAPSHOT # From 10b3b4ecf9f986ca912b024880fda3627e620550 Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Sun, 1 Dec 2019 12:35:15 +0100 Subject: [PATCH 03/12] updated versions --- .travis.yml | 1 + build.gradle | 4 ++-- gradle.properties | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index d9ca7ebe5..1a9b71209 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ before_cache: env: - IDEA_VERSION=LATEST-EAP-SNAPSHOT UPLOAD_BUILD=true + - IDEA_VERSION=2019.3 UPLOAD_BUILD=true - IDEA_VERSION=2019.2.4 UPLOAD_BUILD=false - IDEA_VERSION=2019.2 UPLOAD_BUILD=true diff --git a/build.gradle b/build.gradle index a91ac597f..15cba38d1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { - id "org.jetbrains.intellij" version "0.4.10" - id "org.jetbrains.grammarkit" version "2019.2.1" + id "org.jetbrains.intellij" version "0.4.14" + id "org.jetbrains.grammarkit" version "2019.3" id "com.github.ManifestClasspath" version "0.1.0-RELEASE" } diff --git a/gradle.properties b/gradle.properties index a82031140..b45787cd4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,12 +2,13 @@ # https://www.jetbrains.com/intellij-repository/releases # https://www.jetbrains.com/intellij-repository/snapshots # -ideaVersion=2019.2 +ideaVersion=2019.3 +#ideaVersion=2019.2 #ideaVersion=2019.2.4 #ideaVersion=LATEST-EAP-SNAPSHOT #ideaVersion = LATEST-TRUNK-SNAPSHOT # -lastReleaseVersion=2019.2 +lastReleaseVersion=2019.3 # pluginGroup=de.plushnikov.intellij.plugin pluginName=lombok-plugin From b88cbebd5848df438cb0080a03d57224348e48db Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Sun, 1 Dec 2019 12:35:46 +0100 Subject: [PATCH 04/12] updated sponsors links --- parts/pluginDescription.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/parts/pluginDescription.html b/parts/pluginDescription.html index 6eb0ae583..20f6df2d6 100644 --- a/parts/pluginDescription.html +++ b/parts/pluginDescription.html @@ -12,10 +12,11 @@

IntelliJ Lombok plugin

Sponsors
- -
Discuss, review, and share code with your team in your JetBrains IDE. Integrates with Slack, Jira, Trello, Github and more. -Try it free! + + Codestream +
+Discussing code is now as easy as highlighting a block and typing a comment right from your IDE. Take the pain out of code reviews and improve code quality. +Try it free!

Features @@ -24,7 +25,8 @@

IntelliJ Lombok plugin

  • @FieldNameConstants
  • @ToString
  • @EqualsAndHashCode
  • -
  • @AllArgsConstructor, @RequiredArgsConstructor and @NoArgsConstructor
  • +
  • @AllArgsConstructor, @RequiredArgsConstructor and + @NoArgsConstructor
  • @Log, @Log4j, @Log4j2, @Slf4j, @XSlf4j, @CommonsLog, @JBossLog, @Flogger, @CustomLog
  • @Data
  • From a59854c2e8b322b975d0d295f94a9584b4d68eed Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Sun, 1 Dec 2019 13:49:59 +0100 Subject: [PATCH 05/12] created backport branch for IntelliJ 2019.2 builds --- .travis.yml | 7 ++----- build.gradle | 13 ++----------- gradle.properties | 5 +---- gradle/wrapper/gradle-wrapper.properties | 2 +- 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1a9b71209..b964cb8af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,10 +15,7 @@ before_cache: - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ env: - - IDEA_VERSION=LATEST-EAP-SNAPSHOT UPLOAD_BUILD=true - - IDEA_VERSION=2019.3 UPLOAD_BUILD=true - - IDEA_VERSION=2019.2.4 UPLOAD_BUILD=false - - IDEA_VERSION=2019.2 UPLOAD_BUILD=true + - IDEA_VERSION=2019.2 before_install: - chmod +x gradlew @@ -44,6 +41,6 @@ deploy: file: "build/distributions/lombok-plugin-*.zip" on: tags: true - condition: (( $TRAVIS_TAG =~ ^releasebuild_[0-9]+.*$ ) && ( $UPLOAD_BUILD=true )) + condition: $TRAVIS_TAG =~ ^releasebuild_[0-9]+.*$ after_deploy: - ./gradlew publishPlugin diff --git a/build.gradle b/build.gradle index 15cba38d1..e368bde17 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "org.jetbrains.intellij" version "0.4.14" - id "org.jetbrains.grammarkit" version "2019.3" + id "org.jetbrains.grammarkit" version "2019.2.1" id "com.github.ManifestClasspath" version "0.1.0-RELEASE" } @@ -135,15 +135,6 @@ copy { into("generated/resources") } -grammarKit { - //tag or short commit hash of IntelliJ patched JFlex -// jflexRelease = '1.7.0-1' - //tag or short commit hash of Grammar-Kit to use - if (isEAP) { - grammarKitRelease = '07f30a1e7666f36ae780f614b6bbc89690ba36c3' - } -} - task generateLombokConfigParser(type: org.jetbrains.grammarkit.tasks.GenerateParser) { println "Generating Parser for GrammerKit: ${grammarKit.grammarKitRelease}" @@ -175,7 +166,7 @@ test { exceptionFormat = 'full' showStandardStreams = true } - if( isCI ){ + if (isCI) { testLogging { events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' exceptionFormat "full" diff --git a/gradle.properties b/gradle.properties index b45787cd4..c513a119f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,11 +2,8 @@ # https://www.jetbrains.com/intellij-repository/releases # https://www.jetbrains.com/intellij-repository/snapshots # -ideaVersion=2019.3 #ideaVersion=2019.2 -#ideaVersion=2019.2.4 -#ideaVersion=LATEST-EAP-SNAPSHOT -#ideaVersion = LATEST-TRUNK-SNAPSHOT +ideaVersion=2019.2.4 # lastReleaseVersion=2019.3 # diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4269777d1..528159037 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip From 554613b08f185792f12390a2cef4ba4d17d8a28b Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Sun, 1 Dec 2019 13:52:56 +0100 Subject: [PATCH 06/12] updated current versions --- .travis.yml | 8 +++----- gradle.properties | 2 -- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1a9b71209..f85087692 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,10 +15,8 @@ before_cache: - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ env: - - IDEA_VERSION=LATEST-EAP-SNAPSHOT UPLOAD_BUILD=true - - IDEA_VERSION=2019.3 UPLOAD_BUILD=true - - IDEA_VERSION=2019.2.4 UPLOAD_BUILD=false - - IDEA_VERSION=2019.2 UPLOAD_BUILD=true + - IDEA_VERSION=LATEST-EAP-SNAPSHOT + - IDEA_VERSION=2019.3 before_install: - chmod +x gradlew @@ -44,6 +42,6 @@ deploy: file: "build/distributions/lombok-plugin-*.zip" on: tags: true - condition: (( $TRAVIS_TAG =~ ^releasebuild_[0-9]+.*$ ) && ( $UPLOAD_BUILD=true )) + condition: $TRAVIS_TAG =~ ^releasebuild_[0-9]+.*$ after_deploy: - ./gradlew publishPlugin diff --git a/gradle.properties b/gradle.properties index b45787cd4..ac28c276d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,6 @@ # https://www.jetbrains.com/intellij-repository/snapshots # ideaVersion=2019.3 -#ideaVersion=2019.2 -#ideaVersion=2019.2.4 #ideaVersion=LATEST-EAP-SNAPSHOT #ideaVersion = LATEST-TRUNK-SNAPSHOT # diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4269777d1..528159037 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip From 515d055c2b138c895817d644b41c5dbb388f29a1 Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Sun, 1 Dec 2019 13:54:57 +0100 Subject: [PATCH 07/12] fix master config --- build.gradle | 9 --------- 1 file changed, 9 deletions(-) diff --git a/build.gradle b/build.gradle index 15cba38d1..d01015129 100644 --- a/build.gradle +++ b/build.gradle @@ -135,15 +135,6 @@ copy { into("generated/resources") } -grammarKit { - //tag or short commit hash of IntelliJ patched JFlex -// jflexRelease = '1.7.0-1' - //tag or short commit hash of Grammar-Kit to use - if (isEAP) { - grammarKitRelease = '07f30a1e7666f36ae780f614b6bbc89690ba36c3' - } -} - task generateLombokConfigParser(type: org.jetbrains.grammarkit.tasks.GenerateParser) { println "Generating Parser for GrammerKit: ${grammarKit.grammarKitRelease}" From d5eb89c9a259972aa894e53526332e31caf15be0 Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Sun, 1 Dec 2019 13:55:10 +0100 Subject: [PATCH 08/12] manual tests --- .../de/plushnikov/findusages/Issue645.java | 21 +++++++++++++++++++ .../de/plushnikov/sneakythrows/Issue394.java | 18 ++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test-manual/src/main/java/de/plushnikov/findusages/Issue645.java create mode 100644 test-manual/src/main/java/de/plushnikov/sneakythrows/Issue394.java diff --git a/test-manual/src/main/java/de/plushnikov/findusages/Issue645.java b/test-manual/src/main/java/de/plushnikov/findusages/Issue645.java new file mode 100644 index 000000000..77fecf510 --- /dev/null +++ b/test-manual/src/main/java/de/plushnikov/findusages/Issue645.java @@ -0,0 +1,21 @@ +package de.plushnikov.findusages; + +import lombok.Builder; + +public class Issue645 { + @Builder + public static class SomeDataClass { + public static class SomeDataClassBuilder { + private void buildWithJSON() { + this.jsonObject = "test"; + } + } + + public final String jsonObject; + } + + public static void main(String[] args) { + SomeDataClass dataClass = SomeDataClass.builder().jsonObject("sdsdsd").build(); + System.out.println(dataClass.jsonObject); + } +} diff --git a/test-manual/src/main/java/de/plushnikov/sneakythrows/Issue394.java b/test-manual/src/main/java/de/plushnikov/sneakythrows/Issue394.java new file mode 100644 index 000000000..5ec660098 --- /dev/null +++ b/test-manual/src/main/java/de/plushnikov/sneakythrows/Issue394.java @@ -0,0 +1,18 @@ +package de.plushnikov.sneakythrows; + +import lombok.SneakyThrows; + +import java.io.File; + +public class Issue394 { + +// @SneakyThrows + public String calcString() { + new File("somePath").createNewFile(); + return ""; + } + + public static void main(String[] args) { + new Issue394().calcString(); + } +} From 321303844b0d50abb64cbf8adc540e47bea93eac Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Sun, 1 Dec 2019 15:00:43 +0200 Subject: [PATCH 09/12] #394 (#694) - register quick fix for add SneakyThrows annotation on unhandled exceptions - replaced for onX handler strings to class names, also added lombok.With annotation class as handled --- .../extension/LombokHighlightErrorFilter.java | 135 ++++++++++++++---- .../plugin/handler/OnXAnnotationHandler.java | 24 +++- 2 files changed, 122 insertions(+), 37 deletions(-) diff --git a/src/main/java/de/plushnikov/intellij/plugin/extension/LombokHighlightErrorFilter.java b/src/main/java/de/plushnikov/intellij/plugin/extension/LombokHighlightErrorFilter.java index 567ebeb5e..154c4d91e 100644 --- a/src/main/java/de/plushnikov/intellij/plugin/extension/LombokHighlightErrorFilter.java +++ b/src/main/java/de/plushnikov/intellij/plugin/extension/LombokHighlightErrorFilter.java @@ -1,43 +1,55 @@ package de.plushnikov.intellij.plugin.extension; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.daemon.impl.HighlightInfoFilter; +import com.intellij.codeInsight.intention.AddAnnotationFix; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.editor.colors.CodeInsightColors; import com.intellij.openapi.editor.colors.TextAttributesKey; -import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiClassInitializer; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiLambdaExpression; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.PsiMethodReferenceExpression; +import com.intellij.psi.PsiModifierListOwner; +import com.intellij.psi.util.PsiTreeUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import lombok.SneakyThrows; import de.plushnikov.intellij.plugin.handler.BuilderHandler; import de.plushnikov.intellij.plugin.handler.EqualsAndHashCodeCallSuperHandler; import de.plushnikov.intellij.plugin.handler.LazyGetterHandler; import de.plushnikov.intellij.plugin.handler.OnXAnnotationHandler; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; public class LombokHighlightErrorFilter implements HighlightInfoFilter { - - private static final Pattern UNINITIALIZED_MESSAGE = Pattern.compile("Variable '.+' might not have been initialized"); private static final Pattern LOMBOK_ANY_ANNOTATION_REQUIRED = Pattern.compile("Incompatible types\\. Found: '__*', required: 'lombok.*AnyAnnotation\\[\\]'"); private final Map>> registeredFilters; + private final Map>> registeredHooks; public LombokHighlightErrorFilter() { registeredFilters = new HashMap<>(); + registeredHooks = new HashMap<>(); for (LombokHighlightFilter value : LombokHighlightFilter.values()) { registeredFilters.computeIfAbsent(value.severity, s -> new HashMap<>()) .computeIfAbsent(value.key, k -> new ArrayList<>()) .add(value); } + + for (LombokHighlightFixHook value : LombokHighlightFixHook.values()) { + registeredHooks.computeIfAbsent(value.severity, s -> new HashMap<>()) + .computeIfAbsent(value.key, k -> new ArrayList<>()) + .add(value); + } } @Override @@ -51,30 +63,97 @@ public boolean accept(@NotNull HighlightInfo highlightInfo, @Nullable PsiFile fi return true; } - String description = StringUtil.notNullize(highlightInfo.getDescription()); - if (HighlightSeverity.ERROR.equals(highlightInfo.getSeverity())) { + // check exceptions for highlights + boolean acceptHighlight = registeredFilters + .getOrDefault(highlightInfo.getSeverity(), Collections.emptyMap()) + .getOrDefault(highlightInfo.type.getAttributesKey(), Collections.emptyList()) + .stream() + .filter(filter -> filter.descriptionCheck(highlightInfo.getDescription())) + .allMatch(filter -> filter.accept(highlightedElement)); + + // check if highlight was filtered + if (!acceptHighlight) { + return false; + } - // Handling LazyGetter - if (uninitializedField(description) && LazyGetterHandler.isLazyGetterHandled(highlightedElement)) { + // handle rest cases + String description = highlightInfo.getDescription(); + if (HighlightSeverity.ERROR.equals(highlightInfo.getSeverity())) { + //Handling onX parameters + if (OnXAnnotationHandler.isOnXParameterAnnotation(highlightInfo, file) + || OnXAnnotationHandler.isOnXParameterValue(highlightInfo, file) + || (description != null && LOMBOK_ANY_ANNOTATION_REQUIRED.matcher(description).matches())) { return false; } + } - //Handling onX parameters - return !OnXAnnotationHandler.isOnXParameterAnnotation(highlightInfo, file) - && !OnXAnnotationHandler.isOnXParameterValue(highlightInfo, file) - && !LOMBOK_ANY_ANNOTATION_REQUIRED.matcher(description).matches(); + // register different quick fix for highlight + registeredHooks + .getOrDefault(highlightInfo.getSeverity(), Collections.emptyMap()) + .getOrDefault(highlightInfo.type.getAttributesKey(), Collections.emptyList()) + .stream() + .filter(filter -> filter.descriptionCheck(highlightInfo.getDescription())) + .forEach(filter -> filter.processHook(highlightedElement, highlightInfo)); + + return true; + } + + private enum LombokHighlightFixHook { + + UNHANDLED_EXCEPTION(HighlightSeverity.ERROR, CodeInsightColors.ERRORS_ATTRIBUTES) { + private final Pattern pattern = Pattern.compile("Unhandled exception: .+"); + + @Override + public boolean descriptionCheck(@Nullable String description) { + return description != null && pattern.matcher(description).matches(); + } + + @Override + public void processHook(@NotNull PsiElement highlightedElement, @NotNull HighlightInfo highlightInfo) { + PsiElement importantParent = PsiTreeUtil.getParentOfType(highlightedElement, + PsiMethod.class, PsiLambdaExpression.class, PsiMethodReferenceExpression.class, PsiClassInitializer.class + ); + + // applicable only for methods + if (importantParent instanceof PsiMethod) { + AddAnnotationFix fix = new AddAnnotationFix(SneakyThrows.class.getCanonicalName(), (PsiModifierListOwner) importantParent); + highlightInfo.registerFix(fix, null, null, null, null); + } + } + }; + + private final HighlightSeverity severity; + private final TextAttributesKey key; + + LombokHighlightFixHook(@NotNull HighlightSeverity severity, @Nullable TextAttributesKey key) { + this.severity = severity; + this.key = key; } - // check other exceptions for highlights - Map> severityMap = registeredFilters - .getOrDefault(highlightInfo.getSeverity(), Collections.emptyMap()); + abstract public boolean descriptionCheck(@Nullable String description); - return severityMap.getOrDefault(highlightInfo.type.getAttributesKey(), Collections.emptyList()).stream() - .filter(filter -> filter.descriptionCheck(description)) - .allMatch(filter -> filter.accept(highlightedElement)); + abstract public void processHook(@NotNull PsiElement highlightedElement, @NotNull HighlightInfo highlightInfo); } private enum LombokHighlightFilter { + // ERROR HANDLERS + + VARIABLE_MIGHT_NOT_BEEN_INITIALIZED(HighlightSeverity.ERROR, CodeInsightColors.ERRORS_ATTRIBUTES) { + private final Pattern pattern = Pattern.compile("Variable '.+' might not have been initialized"); + + @Override + public boolean descriptionCheck(@Nullable String description) { + return description != null && pattern.matcher(description).matches(); + } + + @Override + public boolean accept(@NotNull PsiElement highlightedElement) { + return !LazyGetterHandler.isLazyGetterHandled(highlightedElement); + } + }, + + // WARNINGS HANDLERS + VARIABLE_INITIALIZER_IS_REDUNDANT(HighlightSeverity.WARNING, CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES) { private final Pattern pattern = Pattern.compile("Variable '.+' initializer '.+' is redundant"); @@ -130,8 +209,4 @@ public boolean accept(@NotNull PsiElement highlightedElement) { abstract public boolean accept(@NotNull PsiElement highlightedElement); } - - private boolean uninitializedField(String description) { - return UNINITIALIZED_MESSAGE.matcher(description).matches(); - } } diff --git a/src/main/java/de/plushnikov/intellij/plugin/handler/OnXAnnotationHandler.java b/src/main/java/de/plushnikov/intellij/plugin/handler/OnXAnnotationHandler.java index fecdbc811..329fe3a36 100644 --- a/src/main/java/de/plushnikov/intellij/plugin/handler/OnXAnnotationHandler.java +++ b/src/main/java/de/plushnikov/intellij/plugin/handler/OnXAnnotationHandler.java @@ -11,6 +11,15 @@ import java.util.Arrays; import java.util.Collection; import java.util.regex.Pattern; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.With; +import lombok.experimental.Wither; + public class OnXAnnotationHandler { private static final Pattern UNDERSCORES = Pattern.compile("__*"); @@ -21,13 +30,14 @@ public class OnXAnnotationHandler { private static final String CANNOT_FIND_METHOD_VALUE_MESSAGE = "Cannot find method 'value'"; private static final Collection ONXABLE_ANNOTATIONS = Arrays.asList( - "lombok.Getter", - "lombok.Setter", - "lombok.experimental.Wither", - "lombok.NoArgsConstructor", - "lombok.RequiredArgsConstructor", - "lombok.AllArgsConstructor", - "lombok.EqualsAndHashCode" + Getter.class.getCanonicalName(), + Setter.class.getCanonicalName(), + With.class.getCanonicalName(), + Wither.class.getCanonicalName(), + NoArgsConstructor.class.getCanonicalName(), + RequiredArgsConstructor.class.getCanonicalName(), + AllArgsConstructor.class.getCanonicalName(), + EqualsAndHashCode.class.getCanonicalName() ); private static final Collection ONX_PARAMETERS = Arrays.asList( "onConstructor", From 026105848e64c89554b3a3503a15f6ce0a6811f6 Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Sun, 1 Dec 2019 14:05:10 +0100 Subject: [PATCH 10/12] added change log for #394 --- parts/pluginChanges.html | 1 + src/main/resources/messages/lombokBundle.properties | 1 + 2 files changed, 2 insertions(+) diff --git a/parts/pluginChanges.html b/parts/pluginChanges.html index fe6fa45a3..6d108a100 100644 --- a/parts/pluginChanges.html +++ b/parts/pluginChanges.html @@ -1,6 +1,7 @@
    • 0.28
        +
      1. Fixed #394: New feature request: Add SneakyThrows QuickFix, thanks to @Lekanich (Aleksandr Lekanich)
      2. Fixed #440: NPE inspection false positive with lazy getters, thanks to @Lekanich (Aleksandr Lekanich)
      3. Fixed #633: @Builder.Default causes a warning message, thanks to @Lekanich (Aleksandr Lekanich)
      4. Fixed #672: Add support for @CustomLog, thanks to @juriad (Adam Juraszek)
      5. diff --git a/src/main/resources/messages/lombokBundle.properties b/src/main/resources/messages/lombokBundle.properties index 18e3804fa..eb5ecdaa5 100644 --- a/src/main/resources/messages/lombokBundle.properties +++ b/src/main/resources/messages/lombokBundle.properties @@ -22,6 +22,7 @@ daemon.donate.title=Lombok support plugin updated to v{0} daemon.donate.content=
        \ Helpful? Donate with PayPal

        \ Fixes:
        \ +- Fixed (#394): New feature request: Add SneakyThrows QuickFix, thanks to @Lekanich (Aleksandr Lekanich)
        \ - Fixed (#440): NPE inspection false positive with lazy getters, thanks to @Lekanich (Aleksandr Lekanich)
        \ - Fixed (#633): @Builder.Default causes a warning message, thanks to @Lekanich (Aleksandr Lekanich)
        \ - Fixed (#672): Add support for @CustomLog, thanks to @juriad (Adam Juraszek)
        \ From cbed3371ebf9ffde9ebc21f01a2598567c9db8ff Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Sun, 1 Dec 2019 14:54:50 +0100 Subject: [PATCH 11/12] added test for QuickFix registration #394 --- .../extension/LombokHighlightErrorFilter.java | 35 ++++++++++--------- .../SneakyThrowsExceptionAddQuickFixTest.java | 33 +++++++++++++++++ .../CheckedExeptionQuickFixExample.java | 14 ++++++++ 3 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 src/test/java/de/plushnikov/intellij/plugin/extension/SneakyThrowsExceptionAddQuickFixTest.java create mode 100644 testData/extension/CheckedExeptionQuickFixExample.java diff --git a/src/main/java/de/plushnikov/intellij/plugin/extension/LombokHighlightErrorFilter.java b/src/main/java/de/plushnikov/intellij/plugin/extension/LombokHighlightErrorFilter.java index 154c4d91e..e47132229 100644 --- a/src/main/java/de/plushnikov/intellij/plugin/extension/LombokHighlightErrorFilter.java +++ b/src/main/java/de/plushnikov/intellij/plugin/extension/LombokHighlightErrorFilter.java @@ -1,11 +1,5 @@ package de.plushnikov.intellij.plugin.extension; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.daemon.impl.HighlightInfoFilter; import com.intellij.codeInsight.intention.AddAnnotationFix; @@ -20,13 +14,20 @@ import com.intellij.psi.PsiMethodReferenceExpression; import com.intellij.psi.PsiModifierListOwner; import com.intellij.psi.util.PsiTreeUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import lombok.SneakyThrows; import de.plushnikov.intellij.plugin.handler.BuilderHandler; import de.plushnikov.intellij.plugin.handler.EqualsAndHashCodeCallSuperHandler; import de.plushnikov.intellij.plugin.handler.LazyGetterHandler; import de.plushnikov.intellij.plugin.handler.OnXAnnotationHandler; +import lombok.SneakyThrows; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; public class LombokHighlightErrorFilter implements HighlightInfoFilter { @@ -39,16 +40,16 @@ public LombokHighlightErrorFilter() { registeredFilters = new HashMap<>(); registeredHooks = new HashMap<>(); - for (LombokHighlightFilter value : LombokHighlightFilter.values()) { - registeredFilters.computeIfAbsent(value.severity, s -> new HashMap<>()) - .computeIfAbsent(value.key, k -> new ArrayList<>()) - .add(value); + for (LombokHighlightFilter highlightFilter : LombokHighlightFilter.values()) { + registeredFilters.computeIfAbsent(highlightFilter.severity, s -> new HashMap<>()) + .computeIfAbsent(highlightFilter.key, k -> new ArrayList<>()) + .add(highlightFilter); } - for (LombokHighlightFixHook value : LombokHighlightFixHook.values()) { - registeredHooks.computeIfAbsent(value.severity, s -> new HashMap<>()) - .computeIfAbsent(value.key, k -> new ArrayList<>()) - .add(value); + for (LombokHighlightFixHook highlightFixHook : LombokHighlightFixHook.values()) { + registeredHooks.computeIfAbsent(highlightFixHook.severity, s -> new HashMap<>()) + .computeIfAbsent(highlightFixHook.key, k -> new ArrayList<>()) + .add(highlightFixHook); } } diff --git a/src/test/java/de/plushnikov/intellij/plugin/extension/SneakyThrowsExceptionAddQuickFixTest.java b/src/test/java/de/plushnikov/intellij/plugin/extension/SneakyThrowsExceptionAddQuickFixTest.java new file mode 100644 index 000000000..46351387d --- /dev/null +++ b/src/test/java/de/plushnikov/intellij/plugin/extension/SneakyThrowsExceptionAddQuickFixTest.java @@ -0,0 +1,33 @@ +package de.plushnikov.intellij.plugin.extension; + +import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.openapi.editor.Editor; +import com.intellij.psi.PsiFile; +import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; +import de.plushnikov.intellij.plugin.AbstractLombokLightCodeInsightTestCase; + +import java.util.List; + +public class SneakyThrowsExceptionAddQuickFixTest extends AbstractLombokLightCodeInsightTestCase { + + @Override + protected String getBasePath() { + return super.getBasePath() + "/extension"; + } + + public void testCheckedExeptionQuickFixExample() { + myFixture.configureByFile(getBasePath() + '/' + getTestName(false) + ".java"); + + final List availableActions = getAvailableActions(); + assertTrue("Intention to add @SneakyThrows was not presented", + availableActions.stream().anyMatch(action -> action.getText().contains("@SneakyThrows"))); + } + + protected List getAvailableActions() { + final Editor editor = getEditor(); + final PsiFile file = getFile(); + CodeInsightTestFixtureImpl.instantiateAndRun(file, editor, new int[0], false); + return CodeInsightTestFixtureImpl.getAvailableIntentions(editor, file); + } + +} diff --git a/testData/extension/CheckedExeptionQuickFixExample.java b/testData/extension/CheckedExeptionQuickFixExample.java new file mode 100644 index 000000000..152c27dde --- /dev/null +++ b/testData/extension/CheckedExeptionQuickFixExample.java @@ -0,0 +1,14 @@ +package extension; + +import java.io.IOException; + +public class CheckedExeptionQuickFixExample { + + public int calcSomething() { + throw new IOException(); + } + + public static void main(String[] args) { + System.out.println(new CheckedExeptionQuickFixExample().calcSomething()); + } +} From a7941dc9c40dd7ab97926645ba1fcb2e7796b803 Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Sun, 1 Dec 2019 19:08:37 +0100 Subject: [PATCH 12/12] updated manual test classes --- .../bug/issue634/LinkedListImpl.java | 15 ++++++++---- .../java/de/plushnikov/bug/issue634/Node.java | 19 +++++++-------- .../plushnikov/bug/issue634/SomeBoxClass.java | 23 +++++++++++++++++++ 3 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 test-manual/src/main/java/de/plushnikov/bug/issue634/SomeBoxClass.java diff --git a/test-manual/src/main/java/de/plushnikov/bug/issue634/LinkedListImpl.java b/test-manual/src/main/java/de/plushnikov/bug/issue634/LinkedListImpl.java index b332087a8..b929b6819 100644 --- a/test-manual/src/main/java/de/plushnikov/bug/issue634/LinkedListImpl.java +++ b/test-manual/src/main/java/de/plushnikov/bug/issue634/LinkedListImpl.java @@ -1,10 +1,15 @@ package de.plushnikov.bug.issue634; +import lombok.Builder; + +@Builder public class LinkedListImpl { - private Node first; - private Node last; - public void add(Object o) { - Node node = new Node(o, first); - } + private Node first; + private Node.NodeBuilder last; + + public void add(Node o1) { + Node node = new Node(o1, last); + } + } diff --git a/test-manual/src/main/java/de/plushnikov/bug/issue634/Node.java b/test-manual/src/main/java/de/plushnikov/bug/issue634/Node.java index 9b33af21b..0783e22c9 100644 --- a/test-manual/src/main/java/de/plushnikov/bug/issue634/Node.java +++ b/test-manual/src/main/java/de/plushnikov/bug/issue634/Node.java @@ -1,16 +1,17 @@ package de.plushnikov.bug.issue634; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; +import lombok.*; @Getter -@AllArgsConstructor @RequiredArgsConstructor -public class Node { - @Setter - private Node next; +@AllArgsConstructor +@Builder +class Node { - private final Object element; + @Setter + @NonNull + private NodeBuilder next; + @NonNull + @Getter + private final Node element; } diff --git a/test-manual/src/main/java/de/plushnikov/bug/issue634/SomeBoxClass.java b/test-manual/src/main/java/de/plushnikov/bug/issue634/SomeBoxClass.java new file mode 100644 index 000000000..1ef6e22e5 --- /dev/null +++ b/test-manual/src/main/java/de/plushnikov/bug/issue634/SomeBoxClass.java @@ -0,0 +1,23 @@ +package de.plushnikov.bug.issue634; + +import lombok.Builder; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; + +@Builder +@Getter +@Setter +public class SomeBoxClass { + + private Node.NodeBuilder intField; + + @NonNull + private String someString; + + @NonNull + private Node node; + + @NonNull + private LinkedListImpl someImpl; +}