diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-04-17 04:19:37 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-04-17 04:19:37 +0200 |
commit | f540335ef972d84f02efba6dcaf608aec0e19129 (patch) | |
tree | 90b3c96253dc86171c6e948739a95ddc431e91b6 /src/utils/lombok/javac | |
parent | 7e81ac623831c3147e8fba4ca4ebfa021f4f5bd5 (diff) | |
download | lombok-f540335ef972d84f02efba6dcaf608aec0e19129.tar.gz lombok-f540335ef972d84f02efba6dcaf608aec0e19129.tar.bz2 lombok-f540335ef972d84f02efba6dcaf608aec0e19129.zip |
[Fixes #1656] Lombok would silently do the wrong thing when using references to `public static final String` fields, instead of actual string literals, there where you can specify strings in lombok annotation parameters, such as `@ToString(of = MyClass.CONSTANT_FIELD)`. We can’t really fix it, but at least now lombok will error when you do that and describe in detail what’s going wrong.
Diffstat (limited to 'src/utils/lombok/javac')
-rw-r--r-- | src/utils/lombok/javac/Javac.java | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java index 9ff4d22f..2a66baba 100644 --- a/src/utils/lombok/javac/Javac.java +++ b/src/utils/lombok/javac/Javac.java @@ -36,6 +36,7 @@ import javax.lang.model.type.NoType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeVisitor; +import lombok.core.AnnotationValues; import lombok.javac.JavacTreeMaker.TreeTag; import lombok.javac.JavacTreeMaker.TypeTag; @@ -143,16 +144,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 AnnotationValues.ClassLiteral(x.substring(0, x.length() - 6)); + int idx = x.lastIndexOf('.'); + if (idx > -1) x = x.substring(idx + 1); + return new AnnotationValues.FieldSelect(x); + } + + return null; } public static final TypeTag CTC_BOOLEAN = typeTag("BOOLEAN"); |