diff options
-rw-r--r-- | doc/changelog.markdown | 1 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/HandleDelegate.java | 58 |
2 files changed, 42 insertions, 17 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown index 6b24ccc0..00faa993 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -7,6 +7,7 @@ Lombok Changelog * FEATURE: There is now a `lombok.config` key to configure `@ToString`'s call super behavior; it's just like `@EqualsAndHashCode` which has had it for a while now. [Issue #1918](https://github.com/rzwitserloot/lombok/issues/1918) * ENHANCEMENT: The toString generation of enums now contains the name of the enum constant. [Issue #1916](https://github.com/rzwitserloot/lombok/issues/1916) * PLATFORM: Due to changes to switch statements in JDK12, lombok wasn't working with the JDK12 preview. [Issue #1888](https://github.com/rzwitserloot/lombok/issues/1888) +* BUGFIX: Using `@Delegate` in combination `@NonNull` would give an error in jdk8. [Issue #1935](https://github.com/rzwitserloot/lombok/issues/1935) ### v1.18.4 (October 30th, 2018) * PLATFORM: Support for Eclipse Photon. [Issue #1831](https://github.com/rzwitserloot/lombok/issues/1831) 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; + } + } + } } |