Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid Eclipse warnings about lombok.NonNull when NonNullByDefault is used #2155

Merged
merged 1 commit into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
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
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