mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 04:16:19 +00:00
[refactor] Cleaned up static imports (always use *), and refactored out getCtcInt calls into constants as defined in Javac.
This commit is contained in:
1 parent
8a6167f8b0
commit
7e84f8d1c2
21 files changed
+106
-87
No files matched your search
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.bytecode;
|
||||
|
||||
import static lombok.bytecode.AsmUtil.fixJSRInlining;
|
||||
import static lombok.bytecode.AsmUtil.*;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.bytecode;
|
||||
|
||||
import static lombok.bytecode.AsmUtil.fixJSRInlining;
|
||||
import static lombok.bytecode.AsmUtil.*;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.core;
|
||||
|
||||
import static lombok.Lombok.sneakyThrow;
|
||||
import static lombok.Lombok.*;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.eclipse;
|
||||
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.isGenerated;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.eclipse;
|
||||
|
||||
import static lombok.eclipse.Eclipse.toQualifiedName;
|
||||
import static lombok.eclipse.Eclipse.*;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.eclipse;
|
||||
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.error;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.eclipse.handlers;
|
||||
|
||||
import static lombok.eclipse.Eclipse.fromQualifiedName;
|
||||
import static lombok.eclipse.Eclipse.*;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.eclipse.handlers;
|
||||
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.hasAnnotation;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.core.AnnotationValues;
|
||||
import lombok.core.HandlerPriority;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package lombok.eclipse.handlers;
|
||||
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.setGeneratedBy;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
|
||||
|
||||
import org.eclipse.jdt.internal.compiler.ASTVisitor;
|
||||
import org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
package lombok.experimental;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
*/
|
||||
package lombok.javac;
|
||||
|
||||
import static lombok.javac.Javac.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
@@ -417,8 +419,8 @@ public class JavacResolution {
|
||||
|
||||
TreeMaker maker = ast.getTreeMaker();
|
||||
|
||||
if (type.tag == Javac.getCtcInt(TypeTags.class, "BOT")) return createJavaLangObject(ast);
|
||||
if (type.tag == Javac.getCtcInt(TypeTags.class, "VOID")) return allowVoid ? primitiveToJCTree(type.getKind(), maker) : createJavaLangObject(ast);
|
||||
if (type.tag == CTC_BOT) return createJavaLangObject(ast);
|
||||
if (type.tag == CTC_VOID) return allowVoid ? primitiveToJCTree(type.getKind(), maker) : createJavaLangObject(ast);
|
||||
if (type.isPrimitive()) return primitiveToJCTree(type.getKind(), maker);
|
||||
if (type.isErroneous()) throw new TypeNotConvertibleException("Type cannot be resolved");
|
||||
|
||||
@@ -452,7 +454,7 @@ public class JavacResolution {
|
||||
upper = type.getUpperBound();
|
||||
}
|
||||
if (allowCompound) {
|
||||
if (lower == null || lower.tag == Javac.getCtcInt(TypeTags.class, "BOT")) {
|
||||
if (lower == null || lower.tag == CTC_BOT) {
|
||||
if (upper == null || upper.toString().equals("java.lang.Object")) {
|
||||
return maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null);
|
||||
}
|
||||
@@ -513,23 +515,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(CTC_BYTE);
|
||||
case CHAR:
|
||||
return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "CHAR"));
|
||||
return maker.TypeIdent(CTC_CHAR);
|
||||
case SHORT:
|
||||
return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "SHORT"));
|
||||
return maker.TypeIdent(CTC_SHORT);
|
||||
case INT:
|
||||
return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "INT"));
|
||||
return maker.TypeIdent(CTC_INT);
|
||||
case LONG:
|
||||
return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "LONG"));
|
||||
return maker.TypeIdent(CTC_LONG);
|
||||
case FLOAT:
|
||||
return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "FLOAT"));
|
||||
return maker.TypeIdent(CTC_FLOAT);
|
||||
case DOUBLE:
|
||||
return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "DOUBLE"));
|
||||
return maker.TypeIdent(CTC_DOUBLE);
|
||||
case BOOLEAN:
|
||||
return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "BOOLEAN"));
|
||||
return maker.TypeIdent(CTC_BOOLEAN);
|
||||
case VOID:
|
||||
return maker.TypeIdent(Javac.getCtcInt(TypeTags.class, "VOID"));
|
||||
return maker.TypeIdent(CTC_VOID);
|
||||
case NULL:
|
||||
case NONE:
|
||||
case OTHER:
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.javac.handlers;
|
||||
|
||||
import static lombok.javac.handlers.JavacHandlerUtil.deleteAnnotationIfNeccessary;
|
||||
import static lombok.javac.handlers.JavacHandlerUtil.*;
|
||||
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
package lombok.javac.handlers;
|
||||
|
||||
import static lombok.javac.handlers.JavacHandlerUtil.*;
|
||||
import static lombok.javac.Javac.*;
|
||||
import lombok.Cleanup;
|
||||
import lombok.core.AST.Kind;
|
||||
import lombok.core.AnnotationValues;
|
||||
import lombok.javac.Javac;
|
||||
import lombok.javac.JavacAnnotationHandler;
|
||||
import lombok.javac.JavacNode;
|
||||
|
||||
@@ -120,7 +120,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(CTC_NOT_EQUAL, preventNullAnalysis, maker.Literal(CTC_BOT, null));
|
||||
|
||||
JCIf ifNotNullCleanup = maker.If(isNull, maker.Block(0, cleanupCall), null);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.javac.handlers;
|
||||
|
||||
import static lombok.javac.Javac.getCtcInt;
|
||||
import static lombok.javac.Javac.*;
|
||||
import static lombok.javac.handlers.JavacHandlerUtil.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -68,7 +68,7 @@ import com.sun.tools.javac.util.Name;
|
||||
public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHashCode> {
|
||||
private static final String RESULT_NAME = "result";
|
||||
private static final String PRIME_NAME = "PRIME";
|
||||
|
||||
|
||||
private void checkForBogusFieldNames(JavacNode type, AnnotationValues<EqualsAndHashCode> annotation) {
|
||||
if (annotation.isExplicit("exclude")) {
|
||||
for (int i : createListOfNonExistentFields(List.from(annotation.getInstance().exclude()), type, true, true)) {
|
||||
@@ -213,7 +213,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
|
||||
JCAnnotation overrideAnnotation = maker.Annotation(chainDots(typeNode, "java", "lang", "Override"), List.<JCExpression>nil());
|
||||
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation));
|
||||
JCExpression returnType = maker.TypeIdent(getCtcInt(TypeTags.class, "INT"));
|
||||
JCExpression returnType = maker.TypeIdent(CTC_INT);
|
||||
ListBuffer<JCStatement> statements = ListBuffer.lb();
|
||||
|
||||
Name primeName = typeNode.toName(PRIME_NAME);
|
||||
@@ -221,12 +221,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(getCtcInt(TypeTags.class, "INT")), maker.Literal(31)));
|
||||
primeName, maker.TypeIdent(CTC_INT), maker.Literal(31)));
|
||||
}
|
||||
}
|
||||
|
||||
/* int result = 1; */ {
|
||||
statements.append(maker.VarDef(maker.Modifiers(0), resultName, maker.TypeIdent(getCtcInt(TypeTags.class, "INT")), maker.Literal(1)));
|
||||
statements.append(maker.VarDef(maker.Modifiers(0), resultName, maker.TypeIdent(CTC_INT), maker.Literal(1)));
|
||||
}
|
||||
|
||||
if (callSuper) {
|
||||
@@ -296,7 +296,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
|
||||
JCExpression hcCall = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(dollarFieldName), typeNode.toName("hashCode")),
|
||||
List.<JCExpression>nil());
|
||||
JCExpression thisEqualsNull = maker.Binary(getCtcInt(JCTree.class, "EQ"), maker.Ident(dollarFieldName), maker.Literal(getCtcInt(TypeTags.class, "BOT"), null));
|
||||
JCExpression thisEqualsNull = maker.Binary(CTC_EQUAL, maker.Ident(dollarFieldName), maker.Literal(CTC_BOT, null));
|
||||
statements.append(createResultCalculation(typeNode, maker.Conditional(thisEqualsNull, maker.Literal(0), hcCall)));
|
||||
}
|
||||
}
|
||||
@@ -314,17 +314,17 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
/* result = result * PRIME + (expr); */
|
||||
TreeMaker maker = typeNode.getTreeMaker();
|
||||
Name resultName = typeNode.toName(RESULT_NAME);
|
||||
JCExpression mult = maker.Binary(getCtcInt(JCTree.class, "MUL"), maker.Ident(resultName), maker.Ident(typeNode.toName(PRIME_NAME)));
|
||||
JCExpression add = maker.Binary(getCtcInt(JCTree.class, "PLUS"), mult, expr);
|
||||
JCExpression mult = maker.Binary(CTC_MUL, maker.Ident(resultName), maker.Ident(typeNode.toName(PRIME_NAME)));
|
||||
JCExpression add = maker.Binary(CTC_PLUS, mult, expr);
|
||||
return maker.Exec(maker.Assign(maker.Ident(resultName), add));
|
||||
}
|
||||
|
||||
/** 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(getCtcInt(JCTree.class, "USR"), ref1, maker.Literal(32));
|
||||
JCExpression xorBits = maker.Binary(getCtcInt(JCTree.class, "BITXOR"), shift, ref2);
|
||||
return maker.TypeCast(maker.TypeIdent(getCtcInt(TypeTags.class, "INT")), xorBits);
|
||||
JCExpression shift = maker.Binary(CTC_UNSIGNED_SHIFT_RIGHT, ref1, maker.Literal(32));
|
||||
JCExpression xorBits = maker.Binary(CTC_BITXOR, shift, ref2);
|
||||
return maker.TypeCast(maker.TypeIdent(CTC_INT), xorBits);
|
||||
}
|
||||
|
||||
private JCExpression createTypeReference(JavacNode type) {
|
||||
@@ -358,18 +358,18 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
JCAnnotation overrideAnnotation = maker.Annotation(chainDots(typeNode, "java", "lang", "Override"), List.<JCExpression>nil());
|
||||
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation));
|
||||
JCExpression objectType = chainDots(typeNode, "java", "lang", "Object");
|
||||
JCExpression returnType = maker.TypeIdent(getCtcInt(TypeTags.class, "BOOLEAN"));
|
||||
JCExpression returnType = maker.TypeIdent(CTC_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(getCtcInt(JCTree.class, "EQ"), maker.Ident(oName),
|
||||
statements.append(maker.If(maker.Binary(CTC_EQUAL, maker.Ident(oName),
|
||||
maker.Ident(thisName)), returnBool(maker, true), null));
|
||||
}
|
||||
|
||||
/* if (!(o instanceof Outer.Inner.MyType) return false; */ {
|
||||
JCUnary notInstanceOf = maker.Unary(getCtcInt(JCTree.class, "NOT"), maker.TypeTest(maker.Ident(oName), createTypeReference(typeNode)));
|
||||
JCUnary notInstanceOf = maker.Unary(CTC_NOT, maker.TypeTest(maker.Ident(oName), createTypeReference(typeNode)));
|
||||
statements.append(maker.If(notInstanceOf, returnBool(maker, false), null));
|
||||
}
|
||||
|
||||
@@ -404,7 +404,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(getCtcInt(JCTree.class, "NOT"), equalityCheck), returnBool(maker, false), null));
|
||||
statements.append(maker.If(maker.Unary(CTC_NOT, equalityCheck), returnBool(maker, false), null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,7 +413,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(getCtcInt(JCTree.class, "NOT"), callToSuper);
|
||||
JCUnary superNotEqual = maker.Unary(CTC_NOT, callToSuper);
|
||||
statements.append(maker.If(superNotEqual, returnBool(maker, false), null));
|
||||
}
|
||||
|
||||
@@ -436,7 +436,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
default:
|
||||
/* if (this.fieldName != other.fieldName) return false; */
|
||||
statements.append(
|
||||
maker.If(maker.Binary(getCtcInt(JCTree.class, "NE"), thisFieldAccessor, otherFieldAccessor), returnBool(maker, false), null));
|
||||
maker.If(maker.Binary(CTC_NOT_EQUAL, thisFieldAccessor, otherFieldAccessor), returnBool(maker, false), null));
|
||||
break;
|
||||
}
|
||||
} else if (fType instanceof JCArrayTypeTree) {
|
||||
@@ -447,7 +447,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
|
||||
JCExpression eqMethod = chainDots(typeNode, "java", "util", "Arrays", useDeepEquals ? "deepEquals" : "equals");
|
||||
List<JCExpression> args = List.of(thisFieldAccessor, otherFieldAccessor);
|
||||
statements.append(maker.If(maker.Unary(getCtcInt(JCTree.class, "NOT"),
|
||||
statements.append(maker.If(maker.Unary(CTC_NOT,
|
||||
maker.Apply(List.<JCExpression>nil(), eqMethod, args)), returnBool(maker, false), null));
|
||||
} else /* objects */ {
|
||||
/* final java.lang.Object this$fieldName = this.fieldName; */
|
||||
@@ -460,12 +460,12 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), thisDollarFieldName, chainDots(typeNode, "java", "lang", "Object"), thisFieldAccessor));
|
||||
statements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), otherDollarFieldName, chainDots(typeNode, "java", "lang", "Object"), otherFieldAccessor));
|
||||
|
||||
JCExpression thisEqualsNull = maker.Binary(getCtcInt(JCTree.class, "EQ"), maker.Ident(thisDollarFieldName), maker.Literal(getCtcInt(TypeTags.class, "BOT"), null));
|
||||
JCExpression otherNotEqualsNull = maker.Binary(getCtcInt(JCTree.class, "NE"), maker.Ident(otherDollarFieldName), maker.Literal(getCtcInt(TypeTags.class, "BOT"), null));
|
||||
JCExpression thisEqualsNull = maker.Binary(CTC_EQUAL, maker.Ident(thisDollarFieldName), maker.Literal(CTC_BOT, null));
|
||||
JCExpression otherNotEqualsNull = maker.Binary(CTC_NOT_EQUAL, maker.Ident(otherDollarFieldName), maker.Literal(CTC_BOT, null));
|
||||
JCExpression thisEqualsThat = maker.Apply(List.<JCExpression>nil(),
|
||||
maker.Select(maker.Ident(thisDollarFieldName), typeNode.toName("equals")),
|
||||
List.<JCExpression>of(maker.Ident(otherDollarFieldName)));
|
||||
JCExpression fieldsAreNotEqual = maker.Conditional(thisEqualsNull, otherNotEqualsNull, maker.Unary(getCtcInt(JCTree.class, "NOT"), thisEqualsThat));
|
||||
JCExpression fieldsAreNotEqual = maker.Conditional(thisEqualsNull, otherNotEqualsNull, maker.Unary(CTC_NOT, thisEqualsThat));
|
||||
statements.append(maker.If(fieldsAreNotEqual, returnBool(maker, false), null));
|
||||
}
|
||||
}
|
||||
@@ -486,7 +486,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
TreeMaker maker = typeNode.getTreeMaker();
|
||||
|
||||
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.<JCAnnotation>nil());
|
||||
JCExpression returnType = maker.TypeIdent(getCtcInt(TypeTags.class, "BOOLEAN"));
|
||||
JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
|
||||
Name canEqualName = typeNode.toName("canEqual");
|
||||
JCExpression objectType = chainDots(typeNode, "java", "lang", "Object");
|
||||
Name otherName = typeNode.toName("other");
|
||||
@@ -503,12 +503,12 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
/* if (Float.compare(fieldName, other.fieldName) != 0) return false; */
|
||||
JCExpression clazz = chainDots(node, "java", "lang", isDouble ? "Double" : "Float");
|
||||
List<JCExpression> args = List.of(thisDotField, otherDotField);
|
||||
JCBinary compareCallEquals0 = maker.Binary(getCtcInt(JCTree.class, "NE"), maker.Apply(
|
||||
JCBinary compareCallEquals0 = maker.Binary(CTC_NOT_EQUAL, 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(getCtcInt(TypeTags.class, "BOOLEAN"), bool ? 1 : 0));
|
||||
return maker.Return(maker.Literal(CTC_BOOLEAN, bool ? 1 : 0));
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,6 @@ import lombok.javac.handlers.JavacHandlerUtil.FieldAccess;
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.code.TypeTags;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.TreeMaker;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
|
||||
@@ -288,14 +287,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(getCtcInt(TypeTags.class, "INT"), "java.lang.Integer");
|
||||
m.put(getCtcInt(TypeTags.class, "DOUBLE"), "java.lang.Double");
|
||||
m.put(getCtcInt(TypeTags.class, "FLOAT"), "java.lang.Float");
|
||||
m.put(getCtcInt(TypeTags.class, "SHORT"), "java.lang.Short");
|
||||
m.put(getCtcInt(TypeTags.class, "BYTE"), "java.lang.Byte");
|
||||
m.put(getCtcInt(TypeTags.class, "LONG"), "java.lang.Long");
|
||||
m.put(getCtcInt(TypeTags.class, "BOOLEAN"), "java.lang.Boolean");
|
||||
m.put(getCtcInt(TypeTags.class, "CHAR"), "java.lang.Character");
|
||||
m.put(CTC_INT, "java.lang.Integer");
|
||||
m.put(CTC_DOUBLE, "java.lang.Double");
|
||||
m.put(CTC_FLOAT, "java.lang.Float");
|
||||
m.put(CTC_SHORT, "java.lang.Short");
|
||||
m.put(CTC_BYTE, "java.lang.Byte");
|
||||
m.put(CTC_LONG, "java.lang.Long");
|
||||
m.put(CTC_BOOLEAN, "java.lang.Boolean");
|
||||
m.put(CTC_CHAR, "java.lang.Character");
|
||||
TYPE_MAP = Collections.unmodifiableMap(m);
|
||||
}
|
||||
|
||||
@@ -361,7 +360,7 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
|
||||
innerIfStatements.append(statement);
|
||||
}
|
||||
|
||||
JCBinary isNull = maker.Binary(getCtcInt(JCTree.class, "EQ"), maker.Ident(valueName), maker.Literal(getCtcInt(TypeTags.class, "BOT"), null));
|
||||
JCBinary isNull = maker.Binary(CTC_EQUAL, maker.Ident(valueName), maker.Literal(CTC_BOT, null));
|
||||
JCIf ifStatement = maker.If(isNull, maker.Block(0, innerIfStatements.toList()), null);
|
||||
synchronizedStatements.append(ifStatement);
|
||||
}
|
||||
@@ -369,7 +368,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(getCtcInt(JCTree.class, "EQ"), maker.Ident(valueName), maker.Literal(getCtcInt(TypeTags.class, "BOT"), null));
|
||||
JCBinary isNull = maker.Binary(CTC_EQUAL, maker.Ident(valueName), maker.Literal(CTC_BOT, null));
|
||||
JCIf ifStatement = maker.If(isNull, maker.Block(0, List.<JCStatement>of(synchronizedStatement)), null);
|
||||
statements.append(ifStatement);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.javac.handlers;
|
||||
|
||||
import static lombok.javac.Javac.getCtcInt;
|
||||
import static lombok.javac.Javac.*;
|
||||
import static lombok.javac.handlers.JavacHandlerUtil.*;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -43,7 +43,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.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAssign;
|
||||
@@ -227,7 +226,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
|
||||
|
||||
if (methodType == null) {
|
||||
//WARNING: Do not use field.getSymbolTable().voidType - that field has gone through non-backwards compatible API changes within javac1.6.
|
||||
methodType = treeMaker.Type(new JCNoType(getCtcInt(TypeTags.class, "VOID")));
|
||||
methodType = treeMaker.Type(new JCNoType(CTC_VOID));
|
||||
returnThis = false;
|
||||
}
|
||||
|
||||
@@ -257,8 +256,8 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
|
||||
|
||||
@Override
|
||||
public TypeKind getKind() {
|
||||
if (tag == getCtcInt(TypeTags.class, "VOID")) return TypeKind.VOID;
|
||||
if (tag == getCtcInt(TypeTags.class, "NONE")) return TypeKind.NONE;
|
||||
if (tag == CTC_VOID) return TypeKind.VOID;
|
||||
if (tag == CTC_NONE) return TypeKind.NONE;
|
||||
throw new AssertionError("Unexpected tag: " + tag);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,28 +21,27 @@
|
||||
*/
|
||||
package lombok.javac.handlers;
|
||||
|
||||
import static lombok.javac.Javac.*;
|
||||
import static lombok.javac.handlers.JavacHandlerUtil.*;
|
||||
import lombok.Synchronized;
|
||||
import lombok.core.AST.Kind;
|
||||
import lombok.core.AnnotationValues;
|
||||
import lombok.javac.JavacAnnotationHandler;
|
||||
import lombok.javac.JavacNode;
|
||||
import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult;
|
||||
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
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.JCExpression;
|
||||
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCNewArray;
|
||||
import com.sun.tools.javac.tree.JCTree.JCStatement;
|
||||
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
|
||||
import com.sun.tools.javac.tree.TreeMaker;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Handles the {@code lombok.Synchronized} annotation for javac.
|
||||
*/
|
||||
@@ -88,7 +87,7 @@ public class HandleSynchronized extends JavacAnnotationHandler<Synchronized> {
|
||||
JCExpression objectType = chainDots(methodNode, ast.pos, "java", "lang", "Object");
|
||||
//We use 'new Object[0];' because unlike 'new Object();', empty arrays *ARE* serializable!
|
||||
JCNewArray newObjectArray = maker.NewArray(chainDots(methodNode, ast.pos, "java", "lang", "Object"),
|
||||
List.<JCExpression>of(maker.Literal(Javac.getCtcInt(TypeTags.class, "INT"), 0)), null);
|
||||
List.<JCExpression>of(maker.Literal(CTC_INT, 0)), null);
|
||||
JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef(
|
||||
maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (isStatic ? Flags.STATIC : 0)),
|
||||
methodNode.toName(lockName), objectType, newObjectArray), ast);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
package lombok.javac.handlers;
|
||||
|
||||
import static lombok.javac.handlers.JavacHandlerUtil.*;
|
||||
import static lombok.javac.Javac.getCtcInt;
|
||||
import static lombok.javac.Javac.*;
|
||||
|
||||
import lombok.ToString;
|
||||
import lombok.core.AnnotationValues;
|
||||
@@ -193,7 +193,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(getCtcInt(JCTree.class, "PLUS"), current, callToSuper);
|
||||
current = maker.Binary(CTC_PLUS, current, callToSuper);
|
||||
first = false;
|
||||
}
|
||||
|
||||
@@ -213,21 +213,21 @@ public class HandleToString extends JavacAnnotationHandler<ToString> {
|
||||
} else expr = fieldAccessor;
|
||||
|
||||
if (first) {
|
||||
current = maker.Binary(getCtcInt(JCTree.class, "PLUS"), current, expr);
|
||||
current = maker.Binary(CTC_PLUS, current, expr);
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (includeFieldNames) {
|
||||
current = maker.Binary(getCtcInt(JCTree.class, "PLUS"), current, maker.Literal(infix + fieldNode.getName() + "="));
|
||||
current = maker.Binary(CTC_PLUS, current, maker.Literal(infix + fieldNode.getName() + "="));
|
||||
} else {
|
||||
current = maker.Binary(getCtcInt(JCTree.class, "PLUS"), current, maker.Literal(infix));
|
||||
current = maker.Binary(CTC_PLUS, current, maker.Literal(infix));
|
||||
}
|
||||
|
||||
current = maker.Binary(getCtcInt(JCTree.class, "PLUS"), current, expr);
|
||||
current = maker.Binary(CTC_PLUS, current, expr);
|
||||
}
|
||||
|
||||
if (!first) current = maker.Binary(getCtcInt(JCTree.class, "PLUS"), current, maker.Literal(suffix));
|
||||
if (!first) current = maker.Binary(CTC_PLUS, current, maker.Literal(suffix));
|
||||
|
||||
JCStatement returnStatement = maker.Return(current);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.javac.handlers;
|
||||
|
||||
import static lombok.javac.Javac.getCtcInt;
|
||||
import static lombok.javac.Javac.*;
|
||||
import static lombok.javac.handlers.JavacHandlerUtil.*;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -240,7 +240,7 @@ public class HandleWither extends JavacAnnotationHandler<Wither> {
|
||||
}
|
||||
|
||||
JCNewClass newClass = maker.NewClass(null, List.<JCExpression>nil(), selfType, args.toList(), null);
|
||||
JCExpression identityCheck = maker.Binary(getCtcInt(JCTree.class, "EQ"), createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name));
|
||||
JCExpression identityCheck = maker.Binary(CTC_EQUAL, createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name));
|
||||
JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass);
|
||||
JCReturn returnStatement = maker.Return(conditional);
|
||||
|
||||
|
||||
@@ -42,12 +42,10 @@ import lombok.core.AnnotationValues.AnnotationValue;
|
||||
import lombok.core.TransformationsUtil;
|
||||
import lombok.core.TypeResolver;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.javac.Javac;
|
||||
import lombok.javac.JavacNode;
|
||||
|
||||
import com.sun.tools.javac.code.BoundKind;
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.code.TypeTags;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
|
||||
import com.sun.tools.javac.tree.JCTree.JCArrayTypeTree;
|
||||
@@ -891,7 +889,7 @@ public class JavacHandlerUtil {
|
||||
JCExpression npe = chainDots(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(CTC_EQUAL, treeMaker.Ident(fieldName), treeMaker.Literal(CTC_BOT, null)), throwStatement, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,6 +23,8 @@ package lombok.javac;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.sun.tools.javac.code.TypeTags;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCExpression;
|
||||
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
|
||||
import com.sun.tools.javac.tree.JCTree.JCIdent;
|
||||
@@ -71,6 +73,26 @@ public class Javac {
|
||||
} else return null;
|
||||
}
|
||||
|
||||
public static final int CTC_BOOLEAN = getCtcInt(TypeTags.class, "BOOLEAN");
|
||||
public static final int CTC_INT = getCtcInt(TypeTags.class, "INT");
|
||||
public static final int CTC_DOUBLE = getCtcInt(TypeTags.class, "DOUBLE");
|
||||
public static final int CTC_FLOAT = getCtcInt(TypeTags.class, "FLOAT");
|
||||
public static final int CTC_SHORT = getCtcInt(TypeTags.class, "SHORT");
|
||||
public static final int CTC_BYTE = getCtcInt(TypeTags.class, "BYTE");
|
||||
public static final int CTC_LONG = getCtcInt(TypeTags.class, "LONG");
|
||||
public static final int CTC_CHAR = getCtcInt(TypeTags.class, "CHAR");
|
||||
public static final int CTC_VOID = getCtcInt(TypeTags.class, "VOID");
|
||||
public static final int CTC_NONE = getCtcInt(TypeTags.class, "NONE");
|
||||
|
||||
public static final int CTC_NOT_EQUAL = getCtcInt(JCTree.class, "NE");
|
||||
public static final int CTC_NOT = getCtcInt(JCTree.class, "NOT");
|
||||
public static final int CTC_BITXOR = getCtcInt(JCTree.class, "BITXOR");
|
||||
public static final int CTC_UNSIGNED_SHIFT_RIGHT = getCtcInt(JCTree.class, "USR");
|
||||
public static final int CTC_MUL = getCtcInt(JCTree.class, "MUL");
|
||||
public static final int CTC_PLUS = getCtcInt(JCTree.class, "PLUS");
|
||||
public static final int CTC_BOT = getCtcInt(TypeTags.class, "BOT");
|
||||
public static final int CTC_EQUAL = getCtcInt(JCTree.class, "EQ");
|
||||
|
||||
/**
|
||||
* Retrieves a compile time constant of type int from the specified class location.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user