From 04e9397971d3689e0710df026f673f8b0a6cb685 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 18 Mar 2011 19:30:02 +0100 Subject: Rewritten @Cleanup's new null analysis prevention to not use Lombok.preventNullAnalysis but go with Collections.singletonList(expr).get(0) instead; while this does create a pointless object, it doesn't cause a clash when eclipse has lombok 0.10 installed but the project uses 0.9, which doesn't have preventNullAnalysis. Eventually, once 0.9 is long forgotten, this can be reverted. --- src/core/lombok/javac/handlers/HandleCleanup.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/core/lombok/javac/handlers') diff --git a/src/core/lombok/javac/handlers/HandleCleanup.java b/src/core/lombok/javac/handlers/HandleCleanup.java index 9e2fddf6..b681ab28 100644 --- a/src/core/lombok/javac/handlers/HandleCleanup.java +++ b/src/core/lombok/javac/handlers/HandleCleanup.java @@ -117,7 +117,7 @@ public class HandleCleanup implements JavacAnnotationHandler { List cleanupCall = List.of(maker.Exec( maker.Apply(List.nil(), cleanupMethod, List.nil()))); - JCMethodInvocation preventNullAnalysis = maker.Apply(List.nil(), JavacHandlerUtil.chainDotsString(maker, annotationNode, "lombok.Lombok.preventNullAnalysis"), List.of(maker.Ident(decl.name))); + JCMethodInvocation preventNullAnalysis = preventNullAnalysis(maker, annotationNode, maker.Ident(decl.name)); JCBinary isNull = maker.Binary(Javac.getCTCint(JCTree.class, "NE"), preventNullAnalysis, maker.Literal(Javac.getCTCint(TypeTags.class, "BOT"), null)); JCIf ifNotNullCleanup = maker.If(isNull, maker.Block(0, cleanupCall), null); @@ -139,6 +139,12 @@ public class HandleCleanup implements JavacAnnotationHandler { return true; } + private JCMethodInvocation preventNullAnalysis(TreeMaker maker, JavacNode node, JCExpression expression) { + JCMethodInvocation singletonList = maker.Apply(List.nil(), JavacHandlerUtil.chainDotsString(maker, node, "java.util.Collections.singletonList"), List.of(expression)); + JCMethodInvocation cleanedExpr = maker.Apply(List.nil(), maker.Select(singletonList, node.toName("get")) , List.of(maker.Literal(TypeTags.INT, 0))); + return cleanedExpr; + } + private void doAssignmentCheck(JavacNode node, List statements, Name name) { for (JCStatement statement : statements) doAssignmentCheck0(node, statement, name); } -- cgit