aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/javac
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-10-18 17:48:27 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-10-18 17:48:27 +0200
commit17c8f5a0196f5b56361241147e6bcf19eeb2d2ce (patch)
tree77bcb1d38f94569fd622c19a5f9701435f24aa36 /src/lombok/javac
parent4da08ce3ccdd94f48856bd77b3dff50a77c150b1 (diff)
downloadlombok-17c8f5a0196f5b56361241147e6bcf19eeb2d2ce.tar.gz
lombok-17c8f5a0196f5b56361241147e6bcf19eeb2d2ce.tar.bz2
lombok-17c8f5a0196f5b56361241147e6bcf19eeb2d2ce.zip
Added the ability to get the Context object via JavacAST, useful for various things, and specifically requested by David McCullars, who is working on rolling their own lombok extensions.
See: http://groups.google.com/group/project-lombok/browse_thread/thread/a73972d4011a3e21
Diffstat (limited to 'src/lombok/javac')
-rw-r--r--src/lombok/javac/JavacAST.java23
-rw-r--r--src/lombok/javac/JavacNode.java10
-rw-r--r--src/lombok/javac/apt/Processor.java3
3 files changed, 27 insertions, 9 deletions
diff --git a/src/lombok/javac/JavacAST.java b/src/lombok/javac/JavacAST.java
index 77e365ee..f2c83fb8 100644
--- a/src/lombok/javac/JavacAST.java
+++ b/src/lombok/javac/JavacAST.java
@@ -34,7 +34,6 @@ import lombok.core.AST;
import com.sun.source.util.Trees;
import com.sun.tools.javac.code.Symtab;
-import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
@@ -47,6 +46,7 @@ import com.sun.tools.javac.tree.JCTree.JCImport;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCStatement;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
+import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
@@ -61,23 +61,30 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
private final TreeMaker treeMaker;
private final Symtab symtab;
private final Log log;
+ private final Context context;
/**
* Creates a new JavacAST of the provided Compilation Unit.
*
* @param trees The trees instance to use to inspect the compilation unit. Generate via:
* {@code Trees.getInstance(env)}
- * @param env The ProcessingEnvironment object passed e.g. to an annotation processor.
+ * @param messager A Messager for warning and error reporting.
+ * @param context A Context object for interfacing with the compiler.
* @param top The compilation unit, which serves as the top level node in the tree to be built.
*/
- public JavacAST(Trees trees, JavacProcessingEnvironment env, JCCompilationUnit top) {
+ public JavacAST(Trees trees, Messager messager, Context context, JCCompilationUnit top) {
super(top.sourcefile == null ? null : top.sourcefile.toString());
setTop(buildCompilationUnit(top));
- this.messager = env.getMessager();
- this.log = Log.instance(env.getContext());
- this.nameTable = Name.Table.instance(env.getContext());
- this.treeMaker = TreeMaker.instance(env.getContext());
- this.symtab = Symtab.instance(env.getContext());
+ this.context = context;
+ this.messager = messager;
+ this.log = Log.instance(context);
+ this.nameTable = Name.Table.instance(context);
+ this.treeMaker = TreeMaker.instance(context);
+ this.symtab = Symtab.instance(context);
+ }
+
+ public Context getContext() {
+ return context;
}
/** {@inheritDoc} */
diff --git a/src/lombok/javac/JavacNode.java b/src/lombok/javac/JavacNode.java
index 46e06579..a0ee2789 100644
--- a/src/lombok/javac/JavacNode.java
+++ b/src/lombok/javac/JavacNode.java
@@ -36,6 +36,7 @@ import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
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.JCDiagnostic.DiagnosticPosition;
@@ -164,6 +165,15 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre
}
/**
+ * Convenient shortcut to the owning JavacAST object's getContext method.
+ *
+ * @see JavacAST#getContext()
+ */
+ public Context getContext() {
+ return ast.getContext();
+ }
+
+ /**
* Convenient shortcut to the owning JavacAST object's toName method.
*
* @see JavacAST#toName(String)
diff --git a/src/lombok/javac/apt/Processor.java b/src/lombok/javac/apt/Processor.java
index 9f3951bb..1ff1ee88 100644
--- a/src/lombok/javac/apt/Processor.java
+++ b/src/lombok/javac/apt/Processor.java
@@ -93,7 +93,8 @@ public class Processor extends AbstractProcessor {
List<JavacAST> asts = new ArrayList<JavacAST>();
- for (JCCompilationUnit unit : units.keySet()) asts.add(new JavacAST(trees, processingEnv, unit));
+ for (JCCompilationUnit unit : units.keySet()) asts.add(
+ new JavacAST(trees, processingEnv.getMessager(), processingEnv.getContext(), unit));
handlers.skipPrintAST();
for (JavacAST ast : asts) {