mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 06:15:41 +00:00
Avoid Eclipse warnings about null checks generated for lombok.NonNull when NonNullByDefault is used
This commit is contained in:
1 parent
d9b8b14575
commit
8a6603d191
2 files changed
+32
-1
No files matched your search
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user