diff options
-rw-r--r-- | src/delombok/lombok/delombok/PrettyCommentsPrinter.java | 73 | ||||
-rw-r--r-- | test/pretty/resource/after/CastWithIntersection.java | 6 | ||||
-rw-r--r-- | test/pretty/resource/after/Lambda.java | 7 | ||||
-rw-r--r-- | test/pretty/resource/after/MultiCatch.java | 9 | ||||
-rw-r--r-- | test/pretty/resource/before/CastWithIntersection.java | 7 | ||||
-rw-r--r-- | test/pretty/resource/before/Lambda.java | 8 | ||||
-rw-r--r-- | test/pretty/resource/before/MultiCatch.java | 10 |
7 files changed, 114 insertions, 6 deletions
diff --git a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java index 0b0936d0..a0a11d6c 100644 --- a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java +++ b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java @@ -49,6 +49,7 @@ import lombok.javac.JavacTreeMaker.TypeTag; import com.sun.source.tree.Tree; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Symbol; +import com.sun.tools.javac.tree.DocCommentTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCArrayAccess; @@ -101,7 +102,6 @@ import com.sun.tools.javac.tree.JCTree.JCWhileLoop; import com.sun.tools.javac.tree.JCTree.JCWildcard; import com.sun.tools.javac.tree.JCTree.LetExpr; import com.sun.tools.javac.tree.JCTree.TypeBoundKind; -import com.sun.tools.javac.tree.DocCommentTable; import com.sun.tools.javac.tree.TreeInfo; import com.sun.tools.javac.tree.TreeScanner; import com.sun.tools.javac.util.Convert; @@ -396,8 +396,8 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { if (tree == null) print("/*missing*/"); else { consumeComments(tree.pos, tree); - tree.accept(this); - int endPos = endPos(tree); + tree.accept(this); + int endPos = endPos(tree); consumeTrailingComments(endPos); } } catch (UncheckedIOException ex) { @@ -1567,17 +1567,78 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { try { String simpleName = tree.getClass().getSimpleName(); if ("JCTypeUnion".equals(simpleName)) { - print(tree.toString()); + printExprs(readExpressionList(tree, "alternatives"), " | "); return; } else if ("JCTypeIntersection".equals(simpleName)) { - print(tree.toString()); + printExprs(readExpressionList(tree, "bounds"), " & "); + return; + } else if ("JCLambda".equals(simpleName)) { + visitLambda0(tree); return; } else { - print("(UNKNOWN: " + tree + ")"); + print("(UNKNOWN[" + tree.getClass().getSimpleName() + "]: " + tree + ")"); println(); } } catch (IOException e) { throw new UncheckedIOException(e); } } + + private void visitLambda0(JCTree tree) { + try { + print("("); + List<JCVariableDecl> params = (List<JCVariableDecl>) readTreeList(tree, "params"); + boolean explicit = true; + try { + explicit = readObject(tree, "paramKind").toString().equals("EXPLICIT"); + } catch (Exception e) {} + if (explicit) { + printExprs(params); + } else { + String sep = ""; + for (JCVariableDecl param : params) { + print(sep); + print(param.name); + sep = ", "; + } + } + print(") -> "); + printExpr(readTree(tree, "body")); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + private JCTree readTree(JCTree tree, String fieldName) { + try { + return (JCTree) readObject(tree, fieldName); + } catch (Exception e) { + return null; + } + } + + private List<? extends JCTree> readTreeList(JCTree tree, String fieldName) throws IOException { + try { + return (List<? extends JCTree>) readObject(tree, fieldName); + } catch (Exception e) { + return List.nil(); + } + } + + private List<JCExpression> readExpressionList(JCTree tree, String fieldName) throws IOException { + try { + return (List<JCExpression>) readObject(tree, fieldName); + } catch (Exception e) { + return List.nil(); + } + } + + private Object readObject(JCTree tree, String fieldName) throws Exception { + try { + return tree.getClass().getDeclaredField(fieldName).get(tree); + } catch (Exception e) { + print("ERROR_READING_FIELD"); + throw e; + } + } } diff --git a/test/pretty/resource/after/CastWithIntersection.java b/test/pretty/resource/after/CastWithIntersection.java new file mode 100644 index 00000000..2eebdee1 --- /dev/null +++ b/test/pretty/resource/after/CastWithIntersection.java @@ -0,0 +1,6 @@ +import java.util.*; +public class CastWithIntersection { + public void test(List<?> list) { + RandomAccess r = (RandomAccess & java.io.Serializable)list; + } +}
\ No newline at end of file diff --git a/test/pretty/resource/after/Lambda.java b/test/pretty/resource/after/Lambda.java new file mode 100644 index 00000000..54d7caa0 --- /dev/null +++ b/test/pretty/resource/after/Lambda.java @@ -0,0 +1,7 @@ +public class Lambda { + Runnable r = () -> System.out.println(); + java.util.Comparator<Integer> c1 = (a, b) -> a - b; + java.util.Comparator<Integer> c2 = (Integer a, Integer b) -> { + return a - b; + }; +}
\ No newline at end of file diff --git a/test/pretty/resource/after/MultiCatch.java b/test/pretty/resource/after/MultiCatch.java new file mode 100644 index 00000000..f0414c2e --- /dev/null +++ b/test/pretty/resource/after/MultiCatch.java @@ -0,0 +1,9 @@ +public class MultiCatch { + public void test() { + try { + System.out.println(); + } catch (IllegalArgumentException | IllegalStateException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/test/pretty/resource/before/CastWithIntersection.java b/test/pretty/resource/before/CastWithIntersection.java new file mode 100644 index 00000000..ce97cba0 --- /dev/null +++ b/test/pretty/resource/before/CastWithIntersection.java @@ -0,0 +1,7 @@ +// version 8: +import java.util.*; +public class CastWithIntersection { + public void test(List<?> list) { + RandomAccess r = (RandomAccess & java.io.Serializable) list; + } +}
\ No newline at end of file diff --git a/test/pretty/resource/before/Lambda.java b/test/pretty/resource/before/Lambda.java new file mode 100644 index 00000000..e7784df5 --- /dev/null +++ b/test/pretty/resource/before/Lambda.java @@ -0,0 +1,8 @@ +// version 8: +public class Lambda { + Runnable r = () -> System.out.println(); + java.util.Comparator<Integer> c1 = (a, b) -> a - b; + java.util.Comparator<Integer> c2 = (Integer a, Integer b) -> { + return a - b; + }; +}
\ No newline at end of file diff --git a/test/pretty/resource/before/MultiCatch.java b/test/pretty/resource/before/MultiCatch.java new file mode 100644 index 00000000..590fe382 --- /dev/null +++ b/test/pretty/resource/before/MultiCatch.java @@ -0,0 +1,10 @@ +// version 7: +public class MultiCatch { + public void test() { + try { + System.out.println(); + } catch (IllegalArgumentException | IllegalStateException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file |