diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/lombok/core/ClassLiteral.java | 13 | ||||
-rw-r--r-- | src/utils/lombok/core/FieldSelect.java | 13 | ||||
-rw-r--r-- | src/utils/lombok/eclipse/Eclipse.java | 22 | ||||
-rw-r--r-- | src/utils/lombok/javac/Javac.java | 21 |
4 files changed, 56 insertions, 13 deletions
diff --git a/src/utils/lombok/core/ClassLiteral.java b/src/utils/lombok/core/ClassLiteral.java new file mode 100644 index 00000000..077ead31 --- /dev/null +++ b/src/utils/lombok/core/ClassLiteral.java @@ -0,0 +1,13 @@ +package lombok.core; + +public class ClassLiteral { + private final String className; + + public ClassLiteral(String className) { + this.className = className; + } + + public String getClassName() { + return className; + } +} diff --git a/src/utils/lombok/core/FieldSelect.java b/src/utils/lombok/core/FieldSelect.java new file mode 100644 index 00000000..ab784401 --- /dev/null +++ b/src/utils/lombok/core/FieldSelect.java @@ -0,0 +1,13 @@ +package lombok.core; + +public class FieldSelect { + private final String finalPart; + + public FieldSelect(String finalPart) { + this.finalPart = finalPart; + } + + public String getFinalPart() { + return finalPart; + } +} diff --git a/src/utils/lombok/eclipse/Eclipse.java b/src/utils/lombok/eclipse/Eclipse.java index 18b22256..5ef33086 100644 --- a/src/utils/lombok/eclipse/Eclipse.java +++ b/src/utils/lombok/eclipse/Eclipse.java @@ -27,6 +27,8 @@ import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; +import lombok.core.ClassLiteral; +import lombok.core.FieldSelect; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.Annotation; @@ -40,6 +42,7 @@ import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; import org.eclipse.jdt.internal.compiler.ast.TryStatement; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.ast.UnaryExpression; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; @@ -161,7 +164,7 @@ public class Eclipse { */ public static Object calculateValue(Expression e) { if (e instanceof Literal) { - ((Literal)e).computeConstant(); + ((Literal) e).computeConstant(); switch (e.constant.typeID()) { case TypeIds.T_int: return e.constant.intValue(); case TypeIds.T_byte: return e.constant.byteValue(); @@ -175,13 +178,24 @@ public class Eclipse { default: return null; } } else if (e instanceof ClassLiteralAccess) { - return Eclipse.toQualifiedName(((ClassLiteralAccess)e).type.getTypeName()); + return new ClassLiteral(Eclipse.toQualifiedName(((ClassLiteralAccess)e).type.getTypeName())); } else if (e instanceof SingleNameReference) { - return new String(((SingleNameReference)e).token); + return new FieldSelect(new String(((SingleNameReference)e).token)); } else if (e instanceof QualifiedNameReference) { String qName = Eclipse.toQualifiedName(((QualifiedNameReference)e).tokens); int idx = qName.lastIndexOf('.'); - return idx == -1 ? qName : qName.substring(idx+1); + return new FieldSelect(idx == -1 ? qName : qName.substring(idx+1)); + } else if (e instanceof UnaryExpression) { + if ("-".equals(((UnaryExpression) e).operatorToString())) { + Object inner = calculateValue(((UnaryExpression) e).expression); + if (inner instanceof Integer) return - ((Integer) inner).intValue(); + if (inner instanceof Byte) return - ((Byte) inner).byteValue(); + if (inner instanceof Short) return - ((Short) inner).shortValue(); + if (inner instanceof Long) return - ((Long) inner).longValue(); + if (inner instanceof Float) return - ((Float) inner).floatValue(); + if (inner instanceof Double) return - ((Double) inner).doubleValue(); + return null; + } } return null; diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java index 9ff4d22f..92961726 100644 --- a/src/utils/lombok/javac/Javac.java +++ b/src/utils/lombok/javac/Javac.java @@ -36,6 +36,8 @@ import javax.lang.model.type.NoType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeVisitor; +import lombok.core.ClassLiteral; +import lombok.core.FieldSelect; import lombok.javac.JavacTreeMaker.TreeTag; import lombok.javac.JavacTreeMaker.TypeTag; @@ -143,16 +145,17 @@ public class Javac { return ((Number) lit.value).intValue() == 0 ? false : true; } return lit.value; - } else if (expr instanceof JCIdent || expr instanceof JCFieldAccess) { + } + + if (expr instanceof JCIdent || expr instanceof JCFieldAccess) { String x = expr.toString(); - if (x.endsWith(".class")) x = x.substring(0, x.length() - 6); - else { - int idx = x.lastIndexOf('.'); - if (idx > -1) x = x.substring(idx + 1); - } - return x; - } else - return null; + if (x.endsWith(".class")) return new ClassLiteral(x.substring(0, x.length() - 6)); + int idx = x.lastIndexOf('.'); + if (idx > -1) x = x.substring(idx + 1); + return new FieldSelect(x); + } + + return null; } public static final TypeTag CTC_BOOLEAN = typeTag("BOOLEAN"); |