From 1ce747178b8f24f29f94dd795f09f872aad9272f Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Thu, 5 Jun 2014 23:45:43 +0200 Subject: Finished refactor of FieldAugment; there's no longer a separate variant for boolean and references, and the code no longer blows up with a bunch of NPEs if you try to use the reference variant (which is now the only variant) with a primitive type. Should have zero effect on features or bugs, 100% refactor. --- src/utils/lombok/javac/CommentCatcher.java | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/utils/lombok/javac/CommentCatcher.java') diff --git a/src/utils/lombok/javac/CommentCatcher.java b/src/utils/lombok/javac/CommentCatcher.java index ff6be7a2..c32da68b 100644 --- a/src/utils/lombok/javac/CommentCatcher.java +++ b/src/utils/lombok/javac/CommentCatcher.java @@ -25,7 +25,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.Collections; import java.util.List; -import lombok.core.ReferenceFieldAugment; +import lombok.core.FieldAugment; import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; @@ -33,24 +33,22 @@ import com.sun.tools.javac.util.Context; public class CommentCatcher { private final JavaCompiler compiler; - private final ReferenceFieldAugment> commentsField; + public static final FieldAugment> JCCompilationUnit_comments = FieldAugment.augment(JCCompilationUnit.class, List.class, "lombok$comments"); public static CommentCatcher create(Context context) { registerCommentsCollectingScannerFactory(context); JavaCompiler compiler = new JavaCompiler(context); - ReferenceFieldAugment> comments = ReferenceFieldAugment.augment(JCCompilationUnit.class, List.class, "lombok$comments"); - setInCompiler(compiler, context, comments); + setInCompiler(compiler, context); compiler.keepComments = true; compiler.genEndPos = true; - return new CommentCatcher(compiler, comments); + return new CommentCatcher(compiler); } - private CommentCatcher(JavaCompiler compiler, ReferenceFieldAugment> commentsField) { + private CommentCatcher(JavaCompiler compiler) { this.compiler = compiler; - this.commentsField = commentsField; } public JavaCompiler getCompiler() { @@ -59,14 +57,14 @@ public class CommentCatcher { public void setComments(JCCompilationUnit ast, List comments) { if (comments != null) { - commentsField.set(ast, comments); + JCCompilationUnit_comments.set(ast, comments); } else { - commentsField.clear(ast); + JCCompilationUnit_comments.clear(ast); } } public List getComments(JCCompilationUnit ast) { - List list = commentsField.get(ast); + List list = JCCompilationUnit_comments.get(ast); return list == null ? Collections.emptyList() : list; } @@ -89,7 +87,7 @@ public class CommentCatcher { } } - private static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment> commentsField) { + private static void setInCompiler(JavaCompiler compiler, Context context) { try { Class parserFactory; int javaCompilerVersion = Javac.getJavaCompilerVersion(); @@ -100,7 +98,7 @@ public class CommentCatcher { } else { parserFactory = Class.forName("lombok.javac.java8.CommentCollectingParserFactory"); } - parserFactory.getMethod("setInCompiler", JavaCompiler.class, Context.class, ReferenceFieldAugment.class).invoke(null, compiler, context, commentsField); + parserFactory.getMethod("setInCompiler", JavaCompiler.class, Context.class).invoke(null, compiler, context); } catch (InvocationTargetException e) { throw Javac.sneakyThrow(e.getCause()); } catch (Exception e) { -- cgit