diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-07-26 17:02:40 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-07-26 17:02:40 +0200 |
commit | 3e03dcfac19901342a07f74b0dfd9d62dbb380f3 (patch) | |
tree | 343af6c7faa063e492935a47a1f13c8748d6cb62 /src | |
parent | 15d77d473668335fd3dfe0f8f5a8d1f111c0ee44 (diff) | |
download | lombok-3e03dcfac19901342a07f74b0dfd9d62dbb380f3.tar.gz lombok-3e03dcfac19901342a07f74b0dfd9d62dbb380f3.tar.bz2 lombok-3e03dcfac19901342a07f74b0dfd9d62dbb380f3.zip |
Fixed bugs with annotation handling: An array initializer with more than 1 entry now no longer causes ArrayIndexOutOfBoundsException, the setWarning method on a single item in an array initializer on eclipse
now generates the warning on just that node (like with errors), and the API of AnnotationValues has been updated to support setting errors/warning on any node.
Diffstat (limited to 'src')
-rw-r--r-- | src/lombok/core/AnnotationValues.java | 40 | ||||
-rw-r--r-- | src/lombok/eclipse/Eclipse.java | 13 |
2 files changed, 52 insertions, 1 deletions
diff --git a/src/lombok/core/AnnotationValues.java b/src/lombok/core/AnnotationValues.java index 7613212a..9d098b59 100644 --- a/src/lombok/core/AnnotationValues.java +++ b/src/lombok/core/AnnotationValues.java @@ -85,6 +85,18 @@ public class AnnotationValues<A extends Annotation> { node.addError(message); } + /** + * Override this if you want more specific behaviour (to get the source position just right). + * + * @param message English message with the problem. + * @param valueIdx The index into the values for this annotation key that caused the problem. + * -1 for a problem that applies to all values, otherwise the 0-based index into an array of values. + * If there is no array for this value (e.g. value=1 instead of value={1,2}), then always -1 or 0. + */ + public void setWarning(String message, int valueIdx) { + node.addError(message); + } + /** {@inheritDoc} */ @Override public String toString() { return "raws: " + raws + " valueGuesses: " + valueGuesses; @@ -159,7 +171,7 @@ public class AnnotationValues<A extends Annotation> { if ( expected.isArray() ) { isArray = true; expected = expected.getComponentType(); - array = Array.newInstance(expected, 1); + array = Array.newInstance(expected, v.valueGuesses.size()); } if ( !isArray && v.valueGuesses.size() > 1 ) { @@ -296,6 +308,32 @@ public class AnnotationValues<A extends Annotation> { 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); + } + + /** Generates a warning message on the stated annotation value (you should only call this method if you know it's there!) */ + public void setWarning(String annotationMethodName, String message) { + setWarning(annotationMethodName, message, -1); + } + + /** Generates an error message on the stated annotation value, which must have an array initializer. + * The index-th item in the initializer will carry the error (you should only call this method if you know it's there!) */ + public void setError(String annotationMethodName, String message, int index) { + AnnotationValue v = values.get(annotationMethodName); + if ( v == null ) return; + v.setError(message, index); + } + + /** Generates a warning message on the stated annotation value, which must have an array initializer. + * The index-th item in the initializer will carry the error (you should only call this method if you know it's there!) */ + public void setWarning(String annotationMethodName, String message, int index) { + AnnotationValue v = values.get(annotationMethodName); + if ( v == null ) return; + v.setWarning(message, index); + } + /** * Attempts to translate class literals to their fully qualified names, such as 'Throwable.class' to 'java.lang.Throwable'. * diff --git a/src/lombok/eclipse/Eclipse.java b/src/lombok/eclipse/Eclipse.java index a52b8d86..cba2bd05 100644 --- a/src/lombok/eclipse/Eclipse.java +++ b/src/lombok/eclipse/Eclipse.java @@ -315,6 +315,19 @@ public class Eclipse { annotationNode.addError(message, sourceStart, sourceEnd); } + + @Override public void setWarning(String message, int valueIdx) { + Expression ex; + if ( valueIdx == -1 ) ex = fullExpr; + else ex = exprs != null ? exprs[valueIdx] : null; + + if ( ex == null ) ex = annotation; + + int sourceStart = ex.sourceStart; + int sourceEnd = ex.sourceEnd; + + annotationNode.addWarning(message, sourceStart, sourceEnd); + } }); } |