Skip to content

Commit

Permalink
Merge pull request #2155 from brychcy/master
Browse files Browse the repository at this point in the history
Avoid Eclipse warnings about lombok.NonNull when NonNullByDefault is used
  • Loading branch information
rzwitserloot committed Jul 8, 2019
2 parents 1c65efa + 8a6603d commit 93540b2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public String mapResourceName(int classFileFormatVersion, String resourceName) {
patchEcjTransformers(sm, ecjOnly);
patchExtensionMethod(sm, ecjOnly);
patchRenameField(sm);
patchNullCheck(sm);

if (reloadExistingClasses) sm.reloadClasses(instrumentation);
}
Expand Down Expand Up @@ -774,4 +775,24 @@ private static void patchExtensionMethod(ScriptManager sm, boolean ecj) {
.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());
}

}
12 changes: 11 additions & 1 deletion src/eclipseAgent/lombok/launch/PatchFixesHider.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,17 @@ public static boolean isGenerated(org.eclipse.jdt.core.dom.ASTNode node) {
}
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());
}
Expand Down

0 comments on commit 93540b2

Please sign in to comment.