diff options
author | Rawi01 <Rawi01@users.noreply.github.com> | 2021-01-21 08:56:53 +0100 |
---|---|---|
committer | Rawi01 <Rawi01@users.noreply.github.com> | 2021-02-01 09:14:42 +0100 |
commit | 332062be9d47f19352b40ca9a603847061861b55 (patch) | |
tree | 5cb12e034c5ae3041eae31ef737ccb85c63fe6f5 /src/core/lombok | |
parent | 06efa58762d243a6ebcc09aea57b81b338e628a4 (diff) | |
download | lombok-332062be9d47f19352b40ca9a603847061861b55.tar.gz lombok-332062be9d47f19352b40ca9a603847061861b55.tar.bz2 lombok-332062be9d47f19352b40ca9a603847061861b55.zip |
Clear invalid types of unboxed annotations
Diffstat (limited to 'src/core/lombok')
-rw-r--r-- | src/core/lombok/javac/handlers/JavacHandlerUtil.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 98c037b7..8233f20b 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -37,6 +37,7 @@ import java.util.HashMap; import java.util.Map; import java.util.regex.Pattern; +import com.sun.tools.javac.code.Attribute; import com.sun.tools.javac.code.BoundKind; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Scope; @@ -1143,6 +1144,35 @@ public class JavacHandlerUtil { } } } + + static class JCAnnotationReflect { + private static final Field ATTRIBUTE; + + static { + ATTRIBUTE = Permit.permissiveGetField(JCAnnotation.class, "attribute"); + } + + static Attribute.Compound getAttribute(JCAnnotation jcAnnotation) { + if (ATTRIBUTE != null) { + try { + return (Attribute.Compound) ATTRIBUTE.get(jcAnnotation); + } catch (Exception e) { + // Ignore + } + } + return null; + } + + static void setAttribute(JCAnnotation jcAnnotation, Attribute.Compound attribute) { + if (ATTRIBUTE != null) { + try { + Permit.set(ATTRIBUTE, jcAnnotation, attribute); + } catch (Exception e) { + // Ignore + } + } + } + } // jdk9 support, types have changed, names stay the same static class ClassSymbolMembersField { @@ -1783,10 +1813,49 @@ public class JavacHandlerUtil { addError(errorName, annotationNode); } } + for (JCAnnotation annotation : result) { + clearTypes(annotation); + } ast.args = params.toList(); return result.toList(); } + /** + * Removes all type information from the provided tree. + */ + private static void clearTypes(JCTree tree) { + tree.accept(new TreeScanner() { + @Override public void scan(JCTree tree) { + tree.type = null; + super.scan(tree); + } + @Override public void visitClassDef(JCClassDecl tree) { + tree.sym = null; + super.visitClassDef(tree); + } + @Override public void visitMethodDef(JCMethodDecl tree) { + tree.sym = null; + super.visitMethodDef(tree); + } + @Override public void visitVarDef(JCVariableDecl tree) { + tree.sym = null; + super.visitVarDef(tree); + } + @Override public void visitSelect(JCFieldAccess tree) { + tree.sym = null; + super.visitSelect(tree); + } + @Override public void visitIdent(JCIdent tree) { + tree.sym = null; + super.visitIdent(tree); + } + @Override public void visitAnnotation(JCAnnotation tree) { + JCAnnotationReflect.setAttribute(tree, null); + super.visitAnnotation(tree); + } + }); + } + private static void addError(String errorName, JavacNode node) { if (node.getLatestJavaSpecSupported() < 8) { node.addError("The correct format up to JDK7 is " + errorName + "=@__({@SomeAnnotation, @SomeOtherAnnotation}))"); |