aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lombok')
-rw-r--r--src/core/lombok/Delegate.java26
-rw-r--r--src/core/lombok/eclipse/handlers/HandleVal.java2
-rw-r--r--src/core/lombok/javac/HandlerLibrary.java39
-rw-r--r--src/core/lombok/javac/JavacAnnotationHandler.java5
-rw-r--r--src/core/lombok/javac/JavacResolution.java1
-rw-r--r--src/core/lombok/javac/JavacTransformer.java34
-rw-r--r--src/core/lombok/javac/apt/Processor.java3
-rw-r--r--src/core/lombok/javac/handlers/HandleCleanup.java4
-rw-r--r--src/core/lombok/javac/handlers/HandleConstructor.java12
-rw-r--r--src/core/lombok/javac/handlers/HandleData.java4
-rw-r--r--src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java4
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java4
-rw-r--r--src/core/lombok/javac/handlers/HandleLog.java18
-rw-r--r--src/core/lombok/javac/handlers/HandlePrintAST.java4
-rw-r--r--src/core/lombok/javac/handlers/HandleSetter.java4
-rw-r--r--src/core/lombok/javac/handlers/HandleSneakyThrows.java4
-rw-r--r--src/core/lombok/javac/handlers/HandleSynchronized.java4
-rw-r--r--src/core/lombok/javac/handlers/HandleToString.java4
-rw-r--r--src/core/lombok/javac/handlers/HandleVal.java4
19 files changed, 152 insertions, 28 deletions
diff --git a/src/core/lombok/Delegate.java b/src/core/lombok/Delegate.java
new file mode 100644
index 00000000..0bbaed0d
--- /dev/null
+++ b/src/core/lombok/Delegate.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright © 2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package lombok;
+
+public @interface Delegate {
+ Class<?> value() default java.lang.Object.class;
+}
diff --git a/src/core/lombok/eclipse/handlers/HandleVal.java b/src/core/lombok/eclipse/handlers/HandleVal.java
index b3cfa879..7f4f36fb 100644
--- a/src/core/lombok/eclipse/handlers/HandleVal.java
+++ b/src/core/lombok/eclipse/handlers/HandleVal.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2009-2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans.
+ * Copyright © 2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
diff --git a/src/core/lombok/javac/HandlerLibrary.java b/src/core/lombok/javac/HandlerLibrary.java
index 5b792874..8eb7be9f 100644
--- a/src/core/lombok/javac/HandlerLibrary.java
+++ b/src/core/lombok/javac/HandlerLibrary.java
@@ -51,7 +51,7 @@ public class HandlerLibrary {
private final Map<String, AnnotationHandlerContainer<?>> annotationHandlers = new HashMap<String, AnnotationHandlerContainer<?>>();
private final Collection<JavacASTVisitor> visitorHandlers = new ArrayList<JavacASTVisitor>();
private final Messager messager;
- private boolean skipPrintAST = true;
+ private int phase = 0;
/**
* Creates a new HandlerLibrary that will report any problems or errors to the provided messager.
@@ -70,6 +70,10 @@ public class HandlerLibrary {
this.annotationClass = annotationClass;
}
+ public boolean isResolutionBased() {
+ return handler.isResolutionBased();
+ }
+
public boolean handle(final JavacNode node) {
return handler.handle(Javac.createAnnotation(annotationClass, node), (JCAnnotation)node.get(), node);
}
@@ -160,12 +164,14 @@ public class HandlerLibrary {
boolean handled = false;
for (String fqn : resolver.findTypeMatches(node, rawType)) {
boolean isPrintAST = fqn.equals(PrintAST.class.getName());
- if (isPrintAST == skipPrintAST) continue;
+ if (isPrintAST && phase != 2) continue;
+ if (!isPrintAST && phase == 2) continue;
AnnotationHandlerContainer<?> container = annotationHandlers.get(fqn);
if (container == null) continue;
try {
- handled |= container.handle(node);
+ if (container.isResolutionBased() && phase == 1) handled |= container.handle(node);
+ if (!container.isResolutionBased() && phase == 0) handled |= container.handle(node);
} catch (AnnotationValueDecodeFail fail) {
fail.owner.setError(fail.getMessage(), fail.idx);
} catch (Throwable t) {
@@ -183,13 +189,8 @@ public class HandlerLibrary {
*/
public void callASTVisitors(JavacAST ast) {
for (JavacASTVisitor visitor : visitorHandlers) try {
- if (!visitor.isResolutionBased()) ast.traverse(visitor);
- } catch (Throwable t) {
- javacError(String.format("Lombok visitor handler %s failed", visitor.getClass()), t);
- }
-
- for (JavacASTVisitor visitor : visitorHandlers) try {
- if (visitor.isResolutionBased()) ast.traverse(visitor);
+ if (!visitor.isResolutionBased() && phase == 0) ast.traverse(visitor);
+ if (visitor.isResolutionBased() && phase == 1) ast.traverse(visitor);
} catch (Throwable t) {
javacError(String.format("Lombok visitor handler %s failed", visitor.getClass()), t);
}
@@ -197,17 +198,17 @@ public class HandlerLibrary {
/**
* Lombok does not currently support triggering annotations in a specified order; the order is essentially
- * random right now. This lack of order is particularly annoying for the {@code PrintAST} annotation,
- * which is almost always intended to run last. Hence, this hack, which lets it in fact run last.
- *
- * @see #skipAllButPrintAST()
+ * random right now. As a temporary hack we've identified 3 important phases.
*/
- public void skipPrintAST() {
- skipPrintAST = true;
+ public void setPreResolutionPhase() {
+ phase = 0;
+ }
+
+ public void setPostResolutionPhase() {
+ phase = 1;
}
- /** @see #skipPrintAST() */
- public void skipAllButPrintAST() {
- skipPrintAST = false;
+ public void setPrintASTPhase() {
+ phase = 2;
}
}
diff --git a/src/core/lombok/javac/JavacAnnotationHandler.java b/src/core/lombok/javac/JavacAnnotationHandler.java
index 5b6fe4ce..ee330ecb 100644
--- a/src/core/lombok/javac/JavacAnnotationHandler.java
+++ b/src/core/lombok/javac/JavacAnnotationHandler.java
@@ -55,4 +55,9 @@ public interface JavacAnnotationHandler<T extends Annotation> {
* compile session (you've handled it), or {@code false} to indicate you aren't done yet.
*/
boolean handle(AnnotationValues<T> annotation, JCAnnotation ast, JavacNode annotationNode);
+
+ /**
+ * Return true if this handler requires resolution.
+ */
+ boolean isResolutionBased();
}
diff --git a/src/core/lombok/javac/JavacResolution.java b/src/core/lombok/javac/JavacResolution.java
index e0eb436d..26ff34d0 100644
--- a/src/core/lombok/javac/JavacResolution.java
+++ b/src/core/lombok/javac/JavacResolution.java
@@ -11,6 +11,7 @@ import javax.lang.model.type.TypeKind;
import javax.tools.DiagnosticListener;
import com.sun.tools.javac.code.BoundKind;
+import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.TypeSymbol;
import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.code.Type.ArrayType;
diff --git a/src/core/lombok/javac/JavacTransformer.java b/src/core/lombok/javac/JavacTransformer.java
index 5f145460..c703b1c7 100644
--- a/src/core/lombok/javac/JavacTransformer.java
+++ b/src/core/lombok/javac/JavacTransformer.java
@@ -22,16 +22,18 @@
package lombok.javac;
import java.util.ArrayList;
-import java.util.List;
import javax.annotation.processing.Messager;
+import com.sun.tools.javac.comp.Enter;
+import com.sun.tools.javac.comp.MemberEnter;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
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.List;
public class JavacTransformer {
private final HandlerLibrary handlers;
@@ -42,18 +44,39 @@ public class JavacTransformer {
this.handlers = HandlerLibrary.load(messager);
}
- public boolean transform(Context context, Iterable<JCCompilationUnit> compilationUnits) {
- List<JavacAST> asts = new ArrayList<JavacAST>();
+ public boolean transform(Context context, java.util.List<JCCompilationUnit> compilationUnitsRaw) {
+ List<JCCompilationUnit> compilationUnits;
+ if (compilationUnitsRaw instanceof List<?>) {
+ compilationUnits = (List<JCCompilationUnit>)compilationUnitsRaw;
+ } else {
+ compilationUnits = List.nil();
+ for (int i = compilationUnitsRaw.size() -1; i >= 0; i--) {
+ compilationUnits = compilationUnits.prepend(compilationUnitsRaw.get(i));
+ }
+ }
+
+ java.util.List<JavacAST> asts = new ArrayList<JavacAST>();
for (JCCompilationUnit unit : compilationUnits) asts.add(new JavacAST(messager, context, unit));
- handlers.skipPrintAST();
+ handlers.setPreResolutionPhase();
+ for (JavacAST ast : asts) {
+ ast.traverse(new AnnotationVisitor());
+ handlers.callASTVisitors(ast);
+ }
+
+ context.put(Enter.class, (Enter) null);
+ context.put(MemberEnter.class, (MemberEnter) null);
+ Enter.instance(context).main(compilationUnits);
+
+ handlers.setPostResolutionPhase();
for (JavacAST ast : asts) {
ast.traverse(new AnnotationVisitor());
handlers.callASTVisitors(ast);
}
- handlers.skipAllButPrintAST();
+
+ handlers.setPrintASTPhase();
for (JavacAST ast : asts) {
ast.traverse(new AnnotationVisitor());
}
@@ -61,6 +84,7 @@ public class JavacTransformer {
for (JavacAST ast : asts) {
if (ast.isChanged()) return true;
}
+
return false;
}
diff --git a/src/core/lombok/javac/apt/Processor.java b/src/core/lombok/javac/apt/Processor.java
index 037f5ba5..58631c66 100644
--- a/src/core/lombok/javac/apt/Processor.java
+++ b/src/core/lombok/javac/apt/Processor.java
@@ -26,6 +26,7 @@ import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.IdentityHashMap;
import java.util.Map;
@@ -172,7 +173,7 @@ public class Processor extends AbstractProcessor {
if (unit != null) units.put(unit, null);
}
- transformer.transform(processingEnv.getContext(), units.keySet());
+ transformer.transform(processingEnv.getContext(), new ArrayList<JCCompilationUnit>(units.keySet()));
return false;
}
diff --git a/src/core/lombok/javac/handlers/HandleCleanup.java b/src/core/lombok/javac/handlers/HandleCleanup.java
index d72898b8..cbbdc007 100644
--- a/src/core/lombok/javac/handlers/HandleCleanup.java
+++ b/src/core/lombok/javac/handlers/HandleCleanup.java
@@ -156,4 +156,8 @@ public class HandleCleanup implements JavacAnnotationHandler<Cleanup> {
}
}
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java
index c2332974..d56c976f 100644
--- a/src/core/lombok/javac/handlers/HandleConstructor.java
+++ b/src/core/lombok/javac/handlers/HandleConstructor.java
@@ -69,6 +69,10 @@ public class HandleConstructor {
new HandleConstructor().generateConstructor(typeNode, level, fields, staticName, false, false);
return true;
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
@ProviderFor(JavacAnnotationHandler.class)
@@ -86,6 +90,10 @@ public class HandleConstructor {
new HandleConstructor().generateConstructor(typeNode, level, findRequiredFields(typeNode), staticName, false, suppressConstructorProperties);
return true;
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
private static List<JavacNode> findRequiredFields(JavacNode typeNode) {
@@ -131,6 +139,10 @@ public class HandleConstructor {
new HandleConstructor().generateConstructor(typeNode, level, fields, staticName, false, suppressConstructorProperties);
return true;
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
public void generateRequiredArgsConstructor(JavacNode typeNode, AccessLevel level, String staticName, boolean skipIfConstructorExists) {
diff --git a/src/core/lombok/javac/handlers/HandleData.java b/src/core/lombok/javac/handlers/HandleData.java
index 2087c133..682b7fe4 100644
--- a/src/core/lombok/javac/handlers/HandleData.java
+++ b/src/core/lombok/javac/handlers/HandleData.java
@@ -63,4 +63,8 @@ public class HandleData implements JavacAnnotationHandler<Data> {
return true;
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
index 96113bc4..f824986c 100644
--- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
@@ -479,4 +479,8 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
private JCStatement returnBool(TreeMaker maker, boolean bool) {
return maker.Return(maker.Literal(TypeTags.BOOLEAN, bool ? 1 : 0));
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java
index ac3a16a1..65694dde 100644
--- a/src/core/lombok/javac/handlers/HandleGetter.java
+++ b/src/core/lombok/javac/handlers/HandleGetter.java
@@ -202,4 +202,8 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> {
return treeMaker.MethodDef(treeMaker.Modifiers(access, nonNulls.appendList(nullables)), methodName, methodType,
methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue);
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
diff --git a/src/core/lombok/javac/handlers/HandleLog.java b/src/core/lombok/javac/handlers/HandleLog.java
index 03e40d7f..c72892cc 100644
--- a/src/core/lombok/javac/handlers/HandleLog.java
+++ b/src/core/lombok/javac/handlers/HandleLog.java
@@ -121,6 +121,10 @@ public class HandleLog {
@Override public boolean handle(AnnotationValues<lombok.extern.apachecommons.Log> annotation, JCAnnotation ast, JavacNode annotationNode) {
return processAnnotation(LoggingFramework.COMMONS, annotation, annotationNode);
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
/**
@@ -131,7 +135,11 @@ public class HandleLog {
@Override public boolean handle(AnnotationValues<lombok.extern.jul.Log> annotation, JCAnnotation ast, JavacNode annotationNode) {
return processAnnotation(LoggingFramework.JUL, annotation, annotationNode);
}
- }
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
+ }
/**
* Handles the {@link lombok.extern.log4j.Log} annotation for javac.
@@ -141,6 +149,10 @@ public class HandleLog {
@Override public boolean handle(AnnotationValues<lombok.extern.log4j.Log> annotation, JCAnnotation ast, JavacNode annotationNode) {
return processAnnotation(LoggingFramework.LOG4J, annotation, annotationNode);
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
/**
@@ -151,6 +163,10 @@ public class HandleLog {
@Override public boolean handle(AnnotationValues<lombok.extern.slf4j.Log> annotation, JCAnnotation ast, JavacNode annotationNode) {
return processAnnotation(LoggingFramework.SLF4J, annotation, annotationNode);
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
enum LoggingFramework {
diff --git a/src/core/lombok/javac/handlers/HandlePrintAST.java b/src/core/lombok/javac/handlers/HandlePrintAST.java
index 4c25694b..61b877d6 100644
--- a/src/core/lombok/javac/handlers/HandlePrintAST.java
+++ b/src/core/lombok/javac/handlers/HandlePrintAST.java
@@ -54,4 +54,8 @@ public class HandlePrintAST implements JavacAnnotationHandler<PrintAST> {
return true;
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java
index 98b68e4a..9c7a233a 100644
--- a/src/core/lombok/javac/handlers/HandleSetter.java
+++ b/src/core/lombok/javac/handlers/HandleSetter.java
@@ -238,4 +238,8 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> {
return v.visitNoType(this, p);
}
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
diff --git a/src/core/lombok/javac/handlers/HandleSneakyThrows.java b/src/core/lombok/javac/handlers/HandleSneakyThrows.java
index b2337f67..0f37a80e 100644
--- a/src/core/lombok/javac/handlers/HandleSneakyThrows.java
+++ b/src/core/lombok/javac/handlers/HandleSneakyThrows.java
@@ -110,4 +110,8 @@ public class HandleSneakyThrows implements JavacAnnotationHandler<SneakyThrows>
return maker.Try(tryBlock, List.of(maker.Catch(catchParam, catchBody)), null);
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
diff --git a/src/core/lombok/javac/handlers/HandleSynchronized.java b/src/core/lombok/javac/handlers/HandleSynchronized.java
index a095aaf1..b1394b02 100644
--- a/src/core/lombok/javac/handlers/HandleSynchronized.java
+++ b/src/core/lombok/javac/handlers/HandleSynchronized.java
@@ -107,4 +107,8 @@ public class HandleSynchronized implements JavacAnnotationHandler<Synchronized>
return true;
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
diff --git a/src/core/lombok/javac/handlers/HandleToString.java b/src/core/lombok/javac/handlers/HandleToString.java
index e3cb0294..f52602c3 100644
--- a/src/core/lombok/javac/handlers/HandleToString.java
+++ b/src/core/lombok/javac/handlers/HandleToString.java
@@ -247,4 +247,8 @@ public class HandleToString implements JavacAnnotationHandler<ToString> {
}
return typeName;
}
+
+ @Override public boolean isResolutionBased() {
+ return false;
+ }
}
diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java
index 5da6fec0..983f2d86 100644
--- a/src/core/lombok/javac/handlers/HandleVal.java
+++ b/src/core/lombok/javac/handlers/HandleVal.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2010 Reinier Zwitserloot and Roel Spilker.
+ * Copyright © 2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -31,8 +31,10 @@ import org.mangosdk.spi.ProviderFor;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCEnhancedForLoop;
import com.sun.tools.javac.tree.JCTree.JCExpression;
+import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCNewArray;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;