aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2011-11-21 23:53:00 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2011-11-21 23:53:00 +0100
commite24ac22aaa286cb91a0dcdbff1f95d09fb62f8ef (patch)
tree5bc8791be6f63268a959d4313ec383830aba3aa1 /src/core/lombok
parent3fd3ca32a68c728bebd04d41720f2d1f636a3695 (diff)
downloadlombok-e24ac22aaa286cb91a0dcdbff1f95d09fb62f8ef.tar.gz
lombok-e24ac22aaa286cb91a0dcdbff1f95d09fb62f8ef.tar.bz2
lombok-e24ac22aaa286cb91a0dcdbff1f95d09fb62f8ef.zip
Made an API for creating a (oracle javac) JavaCompiler which tracks comments on a per Compilation Unit basis. The old way involved making reflective calls and detecting whether you need the 1.6 or the 1.7 variant to do this. These shenanigans are now hidden behind a nice API (lombok.javac.CommentCatcher).
Diffstat (limited to 'src/core/lombok')
-rw-r--r--src/core/lombok/javac/JavacNode.java4
-rw-r--r--src/core/lombok/javac/JavacTransformer.java6
-rw-r--r--src/core/lombok/javac/LombokOptions.java19
3 files changed, 18 insertions, 11 deletions
diff --git a/src/core/lombok/javac/JavacNode.java b/src/core/lombok/javac/JavacNode.java
index 5b4782e8..b478781b 100644
--- a/src/core/lombok/javac/JavacNode.java
+++ b/src/core/lombok/javac/JavacNode.java
@@ -39,7 +39,6 @@ import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Name;
-import com.sun.tools.javac.util.Options;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
/**
@@ -198,8 +197,7 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre
}
public boolean shouldDeleteLombokAnnotations() {
- Options options = ast.getContext().get(Options.optionsKey);
- return options instanceof LombokOptions && ((LombokOptions)options).deleteLombokAnnotations;
+ return LombokOptions.shouldDeleteLombokAnnotations(ast.getContext());
}
/**
diff --git a/src/core/lombok/javac/JavacTransformer.java b/src/core/lombok/javac/JavacTransformer.java
index f8a738a2..3afdee0a 100644
--- a/src/core/lombok/javac/JavacTransformer.java
+++ b/src/core/lombok/javac/JavacTransformer.java
@@ -33,7 +33,6 @@ import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.List;
-import com.sun.tools.javac.util.Options;
public class JavacTransformer {
private final HandlerLibrary handlers;
@@ -80,10 +79,7 @@ public class JavacTransformer {
}
}
- Options options = context.get(Options.optionsKey);
- if (options instanceof LombokOptions) for (JavacAST ast : asts) {
- if (ast.isChanged()) ((LombokOptions)options).changed.add((JCCompilationUnit) ast.top().get());
- }
+ for (JavacAST ast : asts) if (ast.isChanged()) LombokOptions.markChanged(context, (JCCompilationUnit) ast.top().get());
}
private class AnnotationVisitor extends JavacASTAdapter {
diff --git a/src/core/lombok/javac/LombokOptions.java b/src/core/lombok/javac/LombokOptions.java
index c0c92df8..1a73a8cc 100644
--- a/src/core/lombok/javac/LombokOptions.java
+++ b/src/core/lombok/javac/LombokOptions.java
@@ -29,10 +29,9 @@ import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Options;
public class LombokOptions extends Options {
+ private boolean deleteLombokAnnotations = true;
+ private final Set<JCCompilationUnit> changed = new HashSet<JCCompilationUnit>();
- public boolean deleteLombokAnnotations = true;
- public final Set<JCCompilationUnit> changed = new HashSet<JCCompilationUnit>();
-
public static LombokOptions replaceWithDelombokOptions(Context context) {
Options options = Options.instance(context);
context.put(optionsKey, (Options)null);
@@ -41,6 +40,20 @@ public class LombokOptions extends Options {
return result;
}
+ public boolean isChanged(JCCompilationUnit ast) {
+ return changed.contains(ast);
+ }
+
+ public static void markChanged(Context context, JCCompilationUnit ast) {
+ Options options = context.get(Options.optionsKey);
+ if (options instanceof LombokOptions) ((LombokOptions) options).changed.add(ast);
+ }
+
+ public static boolean shouldDeleteLombokAnnotations(Context context) {
+ Options options = context.get(Options.optionsKey);
+ return (options instanceof LombokOptions) && ((LombokOptions) options).deleteLombokAnnotations;
+ }
+
private LombokOptions(Context context) {
super(context);
}