aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/core
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-07-26 17:02:40 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-07-26 17:02:40 +0200
commit3e03dcfac19901342a07f74b0dfd9d62dbb380f3 (patch)
tree343af6c7faa063e492935a47a1f13c8748d6cb62 /src/lombok/core
parent15d77d473668335fd3dfe0f8f5a8d1f111c0ee44 (diff)
downloadlombok-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/lombok/core')
-rw-r--r--src/lombok/core/AnnotationValues.java40
1 files changed, 39 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'.
*