mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-17 10:14:29 +00:00
Added a prettyprinter test case with some exotic java constructs, and fixed a few bugs involving these. Also removed the old pretty printer.
This commit is contained in:
1 parent
dc5e1b9b35
commit
8db1793461
4 files changed
+122
-1761
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -64,6 +64,7 @@ import com.sun.tools.javac.tree.JCTree.JCUnary;
|
||||
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCWhileLoop;
|
||||
import com.sun.tools.javac.tree.JCTree.JCWildcard;
|
||||
import com.sun.tools.javac.tree.JCTree.TypeBoundKind;
|
||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.Name;
|
||||
@@ -350,6 +351,14 @@ public class PrettyPrinter extends JCTree.Visitor {
|
||||
return null;
|
||||
}
|
||||
|
||||
private int dims(JCExpression vartype) {
|
||||
if (vartype instanceof JCArrayTypeTree) {
|
||||
return 1 + dims(((JCArrayTypeTree) vartype).elemtype);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void printComment(CommentInfo comment) {
|
||||
switch (comment.start) {
|
||||
case DIRECT_AFTER_PREVIOUS:
|
||||
@@ -716,7 +725,10 @@ public class PrettyPrinter extends JCTree.Visitor {
|
||||
}
|
||||
|
||||
@Override public void visitSkip(JCSkip that) {
|
||||
print(";");
|
||||
if (onNewLine && !aligned) {
|
||||
align();
|
||||
}
|
||||
println(";");
|
||||
}
|
||||
|
||||
@Override public void visitAnnotation(JCAnnotation tree) {
|
||||
@@ -1044,13 +1056,17 @@ public class PrettyPrinter extends JCTree.Visitor {
|
||||
if (tree.init.nonEmpty()) {
|
||||
if (tree.init.head instanceof JCVariableDecl) {
|
||||
boolean first = true;
|
||||
int dims = 0;
|
||||
for (JCStatement i : tree.init) {
|
||||
JCVariableDecl vd = (JCVariableDecl) i;
|
||||
if (first) {
|
||||
printVarDefInline(vd);
|
||||
dims = dims(vd.vartype);
|
||||
} else {
|
||||
print(", ");
|
||||
print(vd.name);
|
||||
int dimDiff = dims(vd.vartype) - dims;
|
||||
for (int j = 0; j < dimDiff; j++) print("[]");
|
||||
if (vd.init != null) {
|
||||
print(" = ");
|
||||
print(vd.init);
|
||||
@@ -1121,7 +1137,14 @@ public class PrettyPrinter extends JCTree.Visitor {
|
||||
|
||||
@Override public void visitDoLoop(JCDoWhileLoop tree) {
|
||||
aPrint("do ");
|
||||
print(tree.body);
|
||||
if (tree.body instanceof JCBlock) {
|
||||
println("{");
|
||||
indent++;
|
||||
print(((JCBlock) tree.body).stats, "");
|
||||
indent--;
|
||||
aPrint("}");
|
||||
|
||||
} else print(tree.body);
|
||||
print(" while ");
|
||||
if (tree.cond instanceof JCParens) {
|
||||
print(tree.cond);
|
||||
@@ -1155,7 +1178,7 @@ public class PrettyPrinter extends JCTree.Visitor {
|
||||
}
|
||||
println(": ");
|
||||
indent++;
|
||||
print(tree.stats, "\n");
|
||||
print(tree.stats, "");
|
||||
indent--;
|
||||
}
|
||||
|
||||
@@ -1208,6 +1231,7 @@ public class PrettyPrinter extends JCTree.Visitor {
|
||||
println(";", (JCTree) i);
|
||||
}
|
||||
}
|
||||
indent--;
|
||||
}
|
||||
println("{");
|
||||
indent++;
|
||||
@@ -1371,6 +1395,10 @@ public class PrettyPrinter extends JCTree.Visitor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void visitTypeBoundKind(TypeBoundKind tree) {
|
||||
print(String.valueOf(tree.kind));
|
||||
}
|
||||
|
||||
@Override public void visitTree(JCTree tree) {
|
||||
String simpleName = tree.getClass().getSimpleName();
|
||||
if ("JCTypeUnion".equals(simpleName)) {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import static java.lang.String.*;
|
||||
import java.io.*;
|
||||
class ExoticJava<V> {
|
||||
public <T> ExoticJava(T genericsInConstructor, V genericsInType) {
|
||||
System.out.println(new <String>ExoticJava<Integer>("Hello", 5));
|
||||
}
|
||||
public void test() {
|
||||
int x = 5;
|
||||
int[] y = {10};
|
||||
;
|
||||
class MethodLocal implements Serializable, java.util.RandomAccess {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public final strictfp int foo() {
|
||||
int x = super.hashCode();
|
||||
x <<= 5;
|
||||
do {
|
||||
x <<= 5;
|
||||
} while (Boolean.FALSE);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
for (int i = 10, j[] = {20}; i < 5; i++, j[0]++) {
|
||||
String z = "";
|
||||
try (
|
||||
PrintWriter pw = new PrintWriter(System.out);
|
||||
PrintWriter p2 = new PrintWriter(System.out)) {
|
||||
pw.println();
|
||||
} finally {
|
||||
synchronized (z) {
|
||||
System.out.println(z);
|
||||
}
|
||||
}
|
||||
if ((y == null)) {
|
||||
}
|
||||
if (((y == null))) ;
|
||||
{
|
||||
;
|
||||
}
|
||||
java.util.List<String> list = new java.util.ArrayList<>();
|
||||
assert Boolean.TRUE : "That\'s weird";
|
||||
double d = -1.8E12;
|
||||
long loooong = 305441741;
|
||||
int octal = 87;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import static java.lang.String.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
class ExoticJava<V> {
|
||||
public <T> ExoticJava(T genericsInConstructor, V genericsInType) {
|
||||
System.out.println(new <String>ExoticJava<Integer>("Hello", 5));
|
||||
}
|
||||
;;;;
|
||||
public void test() {
|
||||
int x = 5, y[] = {10};
|
||||
;
|
||||
class MethodLocal implements Serializable, java.util.RandomAccess {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
strictfp public final int foo() {
|
||||
int x = super.hashCode();
|
||||
x <<= 5;
|
||||
do {
|
||||
x <<= 5;
|
||||
} while (Boolean.FALSE);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 10, j[] = {20}; i < 5; i++, j[0]++) {
|
||||
String z = "";
|
||||
try (PrintWriter pw = new PrintWriter(System.out); PrintWriter p2 = new PrintWriter(System.out)) {
|
||||
pw.println();
|
||||
} finally {
|
||||
synchronized (z) {
|
||||
System.out.println(z);
|
||||
}
|
||||
}
|
||||
|
||||
if ((y == null)) {}
|
||||
if (((y == null))) ;
|
||||
{;}
|
||||
java.util.List<String> list = new java.util.ArrayList<>();
|
||||
assert Boolean.TRUE : "That's weird";
|
||||
double d = -1.8e12;
|
||||
long loooong = 0x1234ABCD;
|
||||
int octal = 0127;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user