aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/delombok/lombok/delombok/PrettyCommentsPrinter.java45
-rw-r--r--test/pretty/resource/after/TypeAnnotations.java22
-rw-r--r--test/pretty/resource/before/TypeAnnotations.java23
3 files changed, 89 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;
+ }
+ }
}
diff --git a/test/pretty/resource/after/TypeAnnotations.java b/test/pretty/resource/after/TypeAnnotations.java
new file mode 100644
index 00000000..760b5ef8
--- /dev/null
+++ b/test/pretty/resource/after/TypeAnnotations.java
@@ -0,0 +1,22 @@
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.List;
+import java.util.Map;
+public class TypeAnnotations {
+ @Target({ElementType.TYPE_USE, ElementType.LOCAL_VARIABLE})
+ @interface Foo {
+ }
+ @Target(ElementType.TYPE_USE)
+ @interface Bar {
+ }
+ public List<@Foo String> test(@Foo String param) {
+ @Bar
+ String local = "bar";
+ @Foo
+ java.io.@Foo File[] array = {};
+ return new java.util.@Foo ArrayList<java.lang.@Foo String>();
+ }
+ public <@Foo T extends java.lang.@Foo Number> T test2(@Bar String... varargs) {
+ return null;
+ }
+}
diff --git a/test/pretty/resource/before/TypeAnnotations.java b/test/pretty/resource/before/TypeAnnotations.java
new file mode 100644
index 00000000..a39337da
--- /dev/null
+++ b/test/pretty/resource/before/TypeAnnotations.java
@@ -0,0 +1,23 @@
+// version 8:
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.List;
+import java.util.Map;
+
+public class TypeAnnotations {
+ @Target({ElementType.TYPE_USE, ElementType.LOCAL_VARIABLE})
+ @interface Foo {}
+
+ @Target(ElementType.TYPE_USE)
+ @interface Bar {}
+
+ public List<@Foo String> test(@Foo String param) {
+ @Bar String local = "bar";
+ @Foo java.io.@Foo File[] array = {};
+ return new java.util.@Foo ArrayList<java.lang.@Foo String>();
+ }
+
+ public <@Foo T extends java.lang.@Foo Number> T test2(@Bar String... varargs) {
+ return null;
+ }
+}