diff options
author | Roel Spilker <r.spilker@gmail.com> | 2019-01-08 00:00:04 +0100 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2019-01-08 00:00:04 +0100 |
commit | 2c7870a4c7e219668709563f2e6530319c68dfa0 (patch) | |
tree | f5c3b1902d6702cce05f9cb4a4989de21db8807e /src/core/lombok | |
parent | ca46f98bebe62ce218de9e15d079a100146851ed (diff) | |
download | lombok-2c7870a4c7e219668709563f2e6530319c68dfa0.tar.gz lombok-2c7870a4c7e219668709563f2e6530319c68dfa0.tar.bz2 lombok-2c7870a4c7e219668709563f2e6530319c68dfa0.zip |
@Delegate @NonNull would error on jdk8, fixes #1935
Diffstat (limited to 'src/core/lombok')
-rw-r--r-- | src/core/lombok/javac/handlers/HandleDelegate.java | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/src/core/lombok/javac/handlers/HandleDelegate.java b/src/core/lombok/javac/handlers/HandleDelegate.java index 49bef769..baff7912 100644 --- a/src/core/lombok/javac/handlers/HandleDelegate.java +++ b/src/core/lombok/javac/handlers/HandleDelegate.java @@ -21,11 +21,12 @@ */ package lombok.javac.handlers; -import static lombok.core.handlers.HandlerUtil.*; -import static lombok.javac.handlers.JavacHandlerUtil.*; import static com.sun.tools.javac.code.Flags.*; +import static lombok.core.handlers.HandlerUtil.handleExperimentalFlagUsage; +import static lombok.javac.handlers.JavacHandlerUtil.*; import java.lang.annotation.Annotation; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -42,19 +43,6 @@ import javax.lang.model.type.ExecutableType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; -import lombok.ConfigurationKeys; -import lombok.experimental.Delegate; -import lombok.core.AST.Kind; -import lombok.core.AnnotationValues; -import lombok.core.HandlerPriority; -import lombok.javac.FindTypeVarScanner; -import lombok.javac.JavacAnnotationHandler; -import lombok.javac.JavacNode; -import lombok.javac.JavacResolution; -import lombok.javac.JavacTreeMaker; -import lombok.javac.ResolutionResetNeeded; -import lombok.javac.JavacResolution.TypeNotConvertibleException; - import org.mangosdk.spi.ProviderFor; import com.sun.tools.javac.code.Attribute.Compound; @@ -80,10 +68,24 @@ import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; +import lombok.ConfigurationKeys; +import lombok.core.AST.Kind; +import lombok.core.AnnotationValues; +import lombok.core.HandlerPriority; +import lombok.experimental.Delegate; +import lombok.javac.FindTypeVarScanner; +import lombok.javac.JavacAnnotationHandler; +import lombok.javac.JavacNode; +import lombok.javac.JavacResolution; +import lombok.javac.JavacResolution.TypeNotConvertibleException; +import lombok.javac.JavacTreeMaker; +import lombok.javac.ResolutionResetNeeded; + @ProviderFor(JavacAnnotationHandler.class) @HandlerPriority(65536) //2^16; to make sure that we also delegate generated methods. @ResolutionResetNeeded public class HandleDelegate extends JavacAnnotationHandler<Delegate> { + private static final List<String> METHODS_IN_OBJECT = Collections.unmodifiableList(Arrays.asList( "hashCode()", "canEqual(java.lang.Object)", //Not in j.l.Object, but it goes with hashCode and equals so if we ignore those two, we should ignore this one. @@ -197,8 +199,9 @@ public class HandleDelegate extends JavacAnnotationHandler<Delegate> { } for (Type t : toDelegate) { - if (t instanceof ClassType) { - ClassType ct = (ClassType) t; + Type unannotatedType = Unannotated.unannotatedType(t); + if (unannotatedType instanceof ClassType) { + ClassType ct = (ClassType) unannotatedType; addMethodBindings(signaturesToDelegate, ct, annotationNode.getTypesUtil(), banList); } else { annotationNode.addError("@Delegate can only use concrete class types, not wildcards, arrays, type variables, or primitives."); @@ -453,4 +456,25 @@ public class HandleDelegate extends JavacAnnotationHandler<Delegate> { public abstract JCExpression get(final JavacNode node, final Name name); } + + private static class Unannotated { + private static final Method unannotated; + + static { + Method m = null; + try { + m = Type.class.getDeclaredMethod("unannotatedType"); + } catch (Exception e) {/* ignore */} + unannotated = m; + } + + static Type unannotatedType(Type t) { + if (unannotated == null) return t; + try { + return (Type) unannotated.invoke(t); + } catch (Exception e) { + return t; + } + } + } } |