diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2015-08-18 23:12:17 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2015-08-18 23:12:17 +0200 |
commit | 1dcbc161c403f62eed87603ce79f8bf2f266b778 (patch) | |
tree | ce8c33e0213293e3588ccd3b250a01b6becd081b /src/delombok | |
parent | 05760d67ef4ccec8b702166371c7bdc9bdf77d95 (diff) | |
download | lombok-1dcbc161c403f62eed87603ce79f8bf2f266b778.tar.gz lombok-1dcbc161c403f62eed87603ce79f8bf2f266b778.tar.bz2 lombok-1dcbc161c403f62eed87603ce79f8bf2f266b778.zip |
[Closes #855] [jdk8] annotations are now legit on types and type parameters in JDK8, but we’d print errors in delombok when encountering these.
Diffstat (limited to 'src/delombok')
-rw-r--r-- | src/delombok/lombok/delombok/PrettyCommentsPrinter.java | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java index f57b74a2..ca44670d 100644 --- a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java +++ b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java @@ -1518,6 +1518,11 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { public void visitTypeParameter(JCTypeParameter tree) { try { + List<JCExpression> annotations = readExpressionListOrNil(tree, "annotations"); + if (!annotations.isEmpty()) { + printExprs(annotations); + print(" "); + } print(tree.name); if (tree.bounds.nonEmpty()) { print(" extends "); @@ -1614,6 +1619,8 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { } else if ("JCMemberReference".equals(simpleName)) { visitReference0(tree); return; + } else if ("JCAnnotatedType".equals(simpleName)) { + visitAnnotatedType0(tree); } else { print("(UNKNOWN[" + tree.getClass().getSimpleName() + "]: " + tree + ")"); println(); @@ -1662,13 +1669,31 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { printExprs(typeArgs); print(">"); } - ; print(readObject(tree, "mode").toString().equals("INVOKE") ? readObject(tree, "name") : "new"); } catch (IOException e) { throw new UncheckedIOException(e); } } + public void visitAnnotatedType0(JCTree tree) { + try { + JCTree underlyingType = readTree(tree, "underlyingType"); + if (underlyingType instanceof JCFieldAccess) { + printExpr(((JCFieldAccess) underlyingType).selected); + print("."); + printExprs(readExpressionList(tree, "annotations")); + print(" "); + print(((JCFieldAccess) underlyingType).name); + } else { + printExprs(readExpressionList(tree, "annotations")); + print(" "); + printExpr(underlyingType); + } + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + private JCTree readTree(JCTree tree, String fieldName) { try { return (JCTree) readObject0(tree, fieldName); @@ -1695,6 +1720,15 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { } } + @SuppressWarnings("unchecked") + private List<JCExpression> readExpressionListOrNil(JCTree tree, String fieldName) throws IOException { + try { + return (List<JCExpression>) readObject0(tree, fieldName, List.nil()); + } catch (Exception e) { + return List.nil(); + } + } + private Object readObject(JCTree tree, String fieldName) { try { return readObject0(tree, fieldName); @@ -1712,4 +1746,13 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { throw e; } } + + @SuppressWarnings("unchecked") + private Object readObject0(JCTree tree, String fieldName, Object defaultValue) throws Exception { + try { + return tree.getClass().getDeclaredField(fieldName).get(tree); + } catch (Exception e) { + return defaultValue; + } + } } |