aboutsummaryrefslogtreecommitdiff
path: root/src/utils/lombok/javac/CommentCatcher.java
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2014-06-05 23:45:43 +0200
committerRoel Spilker <r.spilker@gmail.com>2014-06-05 23:45:43 +0200
commit1ce747178b8f24f29f94dd795f09f872aad9272f (patch)
tree76e66d528c56f22ac5782846df4758d75a8b55bd /src/utils/lombok/javac/CommentCatcher.java
parentf30485c91fd3f9553fbcbc02d922e6221182c26e (diff)
downloadlombok-1ce747178b8f24f29f94dd795f09f872aad9272f.tar.gz
lombok-1ce747178b8f24f29f94dd795f09f872aad9272f.tar.bz2
lombok-1ce747178b8f24f29f94dd795f09f872aad9272f.zip
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.
Diffstat (limited to 'src/utils/lombok/javac/CommentCatcher.java')
-rw-r--r--src/utils/lombok/javac/CommentCatcher.java22
1 files changed, 10 insertions, 12 deletions
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<JCCompilationUnit, List<CommentInfo>> commentsField;
+ public static final FieldAugment<JCCompilationUnit, List<CommentInfo>> JCCompilationUnit_comments = FieldAugment.augment(JCCompilationUnit.class, List.class, "lombok$comments");
public static CommentCatcher create(Context context) {
registerCommentsCollectingScannerFactory(context);
JavaCompiler compiler = new JavaCompiler(context);
- ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> 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<JCCompilationUnit, List<CommentInfo>> 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<CommentInfo> comments) {
if (comments != null) {
- commentsField.set(ast, comments);
+ JCCompilationUnit_comments.set(ast, comments);
} else {
- commentsField.clear(ast);
+ JCCompilationUnit_comments.clear(ast);
}
}
public List<CommentInfo> getComments(JCCompilationUnit ast) {
- List<CommentInfo> list = commentsField.get(ast);
+ List<CommentInfo> list = JCCompilationUnit_comments.get(ast);
return list == null ? Collections.<CommentInfo>emptyList() : list;
}
@@ -89,7 +87,7 @@ public class CommentCatcher {
}
}
- private static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> 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) {