aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-07-09 00:30:10 +0200
committerGitHub <noreply@github.com>2019-07-09 00:30:10 +0200
commit93540b267dd9026a7e80b347087a7eae0f0b1c4d (patch)
tree3ac3cbe39221bcc0995b1e23ad2e7f8439ebc174
parent1c65efa7d97795b2e70d2736c9d28963fc6802c6 (diff)
parent8a6603d191f7b8d1f27d32f3b2fa25d1c2eb8e53 (diff)
downloadlombok-93540b267dd9026a7e80b347087a7eae0f0b1c4d.tar.gz
lombok-93540b267dd9026a7e80b347087a7eae0f0b1c4d.tar.bz2
lombok-93540b267dd9026a7e80b347087a7eae0f0b1c4d.zip
Merge pull request #2155 from brychcy/master
Avoid Eclipse warnings about lombok.NonNull when NonNullByDefault is used
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java21
-rwxr-xr-xsrc/eclipseAgent/lombok/launch/PatchFixesHider.java12
2 files changed, 32 insertions, 1 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
index 0e74dfaf..24c1216e 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
@@ -122,6 +122,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
patchEcjTransformers(sm, ecjOnly);
patchExtensionMethod(sm, ecjOnly);
patchRenameField(sm);
+ patchNullCheck(sm);
if (reloadExistingClasses) sm.reloadClasses(instrumentation);
}
@@ -774,4 +775,24 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
.build());
}
}
+
+ private static void patchNullCheck(ScriptManager sm) {
+ /* Avoid warnings caused by the null check generated for lombok.NonNull if NonNullByDefault is used. */
+
+ /* Avoid "Redundant null check: comparing '@NonNull String' against null" */
+ sm.addScript(ScriptBuilder.exitEarly()
+ .target(new MethodTarget("org.eclipse.jdt.internal.compiler.problem.ProblemReporter", "expressionNonNullComparison", "boolean", "org.eclipse.jdt.internal.compiler.ast.Expression", "boolean"))
+ .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.internal.compiler.ast.ASTNode"))
+ .valueMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "returnTrue", "boolean", "java.lang.Object"))
+ .request(StackRequest.PARAM1)
+ .transplant().build());
+
+ /* Avoid "Dead code" */
+ sm.addScript(ScriptBuilder.exitEarly()
+ .target(new MethodTarget("org.eclipse.jdt.internal.compiler.problem.ProblemReporter", "fakeReachable", "void", "org.eclipse.jdt.internal.compiler.ast.ASTNode"))
+ .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.internal.compiler.ast.ASTNode"))
+ .request(StackRequest.PARAM1)
+ .transplant().build());
+ }
+
}
diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
index 3741aba8..563beab1 100755
--- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java
+++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
@@ -315,7 +315,17 @@ final class PatchFixesHider {
}
return result;
}
-
+
+ public static boolean isGenerated(org.eclipse.jdt.internal.compiler.ast.ASTNode node) {
+ boolean result = false;
+ try {
+ result = node.getClass().getField("$generatedBy").get(node) != null;
+ } catch (Exception e) {
+ // better to assume it isn't generated
+ }
+ return result;
+ }
+
public static boolean isListRewriteOnGeneratedNode(org.eclipse.jdt.core.dom.rewrite.ListRewrite rewrite) {
return isGenerated(rewrite.getParent());
}