diff options
-rw-r--r-- | src/core/lombok/core/AnnotationValues.java | 39 | ||||
-rw-r--r-- | src/core/lombok/eclipse/Eclipse.java | 4 | ||||
-rw-r--r-- | src/core/lombok/javac/Javac.java | 5 |
3 files changed, 31 insertions, 17 deletions
diff --git a/src/core/lombok/core/AnnotationValues.java b/src/core/lombok/core/AnnotationValues.java index db4c6d09..6cecedc7 100644 --- a/src/core/lombok/core/AnnotationValues.java +++ b/src/core/lombok/core/AnnotationValues.java @@ -53,29 +53,20 @@ public class AnnotationValues<A extends Annotation> { /** Guesses for each raw expression. If the raw expression is a literal expression, the guess will * likely be right. If not, it'll be wrong. */ public final List<Object> valueGuesses; + + /** A list of the actual expressions. List is size 1 unless an array is provided. */ + public final List<Object> expressions; + private final LombokNode<?, ?, ?> node; private final boolean isExplicit; /** - * 'raw' should be the exact expression, for example '5+7', 'AccessLevel.PUBLIC', or 'int.class'. - * 'valueGuess' should be a likely guess at the real value intended. - * - * For classes, supply the class name (qualified or not) as a string.<br /> - * For enums, supply the simple name part (everything after the last dot) as a string.<br /> - */ - public AnnotationValue(LombokNode<?, ?, ?> node, String raw, Object valueGuess, boolean isExplicit) { - this.node = node; - this.raws = Collections.singletonList(raw); - this.valueGuesses = Collections.singletonList(valueGuess); - this.isExplicit = isExplicit; - } - - /** * Like the other constructor, but used for when the annotation method is initialized with an array value. */ - public AnnotationValue(LombokNode<?, ?, ?> node, List<String> raws, List<Object> valueGuesses, boolean isExplicit) { + public AnnotationValue(LombokNode<?, ?, ?> node, List<String> raws, List<Object> expressions, List<Object> valueGuesses, boolean isExplicit) { this.node = node; this.raws = raws; + this.expressions = expressions; this.valueGuesses = valueGuesses; this.isExplicit = isExplicit; } @@ -310,6 +301,14 @@ public class AnnotationValues<A extends Annotation> { return v == null ? Collections.<String>emptyList() : v.raws; } + /** + * Returns the actual expressions used for the provided {@code annotationMethodName}. + */ + public List<Object> getActualExpressions(String annotationMethodName) { + AnnotationValue v = values.get(annotationMethodName); + return v == null ? Collections.<Object>emptyList() : v.expressions; + } + public boolean isExplicit(String annotationMethodName) { AnnotationValue annotationValue = values.get(annotationMethodName); return annotationValue != null && annotationValue.isExplicit(); @@ -325,6 +324,16 @@ public class AnnotationValues<A extends Annotation> { return l.isEmpty() ? null : l.get(0); } + /** + * Convenience method to return the first result in a {@link #getActualExpressions(String)} call. + * + * You should use this method if the annotation method is not an array type. + */ + public Object getActualExpression(String annotationMethodName) { + List<Object> l = getActualExpressions(annotationMethodName); + return l.isEmpty() ? null : l.get(0); + } + /** Generates an error message on the stated annotation value (you should only call this method if you know it's there!) */ public void setError(String annotationMethodName, String message) { setError(annotationMethodName, message, -1); diff --git a/src/core/lombok/eclipse/Eclipse.java b/src/core/lombok/eclipse/Eclipse.java index c70660f4..915706f9 100644 --- a/src/core/lombok/eclipse/Eclipse.java +++ b/src/core/lombok/eclipse/Eclipse.java @@ -377,6 +377,7 @@ public class Eclipse { if (!Modifier.isPublic(m.getModifiers())) continue; String name = m.getName(); List<String> raws = new ArrayList<String>(); + List<Object> expressionValues = new ArrayList<Object>(); List<Object> guesses = new ArrayList<Object>(); Expression fullExpression = null; Expression[] expressions = null; @@ -397,6 +398,7 @@ public class Eclipse { StringBuffer sb = new StringBuffer(); ex.print(0, sb); raws.add(sb.toString()); + expressionValues.add(ex); guesses.add(calculateValue(ex)); } } @@ -404,7 +406,7 @@ public class Eclipse { final Expression fullExpr = fullExpression; final Expression[] exprs = expressions; - values.put(name, new AnnotationValue(annotationNode, raws, guesses, isExplicit) { + values.put(name, new AnnotationValue(annotationNode, raws, expressionValues, guesses, isExplicit) { @Override public void setError(String message, int valueIdx) { Expression ex; if (valueIdx == -1) ex = fullExpr; diff --git a/src/core/lombok/javac/Javac.java b/src/core/lombok/javac/Javac.java index 58a24207..6d9800ab 100644 --- a/src/core/lombok/javac/Javac.java +++ b/src/core/lombok/javac/Javac.java @@ -90,6 +90,7 @@ public class Javac { String name = m.getName(); List<String> raws = new ArrayList<String>(); List<Object> guesses = new ArrayList<Object>(); + List<Object> expressions = new ArrayList<Object>(); final List<DiagnosticPosition> positions = new ArrayList<DiagnosticPosition>(); boolean isExplicit = false; @@ -112,17 +113,19 @@ public class Javac { List<JCExpression> elems = ((JCNewArray)rhs).elems; for (JCExpression inner : elems) { raws.add(inner.toString()); + expressions.add(inner); guesses.add(calculateGuess(inner)); positions.add(inner.pos()); } } else { raws.add(rhs.toString()); + expressions.add(rhs); guesses.add(calculateGuess(rhs)); positions.add(rhs.pos()); } } - values.put(name, new AnnotationValue(node, raws, guesses, isExplicit) { + values.put(name, new AnnotationValue(node, raws, expressions, guesses, isExplicit) { @Override public void setError(String message, int valueIdx) { if (valueIdx < 0) node.addError(message); else node.addError(message, positions.get(valueIdx)); |