diff options
-rw-r--r-- | src/core/lombok/javac/Javac.java | 2 | ||||
-rw-r--r-- | src/core/lombok/javac/JavacResolution.java | 24 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/HandleCleanup.java | 2 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java | 44 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/HandleGetter.java | 20 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/HandleSetter.java | 6 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/HandleSynchronized.java | 2 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/HandleToString.java | 12 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/JavacHandlerUtil.java | 2 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/Delombok.java | 12 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/PrettyCommentsPrinter.java | 96 |
11 files changed, 118 insertions, 104 deletions
diff --git a/src/core/lombok/javac/Javac.java b/src/core/lombok/javac/Javac.java index 64e8ee27..594539cd 100644 --- a/src/core/lombok/javac/Javac.java +++ b/src/core/lombok/javac/Javac.java @@ -187,7 +187,7 @@ public class Javac { * @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) { + public static int getCtcInt(Class<?> ctcLocation, String identifier) { try { return (Integer)ctcLocation.getField(identifier).get(null); } catch (NoSuchFieldException e) { diff --git a/src/core/lombok/javac/JavacResolution.java b/src/core/lombok/javac/JavacResolution.java index 5f0e3621..7361de90 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 == 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.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 == Javac.getCTCint(TypeTags.class, "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(Javac.getCTCint(TypeTags.class, "BYTE")); + return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "BYTE")); case CHAR: - return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "CHAR")); + return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "CHAR")); case SHORT: - return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "SHORT")); + return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "SHORT")); case INT: - return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "INT")); + return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "INT")); case LONG: - return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "LONG")); + return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "LONG")); case FLOAT: - return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "FLOAT")); + return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "FLOAT")); case DOUBLE: - return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "DOUBLE")); + return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "DOUBLE")); case BOOLEAN: - return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "BOOLEAN")); + return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "BOOLEAN")); case VOID: - return maker.TypeIdent(Javac.getCTCint(TypeTags.class, "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 cc1eb174..43dacda2 100644 --- a/src/core/lombok/javac/handlers/HandleCleanup.java +++ b/src/core/lombok/javac/handlers/HandleCleanup.java @@ -118,7 +118,7 @@ public class HandleCleanup extends JavacAnnotationHandler<Cleanup> { maker.Apply(List.<JCExpression>nil(), cleanupMethod, List.<JCExpression>nil()))); JCMethodInvocation preventNullAnalysis = preventNullAnalysis(maker, annotationNode, maker.Ident(decl.name)); - JCBinary isNull = maker.Binary(Javac.getCTCint(JCTree.class, "NE"), preventNullAnalysis, maker.Literal(Javac.getCTCint(TypeTags.class, "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 47255a2c..afd299ef 100644 --- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java @@ -211,7 +211,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas 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(Javac.getCTCint(TypeTags.class, "INT")); + JCExpression returnType = maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "INT")); ListBuffer<JCStatement> statements = ListBuffer.lb(); Name primeName = typeNode.toName("PRIME"); @@ -219,12 +219,12 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas /* final int PRIME = 31; */ { if (!fields.isEmpty() || callSuper) { statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), - primeName, maker.TypeIdent(Javac.getCTCint(TypeTags.class, "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(Javac.getCTCint(TypeTags.class, "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(); @@ -289,7 +289,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas /* 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(Javac.getCTCint(JCTree.class, "EQ"), fieldAccessor, maker.Literal(Javac.getCTCint(TypeTags.class, "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)); } @@ -298,8 +298,8 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas /* fold each intoResult entry into: result = result * PRIME + (item); */ for (JCExpression expr : intoResult) { - 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); + 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))); } @@ -315,9 +315,9 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas /** 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(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); + 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, JCTree source) { @@ -331,18 +331,18 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas 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(Javac.getCTCint(TypeTags.class, "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(Javac.getCTCint(JCTree.class, "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(Javac.getCTCint(JCTree.class, "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)); } @@ -377,7 +377,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas JCExpression equalityCheck = maker.Apply(exprNil, maker.Select(maker.Ident(otherName), typeNode.toName("canEqual")), List.of(castThisRef)); - statements.append(maker.If(maker.Unary(Javac.getCTCint(JCTree.class, "NOT"), equalityCheck), returnBool(maker, false), null)); + statements.append(maker.If(maker.Unary(Javac.getCtcInt(JCTree.class, "NOT"), equalityCheck), returnBool(maker, false), null)); } } @@ -386,7 +386,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas 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(Javac.getCTCint(JCTree.class, "NOT"), callToSuper); + JCUnary superNotEqual = maker.Unary(Javac.getCtcInt(JCTree.class, "NOT"), callToSuper); statements.append(maker.If(superNotEqual, returnBool(maker, false), null)); } @@ -407,7 +407,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas default: /* if (this.fieldName != other.fieldName) return false; */ statements.append( - maker.If(maker.Binary(Javac.getCTCint(JCTree.class, "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) { @@ -418,18 +418,18 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas JCExpression eqMethod = chainDots(maker, typeNode, "java", "util", "Arrays", useDeepEquals ? "deepEquals" : "equals"); List<JCExpression> args = List.of(thisFieldAccessor, otherFieldAccessor); - statements.append(maker.If(maker.Unary(Javac.getCTCint(JCTree.class, "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(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 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 equalsArg = createFieldAccessor(maker, fieldNode, fieldAccess, maker.Ident(otherName)); JCExpression castEqualsArg = maker.TypeCast(chainDots(maker, typeNode, "java", "lang", "Object"), equalsArg); JCExpression thisEqualsThat = maker.Apply(List.<JCExpression>nil(), maker.Select(createFieldAccessor(maker, fieldNode, fieldAccess), typeNode.toName("equals")), List.of(castEqualsArg)); - JCExpression fieldsAreNotEqual = maker.Conditional(thisEqualsNull, otherNotEqualsNull, maker.Unary(Javac.getCTCint(JCTree.class, "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)); } } @@ -451,7 +451,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas JCClassDecl type = (JCClassDecl) typeNode.get(); JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.<JCAnnotation>nil()); - JCExpression returnType = maker.TypeIdent(Javac.getCTCint(TypeTags.class, "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"); @@ -468,12 +468,12 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas /* 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(Javac.getCTCint(JCTree.class, "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(Javac.getCTCint(TypeTags.class, "BOOLEAN"), bool ? 1 : 0)); + return maker.Return(maker.Literal(Javac.getCtcInt(TypeTags.class, "BOOLEAN"), bool ? 1 : 0)); } } diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java index 0be00d89..a7e357ad 100644 --- a/src/core/lombok/javac/handlers/HandleGetter.java +++ b/src/core/lombok/javac/handlers/HandleGetter.java @@ -260,14 +260,14 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { private static final java.util.Map<Integer, String> TYPE_MAP; static { Map<Integer, String> m = new HashMap<Integer, String>(); - 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"); + 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); } @@ -327,7 +327,7 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { innerIfStatements.append(statement); } - JCBinary isNull = maker.Binary(JCTree.EQ, maker.Ident(valueName), maker.Literal(Javac.getCTCint(TypeTags.class, "BOT"), null)); + JCBinary isNull = maker.Binary(Javac.getCtcInt(JCTree.class, "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); } @@ -335,7 +335,7 @@ public class HandleGetter extends 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(Javac.getCTCint(TypeTags.class, "BOT"), null)); + JCBinary isNull = maker.Binary(Javac.getCtcInt(JCTree.class, "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 8e29d974..d899336f 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -211,7 +211,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> { List<JCAnnotation> annsOnParam = 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(Javac.getCTCint(TypeTags.class, "VOID"))); + JCExpression methodType = treeMaker.Type(new JCNoType(Javac.getCtcInt(TypeTags.class, "VOID"))); List<JCTypeParameter> methodGenericParams = List.nil(); List<JCVariableDecl> parameters = List.of(param); @@ -229,8 +229,8 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> { @Override public TypeKind getKind() { - if (tag == Javac.getCTCint(TypeTags.class, "VOID")) return TypeKind.VOID; - if (tag == Javac.getCTCint(TypeTags.class, "NONE")) return TypeKind.NONE; + 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); } diff --git a/src/core/lombok/javac/handlers/HandleSynchronized.java b/src/core/lombok/javac/handlers/HandleSynchronized.java index 779adc26..fa4a0474 100644 --- a/src/core/lombok/javac/handlers/HandleSynchronized.java +++ b/src/core/lombok/javac/handlers/HandleSynchronized.java @@ -86,7 +86,7 @@ public class HandleSynchronized extends JavacAnnotationHandler<Synchronized> { JCExpression objectType = chainDots(maker, methodNode, "java", "lang", "Object"); //We use 'new Object[0];' because unlike 'new Object();', empty arrays *ARE* serializable! JCNewArray newObjectArray = maker.NewArray(chainDots(maker, methodNode, "java", "lang", "Object"), - List.<JCExpression>of(maker.Literal(Javac.getCTCint(TypeTags.class, "INT"), 0)), null); + List.<JCExpression>of(maker.Literal(Javac.getCtcInt(TypeTags.class, "INT"), 0)), null); JCVariableDecl fieldDecl = Javac.recursiveSetGeneratedBy(maker.VarDef( maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (isStatic ? Flags.STATIC : 0)), methodNode.toName(lockName), objectType, newObjectArray), ast); diff --git a/src/core/lombok/javac/handlers/HandleToString.java b/src/core/lombok/javac/handlers/HandleToString.java index 5c538460..06e70e7a 100644 --- a/src/core/lombok/javac/handlers/HandleToString.java +++ b/src/core/lombok/javac/handlers/HandleToString.java @@ -197,7 +197,7 @@ public class HandleToString extends 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(Javac.getCTCint(JCTree.class, "PLUS"), current, callToSuper); + current = maker.Binary(Javac.getCtcInt(JCTree.class, "PLUS"), current, callToSuper); first = false; } @@ -217,21 +217,21 @@ public class HandleToString extends JavacAnnotationHandler<ToString> { } else expr = fieldAccessor; if (first) { - current = maker.Binary(Javac.getCTCint(JCTree.class, "PLUS"), current, expr); + current = maker.Binary(Javac.getCtcInt(JCTree.class, "PLUS"), current, expr); first = false; continue; } if (includeFieldNames) { - current = maker.Binary(Javac.getCTCint(JCTree.class, "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(Javac.getCTCint(JCTree.class, "PLUS"), current, maker.Literal(infix)); + current = maker.Binary(Javac.getCtcInt(JCTree.class, "PLUS"), current, maker.Literal(infix)); } - current = maker.Binary(Javac.getCTCint(JCTree.class, "PLUS"), current, expr); + current = maker.Binary(Javac.getCtcInt(JCTree.class, "PLUS"), current, expr); } - if (!first) current = maker.Binary(Javac.getCTCint(JCTree.class, "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 03a9142b..c733304b 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -566,7 +566,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(Javac.getCTCint(JCTree.class, "EQ"), treeMaker.Ident(fieldName), treeMaker.Literal(Javac.getCTCint(TypeTags.class, "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); } /** diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 459d2184..c5973dac 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -358,14 +358,14 @@ public class Delombok { options.put("compilePolicy", "attr"); try { - Class.forName("lombok.delombok.java7.CommentCollectingScannerFactory").getMethod("preRegister", Context.class).invoke(null, context); - } catch (Throwable t1) { - if (!(t1 instanceof NoClassDefFoundError)) Lombok.sneakyThrow(t1); - try { + if (JavaCompiler.version().startsWith("1.6")) { Class.forName("lombok.delombok.java6.CommentCollectingScannerFactory").getMethod("preRegister", Context.class).invoke(null, context); - } catch (Exception t2) { - Lombok.sneakyThrow(t2); + } else { + Class.forName("lombok.delombok.java7.CommentCollectingScannerFactory").getMethod("preRegister", Context.class).invoke(null, context); } + + } catch (Throwable t) { + throw Lombok.sneakyThrow(t); } JavaCompiler compiler = new JavaCompiler(context); diff --git a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java index c3924159..f47b3583 100644 --- a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java +++ b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java @@ -36,10 +36,12 @@ import java.io.Writer; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.HashMap; import java.util.Map; import lombok.delombok.Comment.EndConnection; import lombok.delombok.Comment.StartConnection; +import lombok.javac.Javac; import com.sun.source.tree.Tree; import com.sun.tools.javac.code.BoundKind; @@ -117,7 +119,14 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { private static final Method GET_TAG_METHOD; private static final Field TAG_FIELD; + + private static final int PARENS = Javac.getCtcInt(JCTree.class, "PARENS"); + private static final int IMPORT = Javac.getCtcInt(JCTree.class, "IMPORT"); + private static final int VARDEF = Javac.getCtcInt(JCTree.class, "VARDEF"); + private static final int SELECT = Javac.getCtcInt(JCTree.class, "SELECT"); + private static final Map<Integer, String> OPERATORS; + static { Method m = null; Field f = null; @@ -134,6 +143,39 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { } GET_TAG_METHOD = m; TAG_FIELD = f; + + Map<Integer, String> map = new HashMap<Integer, String>(); + + map.put(Javac.getCtcInt(JCTree.class, "POS"), "+"); + map.put(Javac.getCtcInt(JCTree.class, "NEG"), "-"); + map.put(Javac.getCtcInt(JCTree.class, "NOT"), "!"); + map.put(Javac.getCtcInt(JCTree.class, "COMPL"), "~"); + map.put(Javac.getCtcInt(JCTree.class, "PREINC"), "++"); + map.put(Javac.getCtcInt(JCTree.class, "PREDEC"), "--"); + map.put(Javac.getCtcInt(JCTree.class, "POSTINC"), "++"); + map.put(Javac.getCtcInt(JCTree.class, "POSTDEC"), "--"); + map.put(Javac.getCtcInt(JCTree.class, "NULLCHK"), "<*nullchk*>"); + map.put(Javac.getCtcInt(JCTree.class, "OR"), "||"); + map.put(Javac.getCtcInt(JCTree.class, "AND"), "&&"); + map.put(Javac.getCtcInt(JCTree.class, "EQ"), "=="); + map.put(Javac.getCtcInt(JCTree.class, "NE"), "!="); + map.put(Javac.getCtcInt(JCTree.class, "LT"), "<"); + map.put(Javac.getCtcInt(JCTree.class, "GT"), ">"); + map.put(Javac.getCtcInt(JCTree.class, "LE"), "<="); + map.put(Javac.getCtcInt(JCTree.class, "GE"), ">="); + map.put(Javac.getCtcInt(JCTree.class, "BITOR"), "|"); + map.put(Javac.getCtcInt(JCTree.class, "BITXOR"), "^"); + map.put(Javac.getCtcInt(JCTree.class, "BITAND"), "&"); + map.put(Javac.getCtcInt(JCTree.class, "SL"), "<<"); + map.put(Javac.getCtcInt(JCTree.class, "SR"), ">>"); + map.put(Javac.getCtcInt(JCTree.class, "USR"), ">>>"); + map.put(Javac.getCtcInt(JCTree.class, "PLUS"), "+"); + map.put(Javac.getCtcInt(JCTree.class, "MINUS"), "-"); + map.put(Javac.getCtcInt(JCTree.class, "MUL"), "*"); + map.put(Javac.getCtcInt(JCTree.class, "DIV"), "/"); + map.put(Javac.getCtcInt(JCTree.class, "MOD"), "%"); + + OPERATORS = map; } static int getTag(JCTree tree) { @@ -555,7 +597,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { /** Is the given tree an enumerator definition? */ boolean isEnumerator(JCTree t) { - return getTag(t) == JCTree.VARDEF && (((JCVariableDecl) t).mods.flags & ENUM) != 0; + return getTag(t) == VARDEF && (((JCVariableDecl) t).mods.flags & ENUM) != 0; } /** Print unit consisting of package clause and import statements in toplevel, @@ -577,9 +619,9 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { } boolean firstImport = true; for (List<JCTree> l = tree.defs; - l.nonEmpty() && (cdef == null || getTag(l.head) == JCTree.IMPORT); + l.nonEmpty() && (cdef == null || getTag(l.head) == IMPORT); l = l.tail) { - if (getTag(l.head) == JCTree.IMPORT) { + if (getTag(l.head) == IMPORT) { JCImport imp = (JCImport)l.head; Name name = TreeInfo.name(imp.qualid); if (name == name.table.fromChars(new char[] {'*'}, 0, 1) || @@ -793,7 +835,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { printStat(tree.body); align(); print(" while "); - if (getTag(tree.cond) == JCTree.PARENS) { + if (getTag(tree.cond) == PARENS) { printExpr(tree.cond); } else { print("("); @@ -809,7 +851,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { public void visitWhileLoop(JCWhileLoop tree) { try { print("while "); - if (getTag(tree.cond) == JCTree.PARENS) { + if (getTag(tree.cond) == PARENS) { printExpr(tree.cond); } else { print("("); @@ -827,7 +869,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { try { print("for ("); if (tree.init.nonEmpty()) { - if (getTag(tree.init.head) == JCTree.VARDEF) { + if (getTag(tree.init.head) == VARDEF) { printExpr(tree.init.head); for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) { JCVariableDecl vdef = (JCVariableDecl)l.head; @@ -874,7 +916,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { public void visitSwitch(JCSwitch tree) { try { print("switch "); - if (getTag(tree.selector) == JCTree.PARENS) { + if (getTag(tree.selector) == PARENS) { printExpr(tree.selector); } else { print("("); @@ -913,7 +955,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { public void visitSynchronized(JCSynchronized tree) { try { print("synchronized "); - if (getTag(tree.lock) == JCTree.PARENS) { + if (getTag(tree.lock) == PARENS) { printExpr(tree.lock); } else { print("("); @@ -971,7 +1013,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { public void visitIf(JCIf tree) { try { print("if "); - if (getTag(tree.cond) == JCTree.PARENS) { + if (getTag(tree.cond) == PARENS) { printExpr(tree.cond); } else { print("("); @@ -1058,7 +1100,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { public void visitApply(JCMethodInvocation tree) { try { if (!tree.typeargs.isEmpty()) { - if (getTag(tree.meth) == JCTree.SELECT) { + if (getTag(tree.meth) == SELECT) { JCFieldAccess left = (JCFieldAccess)tree.meth; printExpr(left.selected); print(".<"); @@ -1163,37 +1205,9 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { } public String operatorName(int tag) { - switch(tag) { - case JCTree.POS: return "+"; - case JCTree.NEG: return "-"; - case JCTree.NOT: return "!"; - case JCTree.COMPL: return "~"; - case JCTree.PREINC: return "++"; - case JCTree.PREDEC: return "--"; - case JCTree.POSTINC: return "++"; - case JCTree.POSTDEC: return "--"; - case JCTree.NULLCHK: return "<*nullchk*>"; - case JCTree.OR: return "||"; - case JCTree.AND: return "&&"; - case JCTree.EQ: return "=="; - case JCTree.NE: return "!="; - case JCTree.LT: return "<"; - case JCTree.GT: return ">"; - case JCTree.LE: return "<="; - case JCTree.GE: return ">="; - case JCTree.BITOR: return "|"; - case JCTree.BITXOR: return "^"; - case JCTree.BITAND: return "&"; - case JCTree.SL: return "<<"; - case JCTree.SR: return ">>"; - case JCTree.USR: return ">>>"; - case JCTree.PLUS: return "+"; - case JCTree.MINUS: return "-"; - case JCTree.MUL: return "*"; - case JCTree.DIV: return "/"; - case JCTree.MOD: return "%"; - default: throw new Error(); - } + String result = OPERATORS.get(tag); + if (result == null) throw new Error(); + return result; } public void visitAssignop(JCAssignOp tree) { |