aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lombok')
-rw-r--r--src/core/lombok/javac/Javac.java24
-rw-r--r--src/core/lombok/javac/JavacASTAdapter.java1
-rw-r--r--src/core/lombok/javac/JavacResolution.java24
-rw-r--r--src/core/lombok/javac/handlers/HandleCleanup.java3
-rw-r--r--src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java44
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java20
-rw-r--r--src/core/lombok/javac/handlers/HandleSetter.java18
-rw-r--r--src/core/lombok/javac/handlers/HandleSynchronized.java3
-rw-r--r--src/core/lombok/javac/handlers/HandleToString.java12
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java2
10 files changed, 85 insertions, 66 deletions
diff --git a/src/core/lombok/javac/Javac.java b/src/core/lombok/javac/Javac.java
index f4e3f141..8eb56e1d 100644
--- a/src/core/lombok/javac/Javac.java
+++ b/src/core/lombok/javac/Javac.java
@@ -30,11 +30,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import lombok.Lombok;
+import lombok.core.AST.Kind;
import lombok.core.AnnotationValues;
+import lombok.core.AnnotationValues.AnnotationValue;
import lombok.core.TypeLibrary;
import lombok.core.TypeResolver;
-import lombok.core.AST.Kind;
-import lombok.core.AnnotationValues.AnnotationValue;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
@@ -174,4 +175,23 @@ public class Javac {
return x;
} else return null;
}
+
+ /**
+ * Retrieves a compile time constant of type int from the specified class location.
+ *
+ * Solves the problem of compile time constant inlining, resulting in lombok having the wrong value
+ * (javac compiler changes private api constants from time to time)
+ *
+ * @param ctcLocation location of the compile time constant
+ * @param identifier the name of the field of the compile time constant.
+ */
+ public static int getCTCint(Class<?> ctcLocation, String identifier) {
+ try {
+ return (Integer)ctcLocation.getField(identifier).get(null);
+ } catch (NoSuchFieldException e) {
+ throw Lombok.sneakyThrow(e);
+ } catch (IllegalAccessException e) {
+ throw Lombok.sneakyThrow(e);
+ }
+ }
}
diff --git a/src/core/lombok/javac/JavacASTAdapter.java b/src/core/lombok/javac/JavacASTAdapter.java
index bbdb6876..cb8f04bf 100644
--- a/src/core/lombok/javac/JavacASTAdapter.java
+++ b/src/core/lombok/javac/JavacASTAdapter.java
@@ -83,6 +83,7 @@ public class JavacASTAdapter implements JavacASTVisitor {
/** {@inheritDoc} */
@Override public void visitAnnotationOnMethodArgument(JCVariableDecl argument, JCMethodDecl method, JavacNode annotationNode, JCAnnotation annotation) {}
+
/** {@inheritDoc} */
@Override public void endVisitMethodArgument(JavacNode argumentNode, JCVariableDecl argument, JCMethodDecl method) {}
diff --git a/src/core/lombok/javac/JavacResolution.java b/src/core/lombok/javac/JavacResolution.java
index 1200c2b6..c8ff07ec 100644
--- a/src/core/lombok/javac/JavacResolution.java
+++ b/src/core/lombok/javac/JavacResolution.java
@@ -349,8 +349,8 @@ public class JavacResolution {
// NB: There's such a thing as maker.Type(type), but this doesn't work very well; it screws up anonymous classes, captures, and adds an extra prefix dot for some reason too.
// -- so we write our own take on that here.
- if (type.tag == TypeTags.BOT) return createJavaLangObject(maker, ast);
- if (type.tag == TypeTags.VOID) return allowVoid ? primitiveToJCTree(type.getKind(), maker) : createJavaLangObject(maker, ast);
+ if (type.tag == Javac.getCTCint(TypeTags.class, "BOT")) return createJavaLangObject(maker, ast);
+ if (type.tag == Javac.getCTCint(TypeTags.class, "VOID")) return allowVoid ? primitiveToJCTree(type.getKind(), maker) : createJavaLangObject(maker, ast);
if (type.isPrimitive()) return primitiveToJCTree(type.getKind(), maker);
if (type.isErroneous()) throw new TypeNotConvertibleException("Type cannot be resolved");
@@ -384,7 +384,7 @@ public class JavacResolution {
upper = type.getUpperBound();
}
if (allowCompound) {
- if (lower == null || lower.tag == TypeTags.BOT) {
+ if (lower == null || lower.tag == Javac.getCTCint(TypeTags.class, "BOT")) {
if (upper == null || upper.toString().equals("java.lang.Object")) {
return maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null);
}
@@ -421,23 +421,23 @@ public class JavacResolution {
private static JCExpression primitiveToJCTree(TypeKind kind, TreeMaker maker) throws TypeNotConvertibleException {
switch (kind) {
case BYTE:
- return maker.TypeIdent(TypeTags.BYTE);
+ return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "BYTE"));
case CHAR:
- return maker.TypeIdent(TypeTags.CHAR);
+ return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "CHAR"));
case SHORT:
- return maker.TypeIdent(TypeTags.SHORT);
+ return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "SHORT"));
case INT:
- return maker.TypeIdent(TypeTags.INT);
+ return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "INT"));
case LONG:
- return maker.TypeIdent(TypeTags.LONG);
+ return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "LONG"));
case FLOAT:
- return maker.TypeIdent(TypeTags.FLOAT);
+ return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "FLOAT"));
case DOUBLE:
- return maker.TypeIdent(TypeTags.DOUBLE);
+ return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "DOUBLE"));
case BOOLEAN:
- return maker.TypeIdent(TypeTags.BOOLEAN);
+ return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "BOOLEAN"));
case VOID:
- return maker.TypeIdent(TypeTags.VOID);
+ return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "VOID"));
case NULL:
case NONE:
case OTHER:
diff --git a/src/core/lombok/javac/handlers/HandleCleanup.java b/src/core/lombok/javac/handlers/HandleCleanup.java
index bfe357ef..9e2fddf6 100644
--- a/src/core/lombok/javac/handlers/HandleCleanup.java
+++ b/src/core/lombok/javac/handlers/HandleCleanup.java
@@ -25,6 +25,7 @@ import static lombok.javac.handlers.JavacHandlerUtil.markAnnotationAsProcessed;
import lombok.Cleanup;
import lombok.core.AnnotationValues;
import lombok.core.AST.Kind;
+import lombok.javac.Javac;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacNode;
@@ -117,7 +118,7 @@ public class HandleCleanup implements JavacAnnotationHandler<Cleanup> {
maker.Apply(List.<JCExpression>nil(), cleanupMethod, List.<JCExpression>nil())));
JCMethodInvocation preventNullAnalysis = maker.Apply(List.<JCExpression>nil(), JavacHandlerUtil.chainDotsString(maker, annotationNode, "lombok.Lombok.preventNullAnalysis"), List.<JCExpression>of(maker.Ident(decl.name)));
- JCBinary isNull = maker.Binary(JCTree.NE, preventNullAnalysis, maker.Literal(TypeTags.BOT, null));
+ JCBinary isNull = maker.Binary(Javac.getCTCint(JCTree.class, "NE"), preventNullAnalysis, maker.Literal(Javac.getCTCint(TypeTags.class, "BOT"), null));
JCIf ifNotNullCleanup = maker.If(isNull, maker.Block(0, cleanupCall), null);
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
index 59689614..165f2041 100644
--- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
@@ -223,7 +223,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
JCAnnotation overrideAnnotation = maker.Annotation(chainDots(maker, typeNode, "java", "lang", "Override"), List.<JCExpression>nil());
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation));
- JCExpression returnType = maker.TypeIdent(TypeTags.INT);
+ JCExpression returnType = maker.TypeIdent(Javac.getCTCint(TypeTags.class, "INT"));
ListBuffer<JCStatement> statements = ListBuffer.lb();
Name primeName = typeNode.toName("PRIME");
@@ -231,12 +231,12 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
/* final int PRIME = 31; */ {
if (!fields.isEmpty() || callSuper) {
statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL),
- primeName, maker.TypeIdent(TypeTags.INT), maker.Literal(31)));
+ primeName, maker.TypeIdent(Javac.getCTCint(TypeTags.class, "INT")), maker.Literal(31)));
}
}
/* int result = 1; */ {
- statements.append(maker.VarDef(maker.Modifiers(0), resultName, maker.TypeIdent(TypeTags.INT), maker.Literal(1)));
+ statements.append(maker.VarDef(maker.Modifiers(0), resultName, maker.TypeIdent(Javac.getCTCint(TypeTags.class, "INT")), maker.Literal(1)));
}
ListBuffer<JCExpression> intoResult = ListBuffer.lb();
@@ -301,7 +301,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
/* this.fieldName == null ? 0 : this.fieldName.hashCode() */
JCExpression hcCall = maker.Apply(List.<JCExpression>nil(), maker.Select(createFieldAccessor(maker, fieldNode, fieldAccess), typeNode.toName("hashCode")),
List.<JCExpression>nil());
- JCExpression thisEqualsNull = maker.Binary(JCTree.EQ, fieldAccessor, maker.Literal(TypeTags.BOT, null));
+ JCExpression thisEqualsNull = maker.Binary(Javac.getCTCint(JCTree.class, "EQ"), fieldAccessor, maker.Literal(Javac.getCTCint(TypeTags.class, "BOT"), null));
intoResult.append(
maker.Conditional(thisEqualsNull, maker.Literal(0), hcCall));
}
@@ -310,8 +310,8 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
/* fold each intoResult entry into:
result = result * PRIME + (item); */
for (JCExpression expr : intoResult) {
- JCExpression mult = maker.Binary(JCTree.MUL, maker.Ident(resultName), maker.Ident(primeName));
- JCExpression add = maker.Binary(JCTree.PLUS, mult, expr);
+ JCExpression mult = maker.Binary(Javac.getCTCint(JCTree.class, "MUL"), maker.Ident(resultName), maker.Ident(primeName));
+ JCExpression add = maker.Binary(Javac.getCTCint(JCTree.class, "PLUS"), mult, expr);
statements.append(maker.Exec(maker.Assign(maker.Ident(resultName), add)));
}
@@ -327,9 +327,9 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
/** The 2 references must be clones of each other. */
private JCExpression longToIntForHashCode(TreeMaker maker, JCExpression ref1, JCExpression ref2) {
/* (int)(ref >>> 32 ^ ref) */
- JCExpression shift = maker.Binary(JCTree.USR, ref1, maker.Literal(32));
- JCExpression xorBits = maker.Binary(JCTree.BITXOR, shift, ref2);
- return maker.TypeCast(maker.TypeIdent(TypeTags.INT), xorBits);
+ JCExpression shift = maker.Binary(Javac.getCTCint(JCTree.class, "USR"), ref1, maker.Literal(32));
+ JCExpression xorBits = maker.Binary(Javac.getCTCint(JCTree.class, "BITXOR"), shift, ref2);
+ return maker.TypeCast(maker.TypeIdent(Javac.getCTCint(TypeTags.class, "INT")), xorBits);
}
private JCMethodDecl createEquals(JavacNode typeNode, List<JavacNode> fields, boolean callSuper, FieldAccess fieldAccess, boolean needsCanEqual) {
@@ -343,18 +343,18 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
JCAnnotation overrideAnnotation = maker.Annotation(chainDots(maker, typeNode, "java", "lang", "Override"), List.<JCExpression>nil());
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation));
JCExpression objectType = chainDots(maker, typeNode, "java", "lang", "Object");
- JCExpression returnType = maker.TypeIdent(TypeTags.BOOLEAN);
+ JCExpression returnType = maker.TypeIdent(Javac.getCTCint(TypeTags.class, "BOOLEAN"));
ListBuffer<JCStatement> statements = ListBuffer.lb();
final List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL), oName, objectType, null));
/* if (o == this) return true; */ {
- statements.append(maker.If(maker.Binary(JCTree.EQ, maker.Ident(oName),
+ statements.append(maker.If(maker.Binary(Javac.getCTCint(JCTree.class, "EQ"), maker.Ident(oName),
maker.Ident(thisName)), returnBool(maker, true), null));
}
/* if (!(o instanceof MyType) return false; */ {
- JCUnary notInstanceOf = maker.Unary(JCTree.NOT, maker.TypeTest(maker.Ident(oName), maker.Ident(type.name)));
+ JCUnary notInstanceOf = maker.Unary(Javac.getCTCint(JCTree.class, "NOT"), maker.TypeTest(maker.Ident(oName), maker.Ident(type.name)));
statements.append(maker.If(notInstanceOf, returnBool(maker, false), null));
}
@@ -387,7 +387,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
JCExpression equalityCheck = maker.Apply(exprNil,
maker.Select(maker.Ident(otherName), typeNode.toName("canEqual")),
List.<JCExpression>of(maker.Ident(thisName)));
- statements.append(maker.If(maker.Unary(JCTree.NOT, equalityCheck), returnBool(maker, false), null));
+ statements.append(maker.If(maker.Unary(Javac.getCTCint(JCTree.class, "NOT"), equalityCheck), returnBool(maker, false), null));
}
}
@@ -396,7 +396,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
JCMethodInvocation callToSuper = maker.Apply(List.<JCExpression>nil(),
maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("equals")),
List.<JCExpression>of(maker.Ident(oName)));
- JCUnary superNotEqual = maker.Unary(JCTree.NOT, callToSuper);
+ JCUnary superNotEqual = maker.Unary(Javac.getCTCint(JCTree.class, "NOT"), callToSuper);
statements.append(maker.If(superNotEqual, returnBool(maker, false), null));
}
@@ -417,7 +417,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
default:
/* if (this.fieldName != other.fieldName) return false; */
statements.append(
- maker.If(maker.Binary(JCTree.NE, thisFieldAccessor, otherFieldAccessor), returnBool(maker, false), null));
+ maker.If(maker.Binary(Javac.getCTCint(JCTree.class, "NE"), thisFieldAccessor, otherFieldAccessor), returnBool(maker, false), null));
break;
}
} else if (fType instanceof JCArrayTypeTree) {
@@ -428,16 +428,16 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
JCExpression eqMethod = chainDots(maker, typeNode, "java", "util", "Arrays", useDeepEquals ? "deepEquals" : "equals");
List<JCExpression> args = List.of(thisFieldAccessor, otherFieldAccessor);
- statements.append(maker.If(maker.Unary(JCTree.NOT,
+ statements.append(maker.If(maker.Unary(Javac.getCTCint(JCTree.class, "NOT"),
maker.Apply(List.<JCExpression>nil(), eqMethod, args)), returnBool(maker, false), null));
} else /* objects */ {
/* if (this.fieldName == null ? other.fieldName != null : !this.fieldName.equals(other.fieldName)) return false; */
- JCExpression thisEqualsNull = maker.Binary(JCTree.EQ, thisFieldAccessor, maker.Literal(TypeTags.BOT, null));
- JCExpression otherNotEqualsNull = maker.Binary(JCTree.NE, otherFieldAccessor, maker.Literal(TypeTags.BOT, null));
+ JCExpression thisEqualsNull = maker.Binary(Javac.getCTCint(JCTree.class, "EQ"), thisFieldAccessor, maker.Literal(Javac.getCTCint(TypeTags.class, "BOT"), null));
+ JCExpression otherNotEqualsNull = maker.Binary(Javac.getCTCint(JCTree.class, "NE"), otherFieldAccessor, maker.Literal(Javac.getCTCint(TypeTags.class, "BOT"), null));
JCExpression thisEqualsThat = maker.Apply(List.<JCExpression>nil(),
maker.Select(createFieldAccessor(maker, fieldNode, fieldAccess), typeNode.toName("equals")),
List.of(createFieldAccessor(maker, fieldNode, fieldAccess, maker.Ident(otherName))));
- JCExpression fieldsAreNotEqual = maker.Conditional(thisEqualsNull, otherNotEqualsNull, maker.Unary(JCTree.NOT, thisEqualsThat));
+ JCExpression fieldsAreNotEqual = maker.Conditional(thisEqualsNull, otherNotEqualsNull, maker.Unary(Javac.getCTCint(JCTree.class, "NOT"), thisEqualsThat));
statements.append(maker.If(fieldsAreNotEqual, returnBool(maker, false), null));
}
}
@@ -459,7 +459,7 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
JCClassDecl type = (JCClassDecl) typeNode.get();
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.<JCAnnotation>nil());
- JCExpression returnType = maker.TypeIdent(TypeTags.BOOLEAN);
+ JCExpression returnType = maker.TypeIdent(Javac.getCTCint(TypeTags.class, "BOOLEAN"));
Name canEqualName = typeNode.toName("canEqual");
JCExpression objectType = chainDots(maker, typeNode, "java", "lang", "Object");
Name otherName = typeNode.toName("other");
@@ -476,13 +476,13 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler<EqualsAnd
/* if (Float.compare(fieldName, other.fieldName) != 0) return false; */
JCExpression clazz = chainDots(maker, node, "java", "lang", isDouble ? "Double" : "Float");
List<JCExpression> args = List.of(thisDotField, otherDotField);
- JCBinary compareCallEquals0 = maker.Binary(JCTree.NE, maker.Apply(
+ JCBinary compareCallEquals0 = maker.Binary(Javac.getCTCint(JCTree.class, "NE"), maker.Apply(
List.<JCExpression>nil(), maker.Select(clazz, node.toName("compare")), args), maker.Literal(0));
return maker.If(compareCallEquals0, returnBool(maker, false), null);
}
private JCStatement returnBool(TreeMaker maker, boolean bool) {
- return maker.Return(maker.Literal(TypeTags.BOOLEAN, bool ? 1 : 0));
+ return maker.Return(maker.Literal(Javac.getCTCint(TypeTags.class, "BOOLEAN"), bool ? 1 : 0));
}
@Override public boolean isResolutionBased() {
diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java
index 85387684..cfe5c98a 100644
--- a/src/core/lombok/javac/handlers/HandleGetter.java
+++ b/src/core/lombok/javac/handlers/HandleGetter.java
@@ -262,14 +262,14 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> {
private static final java.util.Map<Integer, String> TYPE_MAP;
static {
Map<Integer, String> m = new HashMap<Integer, String>();
- m.put(TypeTags.INT, "java.lang.Integer");
- m.put(TypeTags.DOUBLE, "java.lang.Double");
- m.put(TypeTags.FLOAT, "java.lang.Float");
- m.put(TypeTags.SHORT, "java.lang.Short");
- m.put(TypeTags.BYTE, "java.lang.Byte");
- m.put(TypeTags.LONG, "java.lang.Long");
- m.put(TypeTags.BOOLEAN, "java.lang.Boolean");
- m.put(TypeTags.CHAR, "java.lang.Character");
+ m.put(Javac.getCTCint(TypeTags.class, "INT"), "java.lang.Integer");
+ m.put(Javac.getCTCint(TypeTags.class, "DOUBLE"), "java.lang.Double");
+ m.put(Javac.getCTCint(TypeTags.class, "FLOAT"), "java.lang.Float");
+ m.put(Javac.getCTCint(TypeTags.class, "SHORT"), "java.lang.Short");
+ m.put(Javac.getCTCint(TypeTags.class, "BYTE"), "java.lang.Byte");
+ m.put(Javac.getCTCint(TypeTags.class, "LONG"), "java.lang.Long");
+ m.put(Javac.getCTCint(TypeTags.class, "BOOLEAN"), "java.lang.Boolean");
+ m.put(Javac.getCTCint(TypeTags.class, "CHAR"), "java.lang.Character");
TYPE_MAP = Collections.unmodifiableMap(m);
}
@@ -329,7 +329,7 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> {
innerIfStatements.append(statement);
}
- JCBinary isNull = maker.Binary(JCTree.EQ, maker.Ident(valueName), maker.Literal(TypeTags.BOT, null));
+ JCBinary isNull = maker.Binary(JCTree.EQ, maker.Ident(valueName), maker.Literal(Javac.getCTCint(TypeTags.class, "BOT"), null));
JCIf ifStatement = maker.If(isNull, maker.Block(0, innerIfStatements.toList()), null);
synchronizedStatements.append(ifStatement);
}
@@ -337,7 +337,7 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> {
synchronizedStatement = maker.Synchronized(createFieldAccessor(maker, fieldNode, FieldAccess.ALWAYS_FIELD), maker.Block(0, synchronizedStatements.toList()));
}
- JCBinary isNull = maker.Binary(JCTree.EQ, maker.Ident(valueName), maker.Literal(TypeTags.BOT, null));
+ JCBinary isNull = maker.Binary(JCTree.EQ, maker.Ident(valueName), maker.Literal(Javac.getCTCint(TypeTags.class, "BOT"), null));
JCIf ifStatement = maker.If(isNull, maker.Block(0, List.<JCStatement>of(synchronizedStatement)), null);
statements.append(ifStatement);
}
diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java
index 875c63dd..6dd88abd 100644
--- a/src/core/lombok/javac/handlers/HandleSetter.java
+++ b/src/core/lombok/javac/handlers/HandleSetter.java
@@ -21,7 +21,6 @@
*/
package lombok.javac.handlers;
-import static com.sun.tools.javac.code.TypeTags.*;
import static lombok.javac.handlers.JavacHandlerUtil.*;
import java.util.Collection;
@@ -32,8 +31,8 @@ import javax.lang.model.type.TypeVisitor;
import lombok.AccessLevel;
import lombok.Setter;
-import lombok.core.AnnotationValues;
import lombok.core.AST.Kind;
+import lombok.core.AnnotationValues;
import lombok.core.handlers.TransformationsUtil;
import lombok.javac.Javac;
import lombok.javac.JavacAnnotationHandler;
@@ -45,7 +44,6 @@ import org.mangosdk.spi.ProviderFor;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.TypeTags;
-import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCAssign;
import com.sun.tools.javac.tree.JCTree.JCBlock;
@@ -55,9 +53,10 @@ import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCStatement;
import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
+import com.sun.tools.javac.tree.TreeMaker;
+import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Name;
-import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
/**
* Handles the {@code lombok.Setter} annotation for javac.
@@ -219,7 +218,7 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> {
annsOnParam = annsOnParam.appendList(nonNulls).appendList(nullables);
JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(Flags.FINAL, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
//WARNING: Do not use field.getSymbolTable().voidType - that field has gone through non-backwards compatible API changes within javac1.6.
- JCExpression methodType = treeMaker.Type(new JCNoType(TypeTags.VOID));
+ JCExpression methodType = treeMaker.Type(new JCNoType(Javac.getCTCint(TypeTags.class, "VOID")));
List<JCTypeParameter> methodGenericParams = List.nil();
List<JCVariableDecl> parameters = List.of(param);
@@ -237,12 +236,9 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> {
@Override
public TypeKind getKind() {
- switch (tag) {
- case VOID: return TypeKind.VOID;
- case NONE: return TypeKind.NONE;
- default:
- throw new AssertionError("Unexpected tag: " + tag);
- }
+ if (tag == Javac.getCTCint(TypeTags.class, "VOID")) return TypeKind.VOID;
+ if (tag == Javac.getCTCint(TypeTags.class, "NONE")) return TypeKind.NONE;
+ throw new AssertionError("Unexpected tag: " + tag);
}
@Override
diff --git a/src/core/lombok/javac/handlers/HandleSynchronized.java b/src/core/lombok/javac/handlers/HandleSynchronized.java
index b1394b02..42e29239 100644
--- a/src/core/lombok/javac/handlers/HandleSynchronized.java
+++ b/src/core/lombok/javac/handlers/HandleSynchronized.java
@@ -39,6 +39,7 @@ import com.sun.tools.javac.util.List;
import lombok.Synchronized;
import lombok.core.AnnotationValues;
import lombok.core.AST.Kind;
+import lombok.javac.Javac;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacNode;
@@ -85,7 +86,7 @@ public class HandleSynchronized implements JavacAnnotationHandler<Synchronized>
JCExpression objectType = chainDots(maker, methodNode, "java", "lang", "Object");
//We use 'new Object[0];' because quite unlike 'new Object();', empty arrays *ARE* serializable!
JCNewArray newObjectArray = maker.NewArray(chainDots(maker, methodNode, "java", "lang", "Object"),
- List.<JCExpression>of(maker.Literal(TypeTags.INT, 0)), null);
+ List.<JCExpression>of(maker.Literal(Javac.getCTCint(TypeTags.class, "INT"), 0)), null);
JCVariableDecl fieldDecl = maker.VarDef(
maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (isStatic ? Flags.STATIC : 0)),
methodNode.toName(lockName), objectType, newObjectArray);
diff --git a/src/core/lombok/javac/handlers/HandleToString.java b/src/core/lombok/javac/handlers/HandleToString.java
index 183658c2..6f7465f3 100644
--- a/src/core/lombok/javac/handlers/HandleToString.java
+++ b/src/core/lombok/javac/handlers/HandleToString.java
@@ -198,7 +198,7 @@ public class HandleToString implements JavacAnnotationHandler<ToString> {
JCMethodInvocation callToSuper = maker.Apply(List.<JCExpression>nil(),
maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("toString")),
List.<JCExpression>nil());
- current = maker.Binary(JCTree.PLUS, current, callToSuper);
+ current = maker.Binary(Javac.getCTCint(JCTree.class, "PLUS"), current, callToSuper);
first = false;
}
@@ -218,21 +218,21 @@ public class HandleToString implements JavacAnnotationHandler<ToString> {
} else expr = fieldAccessor;
if (first) {
- current = maker.Binary(JCTree.PLUS, current, expr);
+ current = maker.Binary(Javac.getCTCint(JCTree.class, "PLUS"), current, expr);
first = false;
continue;
}
if (includeFieldNames) {
- current = maker.Binary(JCTree.PLUS, current, maker.Literal(infix + fieldNode.getName() + "="));
+ current = maker.Binary(Javac.getCTCint(JCTree.class, "PLUS"), current, maker.Literal(infix + fieldNode.getName() + "="));
} else {
- current = maker.Binary(JCTree.PLUS, current, maker.Literal(infix));
+ current = maker.Binary(Javac.getCTCint(JCTree.class, "PLUS"), current, maker.Literal(infix));
}
- current = maker.Binary(JCTree.PLUS, current, expr);
+ current = maker.Binary(Javac.getCTCint(JCTree.class, "PLUS"), current, expr);
}
- if (!first) current = maker.Binary(JCTree.PLUS, current, maker.Literal(suffix));
+ if (!first) current = maker.Binary(Javac.getCTCint(JCTree.class, "PLUS"), current, maker.Literal(suffix));
JCStatement returnStatement = maker.Return(current);
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 3f869410..acfc82c9 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -564,7 +564,7 @@ public class JavacHandlerUtil {
JCExpression npe = chainDots(treeMaker, variable, "java", "lang", "NullPointerException");
JCTree exception = treeMaker.NewClass(null, List.<JCExpression>nil(), npe, List.<JCExpression>of(treeMaker.Literal(fieldName.toString())), null);
JCStatement throwStatement = treeMaker.Throw(exception);
- return treeMaker.If(treeMaker.Binary(JCTree.EQ, treeMaker.Ident(fieldName), treeMaker.Literal(TypeTags.BOT, null)), throwStatement, null);
+ return treeMaker.If(treeMaker.Binary(Javac.getCTCint(JCTree.class, "EQ"), treeMaker.Ident(fieldName), treeMaker.Literal(Javac.getCTCint(TypeTags.class, "BOT"), null)), throwStatement, null);
}
/**