aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2015-07-27 23:25:37 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2015-11-16 22:18:29 +0100
commit9cfac4131ff33b247652ed3622491cbf8bf76721 (patch)
treec1f31d3577a308ea7b76bc847c73b2c40fc11333
parentff4f995507d23c1c9172de2f5fffaf0bfb6cf1ec (diff)
downloadlombok-9cfac4131ff33b247652ed3622491cbf8bf76721.tar.gz
lombok-9cfac4131ff33b247652ed3622491cbf8bf76721.tar.bz2
lombok-9cfac4131ff33b247652ed3622491cbf8bf76721.zip
The bulk of the effort for a new pretty printer.
-rw-r--r--src/delombok/lombok/delombok/DelombokResult.java3
-rw-r--r--src/delombok/lombok/delombok/PrettyPrinter.java1458
-rw-r--r--test/pretty/resource/after/Cast.java2
-rw-r--r--test/pretty/resource/after/CastWithIntersection.java2
-rw-r--r--test/pretty/resource/after/DefaultMethod.java2
-rw-r--r--test/pretty/resource/after/Enum.java9
-rw-r--r--test/pretty/resource/after/Interfaces.java5
-rw-r--r--test/pretty/resource/before/Cast.java2
-rw-r--r--test/transform/resource/after-delombok/Accessors.java4
-rw-r--r--test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java4
-rw-r--r--test/transform/resource/after-delombok/DataConfiguration.java4
-rw-r--r--test/transform/resource/after-delombok/DataExtended.java4
-rw-r--r--test/transform/resource/after-delombok/DataIgnore.java4
-rw-r--r--test/transform/resource/after-delombok/DataOnLocalClass.java12
-rw-r--r--test/transform/resource/after-delombok/DataPlain.java18
-rw-r--r--test/transform/resource/after-delombok/DataWithGetter.java4
-rw-r--r--test/transform/resource/after-delombok/DataWithGetterNone.java4
-rw-r--r--test/transform/resource/after-delombok/DelegateOnGetter.java4
-rw-r--r--test/transform/resource/after-delombok/EqualsAndHashCode.java18
-rw-r--r--test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java4
-rw-r--r--test/transform/resource/after-delombok/EqualsAndHashCodeWithOnParam.java4
-rw-r--r--test/transform/resource/after-delombok/EqualsAndHashCodeWithSomeExistingMethods.java8
-rw-r--r--test/transform/resource/after-delombok/GetterLazy.java2
-rw-r--r--test/transform/resource/after-delombok/GetterLazyBoolean.java8
-rw-r--r--test/transform/resource/after-delombok/GetterLazyEahcToString.java7
-rw-r--r--test/transform/resource/after-delombok/GetterLazyNative.java20
-rw-r--r--test/transform/resource/after-delombok/GetterSetterJavadoc.java4
-rw-r--r--test/transform/resource/after-delombok/InjectField.java3
-rw-r--r--test/transform/resource/after-delombok/LoggerSlf4jTypes.java2
-rw-r--r--test/transform/resource/after-delombok/UtilityClass.java3
-rw-r--r--test/transform/resource/after-delombok/UtilityClassErrors.java2
-rw-r--r--test/transform/resource/after-delombok/ValAnonymousSubclassWithGenerics.java4
-rw-r--r--test/transform/resource/after-delombok/ValLambda.java14
-rw-r--r--test/transform/resource/after-delombok/ValRawType.java2
-rw-r--r--test/transform/resource/after-delombok/ValWeirdTypes.java6
-rw-r--r--test/transform/resource/after-delombok/ValWithLocalClasses.java2
-rw-r--r--test/transform/resource/after-delombok/ValuePlain.java8
37 files changed, 1557 insertions, 109 deletions
diff --git a/src/delombok/lombok/delombok/DelombokResult.java b/src/delombok/lombok/delombok/DelombokResult.java
index 84aeb68b..8985b257 100644
--- a/src/delombok/lombok/delombok/DelombokResult.java
+++ b/src/delombok/lombok/delombok/DelombokResult.java
@@ -65,7 +65,8 @@ public class DelombokResult {
else comments_ = com.sun.tools.javac.util.List.from(comments.toArray(new CommentInfo[0]));
FormatPreferences preferences = new FormatPreferenceScanner().scan(formatPreferences, getContent());
- compilationUnit.accept(new PrettyCommentsPrinter(out, compilationUnit, comments_, preferences));
+ //compilationUnit.accept(new PrettyCommentsPrinter(out, compilationUnit, comments_, preferences));
+ compilationUnit.accept(new PrettyPrinter(out, compilationUnit, comments_, preferences));
}
private CharSequence getContent() throws IOException {
diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java
new file mode 100644
index 00000000..0b248c52
--- /dev/null
+++ b/src/delombok/lombok/delombok/PrettyPrinter.java
@@ -0,0 +1,1458 @@
+package lombok.delombok;
+
+import static com.sun.tools.javac.code.Flags.*;
+import static lombok.javac.Javac.*;
+import static lombok.javac.JavacTreeMaker.TreeTag.treeTag;
+import static lombok.javac.JavacTreeMaker.TypeTag.typeTag;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+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;
+import com.sun.tools.javac.tree.JCTree.JCArrayTypeTree;
+import com.sun.tools.javac.tree.JCTree.JCAssert;
+import com.sun.tools.javac.tree.JCTree.JCAssign;
+import com.sun.tools.javac.tree.JCTree.JCAssignOp;
+import com.sun.tools.javac.tree.JCTree.JCBinary;
+import com.sun.tools.javac.tree.JCTree.JCBlock;
+import com.sun.tools.javac.tree.JCTree.JCBreak;
+import com.sun.tools.javac.tree.JCTree.JCCase;
+import com.sun.tools.javac.tree.JCTree.JCCatch;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
+import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
+import com.sun.tools.javac.tree.JCTree.JCConditional;
+import com.sun.tools.javac.tree.JCTree.JCContinue;
+import com.sun.tools.javac.tree.JCTree.JCDoWhileLoop;
+import com.sun.tools.javac.tree.JCTree.JCEnhancedForLoop;
+import com.sun.tools.javac.tree.JCTree.JCErroneous;
+import com.sun.tools.javac.tree.JCTree.JCExpression;
+import com.sun.tools.javac.tree.JCTree.JCExpressionStatement;
+import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
+import com.sun.tools.javac.tree.JCTree.JCForLoop;
+import com.sun.tools.javac.tree.JCTree.JCIdent;
+import com.sun.tools.javac.tree.JCTree.JCIf;
+import com.sun.tools.javac.tree.JCTree.JCImport;
+import com.sun.tools.javac.tree.JCTree.JCInstanceOf;
+import com.sun.tools.javac.tree.JCTree.JCLabeledStatement;
+import com.sun.tools.javac.tree.JCTree.JCLiteral;
+import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
+import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
+import com.sun.tools.javac.tree.JCTree.JCModifiers;
+import com.sun.tools.javac.tree.JCTree.JCNewArray;
+import com.sun.tools.javac.tree.JCTree.JCNewClass;
+import com.sun.tools.javac.tree.JCTree.JCParens;
+import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree;
+import com.sun.tools.javac.tree.JCTree.JCReturn;
+import com.sun.tools.javac.tree.JCTree.JCSkip;
+import com.sun.tools.javac.tree.JCTree.JCStatement;
+import com.sun.tools.javac.tree.JCTree.JCSwitch;
+import com.sun.tools.javac.tree.JCTree.JCSynchronized;
+import com.sun.tools.javac.tree.JCTree.JCThrow;
+import com.sun.tools.javac.tree.JCTree.JCTry;
+import com.sun.tools.javac.tree.JCTree.JCTypeApply;
+import com.sun.tools.javac.tree.JCTree.JCTypeCast;
+import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
+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.util.JCDiagnostic.DiagnosticPosition;
+import com.sun.tools.javac.util.List;
+import com.sun.tools.javac.util.Name;
+import com.sun.tools.javac.util.Position;
+
+import lombok.javac.CommentInfo;
+import lombok.javac.CommentInfo.EndConnection;
+import lombok.javac.CommentInfo.StartConnection;
+import lombok.javac.JavacTreeMaker.TreeTag;
+import lombok.javac.JavacTreeMaker.TypeTag;
+
+public class PrettyPrinter extends JCTree.Visitor {
+ private static final String LINE_SEP = System.getProperty("line.separator");
+ private static final Map<TreeTag, String> OPERATORS;
+
+ static {
+ Map<TreeTag, String> map = new HashMap<TreeTag, String>();
+
+ map.put(treeTag("POS"), "+");
+ map.put(treeTag("NEG"), "-");
+ map.put(treeTag("NOT"), "!");
+ map.put(treeTag("COMPL"), "~");
+ map.put(treeTag("PREINC"), "++");
+ map.put(treeTag("PREDEC"), "--");
+ map.put(treeTag("POSTINC"), "++");
+ map.put(treeTag("POSTDEC"), "--");
+ map.put(treeTag("NULLCHK"), "<*nullchk*>");
+ map.put(treeTag("OR"), "||");
+ map.put(treeTag("AND"), "&&");
+ map.put(treeTag("EQ"), "==");
+ map.put(treeTag("NE"), "!=");
+ map.put(treeTag("LT"), "<");
+ map.put(treeTag("GT"), ">");
+ map.put(treeTag("LE"), "<=");
+ map.put(treeTag("GE"), ">=");
+ map.put(treeTag("BITOR"), "|");
+ map.put(treeTag("BITXOR"), "^");
+ map.put(treeTag("BITAND"), "&");
+ map.put(treeTag("SL"), "<<");
+ map.put(treeTag("SR"), ">>");
+ map.put(treeTag("USR"), ">>>");
+ map.put(treeTag("PLUS"), "+");
+ map.put(treeTag("MINUS"), "-");
+ map.put(treeTag("MUL"), "*");
+ map.put(treeTag("DIV"), "/");
+ map.put(treeTag("MOD"), "%");
+
+ map.put(treeTag("BITOR_ASG"), "|=");
+ map.put(treeTag("BITXOR_ASG"), "^=");
+ map.put(treeTag("BITAND_ASG"), "&=");
+ map.put(treeTag("SL_ASG"), "<<=");
+ map.put(treeTag("SR_ASG"), ">>=");
+ map.put(treeTag("USR_ASG"), ">>>=");
+ map.put(treeTag("PLUS_ASG"), "+=");
+ map.put(treeTag("MINUS_ASG"), "-=");
+ map.put(treeTag("MUL_ASG"), "*=");
+ map.put(treeTag("DIV_ASG"), "/=");
+ map.put(treeTag("MOD_ASG"), "%=");
+
+ OPERATORS = map;
+ }
+
+ private final Writer out;
+ private final JCCompilationUnit compilationUnit;
+ private List<CommentInfo> comments;
+ private final FormatPreferences formatPreferences;
+
+ private final Map<JCTree, String> docComments;
+ private final DocCommentTable docTable;
+ private int indent = 0;
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public PrettyPrinter(Writer out, JCCompilationUnit cu, List<CommentInfo> comments, FormatPreferences preferences) {
+ this.out = out;
+ this.comments = comments;
+ this.compilationUnit = cu;
+ this.formatPreferences = preferences;
+
+ /* load doc comments */ {
+ Object dc = getDocComments(compilationUnit);
+ if (dc instanceof Map<?, ?>) {
+ this.docComments = (Map) dc;
+ this.docTable = null;
+ } else if (dc instanceof DocCommentTable) {
+ this.docComments = null;
+ this.docTable = (DocCommentTable) dc;
+ } else {
+ this.docComments = null;
+ this.docTable = null;
+ }
+ }
+ }
+
+ private int endPos(JCTree tree) {
+ return getEndPosition(tree, compilationUnit);
+ }
+
+ private static int lineEndPos(String s, int start) {
+ int pos = s.indexOf('\n', start);
+ if (pos < 0) pos = s.length();
+ return pos;
+ }
+
+ private boolean needsAlign, needsNewLine, onNewLine = true, needsSpace, aligned;
+
+ public static final class UncheckedIOException extends RuntimeException {
+ UncheckedIOException(IOException source) {
+ super(toMsg(source));
+ setStackTrace(source.getStackTrace());
+ }
+
+ private static String toMsg(Throwable t) {
+ String msg = t.getMessage();
+ String n = t.getClass().getSimpleName();
+ if (msg == null || msg.isEmpty()) return n;
+ return n + ": " + msg;
+ }
+ }
+
+ private void align() {
+ if (!onNewLine) return;
+ try {
+ for (int i = 0; i < indent; i++) out.write(formatPreferences.indent());
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+
+ onNewLine = false;
+ aligned = true;
+ needsAlign = false;
+ }
+
+ private void print(JCTree tree) {
+ if (tree == null) {
+ print("/*missing*/");
+ return;
+ }
+
+ consumeComments(tree);
+ tree.accept(this);
+ consumeTrailingComments(endPos(tree));
+ }
+
+ private void print(List<? extends JCTree> trees, String infix) {
+ boolean first = true;
+ JCTree prev = null;
+ for (JCTree tree : trees) {
+ if (suppress(tree)) continue;
+ if (!first && infix != null && !infix.isEmpty()) {
+ if ("\n".equals(infix)) println(prev);
+ else print(infix);
+ }
+ first = false;
+ print(tree);
+ prev = tree;
+ }
+ }
+
+ private boolean suppress(JCTree tree) {
+ if (tree instanceof JCBlock) {
+ JCBlock block = (JCBlock) tree;
+ return (Position.NOPOS == block.pos) && block.stats.isEmpty();
+ }
+
+ if (tree instanceof JCExpressionStatement) {
+ JCExpression expr = ((JCExpressionStatement)tree).expr;
+ if (expr instanceof JCMethodInvocation) {
+ JCMethodInvocation inv = (JCMethodInvocation) expr;
+ if (!inv.typeargs.isEmpty() || !inv.args.isEmpty()) return false;
+ if (!(inv.meth instanceof JCIdent)) return false;
+ return ((JCIdent) inv.meth).name.toString().equals("super");
+ }
+ }
+
+ return false;
+ }
+
+ private void print(CharSequence s) {
+ boolean align = needsAlign;
+ if (needsNewLine && !onNewLine) println();
+ if (align && !aligned) align();
+ try {
+ if (needsSpace && !onNewLine && !aligned) out.write(' ');
+ out.write(s.toString());
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+
+ needsSpace = false;
+ onNewLine = false;
+ aligned = false;
+ }
+
+
+ private void println() {
+ try {
+ out.write(LINE_SEP);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+
+ onNewLine = true;
+ aligned = false;
+ needsNewLine = false;
+ }
+
+ private void println(JCTree completed) {
+ if (completed != null) {
+ int endPos = endPos(completed);
+ consumeTrailingComments(endPos);
+ }
+ try {
+ out.write(LINE_SEP);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+
+ onNewLine = true;
+ aligned = false;
+ needsNewLine = false;
+ }
+
+ private void println(CharSequence s) {
+ print(s);
+ println();
+ }
+
+ private void println(CharSequence s, JCTree completed) {
+ print(s);
+ println(completed);
+ }
+
+ private void aPrint(CharSequence s) {
+ align();
+ print(s);
+ }
+
+ private void aPrintln(CharSequence s) {
+ align();
+ print(s);
+ println();
+ }
+
+ private void aPrintln(CharSequence s, JCTree completed) {
+ align();
+ print(s);
+ println(completed);
+ }
+
+ private void consumeComments(int until) {
+ CommentInfo head = comments.head;
+ while (comments.nonEmpty() && head.pos < until) {
+ printComment(head);
+ comments = comments.tail;
+ head = comments.head;
+ }
+ }
+
+ private void consumeComments(JCTree tree) {
+ consumeComments(tree.pos);
+ }
+
+ private void consumeTrailingComments(int from) {
+ boolean prevNewLine = onNewLine;
+ CommentInfo head = comments.head;
+ boolean stop = false;
+
+ while (comments.nonEmpty() && head.prevEndPos == from && !stop && !(head.start == StartConnection.ON_NEXT_LINE || head.start == StartConnection.START_OF_LINE)) {
+ from = head.endPos;
+ printComment(head);
+ stop = (head.end == EndConnection.ON_NEXT_LINE);
+ comments = comments.tail;
+ head = comments.head;
+ }
+
+ if (!onNewLine && prevNewLine) {
+ println();
+ }
+ }
+
+ private String getJavadocFor(JCTree node) {
+ if (docComments != null) return docComments.get(node);
+ if (docTable != null) return docTable.getCommentText(node);
+ return null;
+ }
+
+ private void printComment(CommentInfo comment) {
+ switch (comment.start) {
+ case DIRECT_AFTER_PREVIOUS:
+ needsSpace = false;
+ break;
+ case AFTER_PREVIOUS:
+ needsSpace = true;
+ break;
+ case START_OF_LINE:
+ needsNewLine = true;
+ needsAlign = false;
+ break;
+ case ON_NEXT_LINE:
+ if (!onNewLine) {
+ needsNewLine = true;
+ needsAlign = true;
+ } else if (!aligned) {
+ needsAlign = true;
+ }
+ break;
+ }
+
+ print(comment.content);
+
+ switch (comment.end) {
+ case ON_NEXT_LINE:
+ if (!aligned) {
+ needsNewLine = true;
+ needsAlign = true;
+ }
+ break;
+ case AFTER_COMMENT:
+ needsSpace = true;
+ break;
+ case DIRECT_AFTER_COMMENT:
+ // do nothing
+ break;
+ }
+ }
+
+ private void printDocComment(JCTree tree) {
+ String dc = getJavadocFor(tree);
+ if (dc == null) return;
+ aPrintln("/**");
+ int pos = 0;
+ int endpos = lineEndPos(dc, pos);
+ boolean atStart = true;
+ while (pos < dc.length()) {
+ String line = dc.substring(pos, endpos);
+ if (line.trim().isEmpty() && atStart) {
+ atStart = false;
+ continue;
+ }
+ atStart = false;
+ aPrint(" *");
+ if (pos < dc.length() && dc.charAt(pos) > ' ') print(" ");
+ println(dc.substring(pos, endpos));
+ pos = endpos + 1;
+ endpos = lineEndPos(dc, pos);
+ }
+ aPrintln(" */");
+ }
+
+ private Name __INIT__, __VALUE__;
+ private Name name_init(Name someName) {
+ if (__INIT__ == null) __INIT__ = someName.table.fromChars("<init>".toCharArray(), 0, 6);
+ return __INIT__;
+ }
+ private Name name_value(Name someName) {
+ if (__VALUE__ == null) __VALUE__ = someName.table.fromChars("value".toCharArray(), 0, 5);
+ return __VALUE__;
+ }
+
+ @Override public void visitTopLevel(JCCompilationUnit tree) {
+ printDocComment(tree);
+ if (tree.pid != null) {
+ consumeComments(tree);
+ aPrint("package ");
+ print(tree.pid);
+ println(";", tree.pid);
+ }
+
+ boolean first = true;
+
+ for (JCTree child : tree.defs) {
+ if (!(child instanceof JCImport)) continue;
+ if (first) println();
+ first = false;
+ print(child);
+ }
+
+ for (JCTree child : tree.defs) {
+ if (child instanceof JCImport) continue;
+ print(child);
+ }
+ consumeComments(Integer.MAX_VALUE);
+ }
+
+ @Override public void visitImport(JCImport tree) {
+ aPrint("import ");
+ if (tree.staticImport) print("static ");
+ print(tree.qualid);
+ println(";", tree);
+ }
+
+ private Name currentTypeName;
+ @Override public void visitClassDef(JCClassDecl tree) {
+ println();
+ printDocComment(tree);
+ align();
+ print(tree.mods);
+
+ boolean isInterface = (tree.mods.flags & INTERFACE) != 0;
+ boolean isAnnotationInterface = isInterface && (tree.mods.flags & ANNOTATION) != 0;
+ boolean isEnum = (tree.mods.flags & ENUM) != 0;
+
+ if (isAnnotationInterface) print("@interface ");
+ else if (isInterface) print("interface ");
+ else if (isEnum) print("enum ");
+ else print("class ");
+
+ print(tree.name);
+ Name prevTypeName = currentTypeName;
+ currentTypeName = tree.name;
+
+ if (tree.typarams.nonEmpty()) {
+ print("<");
+ print(tree.typarams, ", ");
+ print(">");
+ }
+ JCTree extendsClause = getExtendsClause(tree);
+ if (extendsClause != null) {
+ print(" extends ");
+ print(extendsClause);
+ }
+
+ if (tree.implementing.nonEmpty()) {
+ print(isInterface ? " extends " : " implements ");
+ print(tree.implementing, ", ");
+ }
+
+ println(" {");
+ indent++;
+ printClassMembers(tree.defs, isEnum, isInterface);
+ consumeComments(endPos(tree));
+ indent--;
+ aPrintln("}", tree);
+ currentTypeName = prevTypeName;
+ }
+
+ private void printClassMembers(List<JCTree> members, boolean isEnum, boolean isInterface) {
+ Class<?> prefType = null;
+ int typeOfPrevEnumMember = isEnum ? 3 : 0; // 1 = normal, 2 = with body, 3 = no enum field yet.
+ boolean prevWasEnumMember = isEnum;
+
+ for (JCTree member : members) {
+ if (typeOfPrevEnumMember == 3 && member instanceof JCMethodDecl && (((JCMethodDecl) member).mods.flags & GENERATEDCONSTR) != 0) continue;
+ boolean isEnumVar = isEnum && member instanceof JCVariableDecl && (((JCVariableDecl) member).mods.flags & ENUM) != 0;
+ if (!isEnumVar && prevWasEnumMember) {
+ prevWasEnumMember = false;
+ if (typeOfPrevEnumMember == 3) align();
+ println(";");
+ }
+
+ if (isEnumVar) {
+ if (prefType != null && prefType != JCVariableDecl.class) println();
+ switch (typeOfPrevEnumMember) {
+ case 1:
+ print(", ");
+ break;
+ case 2:
+ println(",");
+ align();
+ break;
+ }
+ print(member);
+ JCTree init = ((JCVariableDecl) member).init;
+ typeOfPrevEnumMember = init instanceof JCNewClass && ((JCNewClass) init).def != null ? 2 : 1;
+ } else if (member instanceof JCVariableDecl) {
+ if (prefType != null && prefType != JCVariableDecl.class) println();
+ if (isInterface) flagMod = -1L & ~(PUBLIC | STATIC | FINAL);
+ print(member);
+ } else if (member instanceof JCMethodDecl) {
+ if ((((JCMethodDecl) member).mods.flags & GENERATEDCONSTR) != 0) continue;
+ if (prefType != null) println();
+ if (isInterface) flagMod = -1L & ~(PUBLIC | ABSTRACT);
+ print(member);
+ } else if (member instanceof JCClassDecl) {
+ if (prefType != null) println();
+ if (isInterface) flagMod = -1L & ~(PUBLIC | STATIC);
+ print(member);
+ } else {
+ if (prefType != null) println();
+ print(member);
+ }
+
+ prefType = member.getClass();
+ }
+
+ if (prevWasEnumMember) {
+ prevWasEnumMember = false;
+ if (typeOfPrevEnumMember == 3) align();
+ println(";");
+ }
+ }
+
+ @Override public void visitTypeParameter(JCTypeParameter tree) {
+ List<JCExpression> annotations = readObject(tree, "annotations", List.<JCExpression>nil());
+ if (!annotations.isEmpty()) {
+ print(annotations, " ");
+ print(" ");
+ }
+ print(tree.name);
+ if (tree.bounds.nonEmpty()) {
+ print(" extends ");
+ print(tree.bounds, " & ");
+ }
+ consumeComments(tree);
+ }
+
+ @Override public void visitVarDef(JCVariableDecl tree) {
+ printDocComment(tree);
+ align();
+ if ((tree.mods.flags & ENUM) != 0) {
+ printEnumMember(tree);
+ return;
+ }
+ printAnnotations(tree.mods.annotations, true);
+ printModifierKeywords(tree.mods);
+ printVarDef0(tree);
+ println(";", tree);
+ }
+
+ private void printVarDefInline(JCVariableDecl tree) {
+ printAnnotations(tree.mods.annotations, false);
+ printModifierKeywords(tree.mods);
+ printVarDef0(tree);
+ }
+
+ private void printVarDef0(JCVariableDecl tree) {
+ boolean varargs = (tree.mods.flags & VARARGS) != 0;
+ if (varargs && tree.vartype instanceof JCArrayTypeTree) {
+ print(((JCArrayTypeTree) tree.vartype).elemtype);
+ print("...");
+ } else {
+ print(tree.vartype);
+ }
+ print(" ");
+ print(tree.name);
+ if (tree.init != null) {
+ print(" = ");
+ print(tree.init);
+ }
+ }
+
+ private void printEnumMember(JCVariableDecl tree) {
+ printAnnotations(tree.mods.annotations, true);
+ print(tree.name);
+ if (tree.init instanceof JCNewClass) {
+ JCNewClass constructor = (JCNewClass) tree.init;
+ if (constructor.args != null && constructor.args.nonEmpty()) {
+ print("(");
+ print(constructor.args, ", ");
+ print(")");
+ }
+
+ if (constructor.def != null && constructor.def.defs != null) {
+ println(" {");
+ indent++;
+ printClassMembers(constructor.def.defs, false, false);
+ consumeComments(endPos(tree));
+ indent--;
+ aPrint("}");
+ }
+ }
+ }
+
+ // TODO: Test postfix syntax for methods (?), for decls. Multiline vardefs, possibly with comments. enums with bodies. constructor-local generics, method-local generics, also do/while, finally, try-with-resources, lambdas, annotations in java8 places...
+ // TODO: Whatever is JCAnnotatedType? We handle it in the 7+ bucket in the old one...
+
+ @Override public void visitTypeApply(JCTypeApply tree) {
+ print(tree.clazz);
+ print("<");
+ print(tree.arguments, ", ");
+ print(">");
+ }
+
+ @Override public void visitWildcard(JCWildcard tree) {
+ switch (tree.getKind()) {
+ default:
+ case UNBOUNDED_WILDCARD:
+ print("?");
+ return;
+ case EXTENDS_WILDCARD:
+ print("? extends ");
+ print(tree.inner);
+ return;
+ case SUPER_WILDCARD:
+ print("? super ");
+ print(tree.inner);
+ return;
+ }
+ }
+
+ @Override public void visitLiteral(JCLiteral tree) {
+ TypeTag typeTag = typeTag(tree);
+ if (CTC_INT.equals(typeTag)) print("" + tree.value);
+ else if (CTC_LONG.equals(typeTag)) print(tree.value + "L");
+ else if (CTC_FLOAT.equals(typeTag)) print(tree.value + "F");
+ else if (CTC_DOUBLE.equals(typeTag)) print("" + tree.value);
+ else if (CTC_CHAR.equals(typeTag)) {
+ print("\'" + quoteChar((char)((Number)tree.value).intValue()) + "\'");
+ }
+ else if (CTC_BOOLEAN.equals(typeTag)) print(((Number)tree.value).intValue() == 1 ? "true" : "false");
+ else if (CTC_BOT.equals(typeTag)) print("null");
+ else print("\"" + quoteChars(tree.value.toString()) + "\"");
+ }
+
+ @Override public void visitMethodDef(JCMethodDecl tree) {
+ boolean isConstructor = tree.name == name_init(tree.name);
+ if (isConstructor && (tree.mods.flags & GENERATEDCONSTR) != 0) return;
+ printDocComment(tree);
+ align();
+ print(tree.mods);
+ if (tree.typarams != null && tree.typarams.nonEmpty()) {
+ print("<");
+ print(tree.typarams, ", ");
+ print("> ");
+ }
+
+ if (isConstructor) {
+ print(currentTypeName == null ? "<init>" : currentTypeName);
+ } else {
+ print(tree.restype);
+ print(" ");
+ print(tree.name);
+ }
+
+ print("(");
+ boolean first = true;
+ for (JCVariableDecl param : tree.params) {
+ if (!first) print(", ");
+ first = false;
+ printVarDefInline(param);
+ }
+ print(")");
+
+ if (tree.thrown.nonEmpty()) {
+ print(" throws ");
+ print(tree.thrown, ", ");
+ }
+
+ if (tree.defaultValue != null) {
+ print(" default ");
+ print(tree.defaultValue);
+ }
+
+ if (tree.body != null) {
+ print(" ");
+ print(tree.body);
+ } else println(";", tree);
+ }
+
+ @Override public void visitSkip(JCSkip that) {
+ print(";");
+ }
+
+ @Override public void visitAnnotation(JCAnnotation tree) {
+ print("@");
+ print(tree.annotationType);
+ if (tree.args.isEmpty()) return;
+ print("(");
+ boolean done = false;
+ if (tree.args.length() == 1 && tree.args.get(0) instanceof JCAssign) {
+ JCAssign arg1 = (JCAssign) tree.args.get(0);
+ JCIdent arg1Name = arg1.lhs instanceof JCIdent ? ((JCIdent) arg1.lhs) : null;
+ if (arg1Name != null && arg1Name.name == name_value(arg1Name.name)) {
+ print(arg1.rhs);
+ done = true;
+ }
+ }
+ if (!done) print(tree.args, ", ");
+ print(")");
+ }
+
+ @Override public void visitTypeArray(JCArrayTypeTree tree) {
+ JCTree elem = tree.elemtype;
+ while (elem instanceof JCWildcard) elem = ((JCWildcard) elem).inner;
+ print(elem);
+ print("[]");
+ }
+
+ @Override public void visitNewArray(JCNewArray tree) {
+ JCTree elem = tree.elemtype;
+ int dims = 0;
+ if (elem != null) {
+ print("new ");
+
+ while (elem instanceof JCArrayTypeTree) {
+ dims++;
+ elem = ((JCArrayTypeTree) elem).elemtype;
+ }
+ print(elem);
+
+ for (JCExpression expr : tree.dims) {
+ print("[");
+ print(expr);
+ print("]");
+ }
+ }
+
+ for (int i = 0; i < dims; i++) print("[]");
+
+ if (tree.elems != null) {
+ if (elem != null) print("[] ");
+ print("{");
+ print(tree.elems, ", ");
+ print("}");
+ }
+ }
+
+ @Override public void visitNewClass(JCNewClass tree) {
+ if (tree.encl != null) {
+ print(tree.encl);
+ print(".");
+ }
+
+ print("new ");
+ if (!tree.typeargs.isEmpty()) {
+ print("<");
+ print(tree.typeargs, ", ");
+ print(">");
+ }
+ print(tree.clazz);
+ print("(");
+ print(tree.args, ", ");
+ print(")");
+ if (tree.def != null) {
+ Name previousTypeName = currentTypeName;
+ currentTypeName = null;
+ println(" {");
+ indent++;
+ print(tree.def.defs, "");
+ indent--;
+ aPrint("}");
+ currentTypeName = previousTypeName;
+ }
+ }
+
+ @Override public void visitIndexed(JCArrayAccess tree) {
+ print(tree.indexed);
+ print("[");
+ print(tree.index);
+ print("]");
+ }
+
+ @Override public void visitTypeIdent(JCPrimitiveTypeTree tree) {
+ TypeTag typeTag = typeTag(tree);
+
+ if (CTC_BYTE.equals(typeTag)) print("byte");
+ else if (CTC_CHAR.equals(typeTag)) print("char");
+ else if (CTC_SHORT.equals(typeTag)) print("short");
+ else if (CTC_INT.equals(typeTag)) print("int");
+ else if (CTC_LONG.equals(typeTag)) print("long");
+ else if (CTC_FLOAT.equals(typeTag)) print("float");
+ else if (CTC_DOUBLE.equals(typeTag)) print("double");
+ else if (CTC_BOOLEAN.equals(typeTag)) print("boolean");
+ else if (CTC_VOID.equals(typeTag)) print("void");
+ else print("error");
+ }
+
+ @Override public void visitLabelled(JCLabeledStatement tree) {
+ aPrint(tree.label);
+ print(":");
+ if (tree.body instanceof JCSkip || suppress(tree)) {
+ println(" ;", tree);
+ } else if (tree.body instanceof JCBlock) {
+ print(" ");
+ print(tree.body);
+ } else {
+ println(tree);
+ print(tree.body);
+ }
+ }
+
+ private long flagMod = -1L;
+ private static final long DEFAULT = 1L<<43;
+
+ @Override public void visitModifiers(JCModifiers tree) {
+ printAnnotations(tree.annotations, true);
+ printModifierKeywords(tree);
+ }
+
+ private void printAnnotations(List<JCAnnotation> annotations, boolean newlines) {
+ for (JCAnnotation ann : annotations) {
+ print(ann);
+ if (newlines) {
+ println();
+ align();
+ } else print(" ");
+ }
+ }
+
+ private void printModifierKeywords(JCModifiers tree) {
+ long v = flagMod & tree.flags;
+ flagMod = -1L;
+
+ if ((v & SYNTHETIC) != 0) print("/* synthetic */ ");
+ if ((v & PUBLIC) != 0) print("public ");
+ if ((v & PRIVATE) != 0) print("private ");
+ if ((v & PROTECTED) != 0) print("protected ");
+ if ((v & STATIC) != 0) print("static ");
+ if ((v & FINAL) != 0) print("final ");
+ if ((v & SYNCHRONIZED) != 0) print("synchronized ");
+ if ((v & VOLATILE) != 0) print("volatile ");
+ if ((v & TRANSIENT) != 0) print("transient ");
+ if ((v & NATIVE) != 0) print("native ");
+ if ((v & ABSTRACT) != 0) print("abstract ");
+ if ((v & STRICTFP) != 0) print("strictfp ");
+ if ((v & DEFAULT) != 0 && (v & INTERFACE) == 0) print("default ");
+ }
+
+ @Override public void visitSelect(JCFieldAccess tree) {
+ print(tree.selected);
+ print(".");
+ print(tree.name);
+ }
+
+ @Override public void visitIdent(JCIdent tree) {
+ print(tree.name);
+ }
+
+ @Override public void visitApply(JCMethodInvocation tree) {
+ if (tree.typeargs.nonEmpty()) {
+ if (tree.meth instanceof JCFieldAccess) {
+ JCFieldAccess fa = (JCFieldAccess) tree.meth;
+ print(fa.selected);
+ print(".<");
+ print(tree.typeargs, ", ");
+ print(">");
+ print(fa.name);
+ } else {
+ print("<");
+ print(tree.typeargs, ", ");
+ print(">");
+ print(tree.meth);
+ }
+ } else {
+ print(tree.meth);
+ }
+
+ print("(");
+ print(tree.args, ", ");
+ print(")");
+ }
+
+ @Override public void visitAssert(JCAssert tree) {
+ aPrint("assert ");
+ print(tree.cond);
+ if (tree.detail != null) {
+ print(" : ");
+ print(tree.detail);
+ }
+ println(";", tree);
+ }
+
+ @Override public void visitAssign(JCAssign tree) {
+ print(tree.lhs);
+ print(" = ");
+ print(tree.rhs);
+ }
+
+ @Override public void visitAssignop(JCAssignOp tree) {
+ print(tree.lhs);
+ String opname = operator(treeTag(tree));
+ print(" " + opname + " ");
+ print(tree.rhs);
+ }
+
+ private static final int PREFIX = 14;
+
+ @Override public void visitUnary(JCUnary tree) {
+ String op = operator(treeTag(tree));
+ if (treeTag(tree).getOperatorPrecedenceLevel() == PREFIX) {
+ print(op);
+ print(tree.arg);
+ } else {
+ print(tree.arg);
+ print(op);
+ }
+ }
+
+ @Override public void visitBinary(JCBinary tree) {
+ String op = operator(treeTag(tree));
+ print(tree.lhs);
+ print(" ");
+ print(op);
+ print(" ");
+ print(tree.rhs);
+ }
+
+ @Override public void visitTypeTest(JCInstanceOf tree) {
+ print(tree.expr);
+ print(" instanceof ");
+ print(tree.clazz);
+ }
+
+ @Override public void visitTypeCast(JCTypeCast tree) {
+ print("(");
+ print(tree.clazz);
+ print(") ");
+ print(tree.expr);
+ }
+
+ @Override public void visitBlock(JCBlock tree) {
+ if (tree.pos == Position.NOPOS && tree.stats.isEmpty()) return;
+ if (onNewLine) align();
+ if ((tree.flags & STATIC) != 0) print("static ");
+ println("{");
+ indent++;
+ print(tree.stats, "");
+ consumeComments(endPos(tree));
+ indent--;
+ aPrintln("}", tree);
+ }
+
+ @Override public void visitBreak(JCBreak tree) {
+ aPrint("break");
+ if (tree.label != null) {
+ print(" ");
+ print(tree.label);
+ }
+ println(";", tree);
+ }
+
+ @Override public void visitContinue(JCContinue tree) {
+ aPrint("continue");
+ if (tree.label != null) {
+ print(" ");
+ print(tree.label);
+ }
+ println(";", tree);
+ }
+
+ @Override public void visitConditional(JCConditional tree) {
+ print(tree.cond);
+ print(" ? ");
+ print(tree.truepart);
+ print(" : ");
+ print(tree.falsepart);
+ }
+
+ @Override public void visitParens(JCParens tree) {
+ print("(");
+ print(tree.expr);
+ print(")");
+ }
+
+ @Override public void visitReturn(JCReturn tree) {
+ aPrint("return");
+ if (tree.expr != null) {
+ print(" ");
+ print(tree.expr);
+ }
+ println(";", tree);
+ }
+
+ @Override public void visitThrow(JCThrow tree) {
+ aPrint("throw ");
+ print(tree.expr);
+ println(";", tree);
+ }
+
+ @Override public void visitWhileLoop(JCWhileLoop tree) {
+ aPrint("while ");
+ if (tree.cond instanceof JCParens) {
+ print(tree.cond);
+ } else {
+ print("(");
+ print(tree.cond);
+ print(")");
+ }
+ print(" ");
+ print(tree.body);
+ // make sure to test while (true) ; and while(true){} and while(true) x = 5;
+ }
+
+ @Override public void visitForLoop(JCForLoop tree) {
+ aPrint("for (");
+ if (tree.init.nonEmpty()) {
+ if (tree.init.head instanceof JCVariableDecl) {
+ boolean first = true;
+ for (JCStatement i : tree.init) {
+ JCVariableDecl vd = (JCVariableDecl) i;
+ if (first) {
+ printVarDefInline(vd);
+ } else {
+ print(", ");
+ print(vd.name);
+ if (vd.init != null) {
+ print(" = ");
+ print(vd.init);
+ }
+ }
+ first = false;
+ }
+ } else {
+ print(tree.init, ", ");
+ }
+ }
+ print("; ");
+ if (tree.cond != null) print(tree.cond);
+ print("; ");
+ boolean first = true;
+ for (JCExpressionStatement exprStatement : tree.step) {
+ if (!first) print(", ");
+ first = false;
+ print(exprStatement.expr);
+ }
+ print(") ");
+ print(tree.body);
+ }
+
+ @Override public void visitForeachLoop(JCEnhancedForLoop tree) {
+ aPrint("for (");
+ printVarDefInline(tree.var);
+ print(" : ");
+ print(tree.expr);
+ print(") ");
+ print(tree.body);
+ }
+
+ @Override public void visitIf(JCIf tree) {
+ aPrint("if ");
+ if (tree.cond instanceof JCParens) {
+ print(tree.cond);
+ } else {
+ print("(");
+ print(tree.cond);
+ print(")");
+ }
+ print(" ");
+ if (tree.thenpart instanceof JCBlock) {
+ println("{");
+ indent++;
+ print(((JCBlock) tree.thenpart).stats, "");
+ indent--;
+ if (tree.elsepart == null) {
+ aPrintln("}", tree);
+ } else {
+ aPrint("}");
+ }
+ } else {
+ print(tree.thenpart);
+ }
+ if (tree.elsepart != null) {
+ aPrint(" else ");
+ print(tree.elsepart);
+ }
+ }
+
+ @Override public void visitExec(JCExpressionStatement tree) {
+ align();
+ print(tree.expr);
+ println(";", tree);
+ }
+
+ @Override public void visitDoLoop(JCDoWhileLoop tree) {
+ aPrint("do ");
+ print(tree.body);
+ print(" while ");
+ if (tree.cond instanceof JCParens) {
+ print(tree.cond);
+ } else {
+ print("(");
+ print(tree.cond);
+ print(")");
+ }
+ println(";", tree);
+ }
+
+ @Override public void visitSynchronized(JCSynchronized tree) {
+ aPrint("synchronized ");
+ if (tree.lock instanceof JCParens) {
+ print(tree.lock);
+ } else {
+ print("(");
+ print(tree.lock);
+ print(")");
+ }
+ print(" ");
+ print(tree.body);
+ }
+
+ @Override public void visitCase(JCCase tree) {
+ if (tree.pat == null) {
+ aPrint("default");
+ } else {
+ aPrint("case ");
+ print(tree.pat);
+ }
+ println(": ");
+ indent++;
+ print(tree.stats, "\n");
+ indent--;
+ }
+
+ @Override public void visitCatch(JCCatch tree) {
+ print(" catch (");
+ print(tree.param);
+ print(") ");
+ print(tree.body);
+ }
+
+ @Override public void visitSwitch(JCSwitch tree) {
+ aPrint("switch ");
+ if (tree.selector instanceof JCParens) {
+ print(tree.selector);
+ } else {
+ print("(");
+ print(tree.selector);
+ print(")");
+ }
+ println(" {");
+ print(tree.cases, "\n");
+ aPrintln("}", tree);
+ }
+
+ @Override public void visitTry(JCTry tree) {
+ aPrint("try ");
+ List<?> resources = readObject(tree, "resources", List.nil());
+ int len = resources.length();
+ switch (len) {
+ case 0:
+ break;
+ case 1:
+ print("(");
+ JCVariableDecl decl = (JCVariableDecl) resources.get(0);
+ flagMod = -1L & ~FINAL;
+ printVarDefInline(decl);
+ print(") ");
+ break;
+ default:
+ println("(");
+ indent++;
+ int c = 0;
+ for (Object i : resources) {
+ align();
+ flagMod = -1L & ~FINAL;
+ printVarDefInline((JCVariableDecl) i);
+ if (++c == len) {
+ print(") ");
+ } else {
+ println(";", (JCTree) i);
+ }
+ }
+ }
+ println("{");
+ indent++;
+ for (JCStatement stat : tree.body.stats) print(stat);
+ indent--;
+ aPrint("}");
+ for (JCCatch catchBlock : tree.catchers) {
+ printCatch(catchBlock);
+ }
+ if (tree.finalizer != null) {
+ println(" finally {");
+ indent++;
+ for (JCStatement stat : tree.finalizer.stats) print(stat);
+ indent--;
+ aPrint("}");
+ }
+ println(tree);
+ }
+
+ private void printCatch(JCCatch catchBlock) {
+ print(" catch (");
+ printVarDefInline(catchBlock.param); // ExprType1 | ExprType2 handled via JCTypeUnion.
+ println(") {");
+ indent++;
+ for (JCStatement stat : catchBlock.body.stats) print(stat);
+ indent--;
+ aPrint("}");
+ }
+
+ public void visitErroneous(JCErroneous tree) {
+ print("(ERROR)");
+ }
+
+ private static String operator(TreeTag tag) {
+ String op = OPERATORS.get(tag);
+ if (op == null) return "(?op?)";
+ return op;
+ }
+
+ private static String quoteChars(String s) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < s.length(); i++) sb.append(quoteChar(s.charAt(i)));
+ return sb.toString();
+ }
+
+ private static String quoteChar(char ch) {
+ switch (ch) {
+ case '\b': return "\\b";
+ case '\f': return "\\f";
+ case '\n': return "\\n";
+ case '\r': return "\\r";
+ case '\t': return "\\t";
+ case '\'': return "\\'";
+ case '\"': return "\\\"";
+ case '\\': return "\\\\";
+ default:
+ if (ch < 32) return String.format("\\%03o", (int) ch);
+ return String.valueOf(ch);
+ }
+ }
+
+ private static final Method getExtendsClause, getEndPosition, storeEnd;
+
+ static {
+ getExtendsClause = getMethod(JCClassDecl.class, "getExtendsClause", new Class<?>[0]);
+ getExtendsClause.setAccessible(true);
+
+ if (getJavaCompilerVersion() < 8) {
+ getEndPosition = getMethod(DiagnosticPosition.class, "getEndPosition", java.util.Map.class);
+ storeEnd = getMethod(java.util.Map.class, "put", Object.class, Object.class);
+ } else {
+ getEndPosition = getMethod(DiagnosticPosition.class, "getEndPosition", "com.sun.tools.javac.tree.EndPosTable");
+ Method storeEndMethodTemp;
+ Class<?> endPosTable;
+ try {
+ endPosTable = Class.forName("com.sun.tools.javac.tree.EndPosTable");
+ } catch (ClassNotFoundException ex) {
+ throw sneakyThrow(ex);
+ }
+ try {
+ storeEndMethodTemp = endPosTable.getMethod("storeEnd", JCTree.class, int.class);
+ } catch (NoSuchMethodException e) {
+ try {
+ endPosTable = Class.forName("com.sun.tools.javac.parser.JavacParser$AbstractEndPosTable");
+ storeEndMethodTemp = endPosTable.getDeclaredMethod("storeEnd", JCTree.class, int.class);
+ } catch (NoSuchMethodException ex) {
+ throw sneakyThrow(ex);
+ } catch (ClassNotFoundException ex) {
+ throw sneakyThrow(ex);
+ }
+ }
+ storeEnd = storeEndMethodTemp;
+ }
+ getEndPosition.setAccessible(true);
+ storeEnd.setAccessible(true);
+ }
+
+ private static Method getMethod(Class<?> clazz, String name, Class<?>... paramTypes) {
+ try {
+ return clazz.getMethod(name, paramTypes);
+ } catch (NoSuchMethodException e) {
+ throw sneakyThrow(e);
+ }
+ }
+
+ private static Method getMethod(Class<?> clazz, String name, String... paramTypes) {
+ try {
+ Class<?>[] c = new Class[paramTypes.length];
+ for (int i = 0; i < paramTypes.length; i++) c[i] = Class.forName(paramTypes[i]);
+ return clazz.getMethod(name, c);
+ } catch (NoSuchMethodException e) {
+ throw sneakyThrow(e);
+ } catch (ClassNotFoundException e) {
+ throw sneakyThrow(e);
+ }
+ }
+
+ public static JCTree getExtendsClause(JCClassDecl decl) {
+ try {
+ return (JCTree) getExtendsClause.invoke(decl);
+ } catch (IllegalAccessException e) {
+ throw sneakyThrow(e);
+ } catch (InvocationTargetException e) {
+ throw sneakyThrow(e.getCause());
+ }
+ }
+
+ static RuntimeException sneakyThrow(Throwable t) {
+ if (t == null) throw new NullPointerException("t");
+ PrettyPrinter.<RuntimeException>sneakyThrow0(t);
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T extends Throwable> void sneakyThrow0(Throwable t) throws T {
+ throw (T)t;
+ }
+
+ private static final Map<Class<?>, Map<String, Field>> reflectionCache = new HashMap<Class<?>, Map<String, Field>>();
+
+ @SuppressWarnings("unchecked")
+ private <T> T readObject(JCTree tree, String fieldName, T defaultValue) {
+ Class<?> tClass = tree.getClass();
+ Map<String, Field> c = reflectionCache.get(tClass);
+ if (c == null) reflectionCache.put(tClass, c = new HashMap<String, Field>());
+ Field f = c.get(fieldName);
+ if (f == null) {
+ try {
+ f = tClass.getDeclaredField(fieldName);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ f.setAccessible(true);
+ c.put(fieldName, f);
+ }
+
+ try {
+ return (T) f.get(tree);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ @Override public void visitTree(JCTree tree) {
+ String simpleName = tree.getClass().getSimpleName();
+ if ("JCTypeUnion".equals(simpleName)) {
+ List<JCExpression> types = readObject(tree, "alternatives", List.<JCExpression>nil());
+ print(types, " | ");
+ return;
+ } else if ("JCTypeIntersection".equals(simpleName)) {
+ print(readObject(tree, "bounds", List.<JCExpression>nil()), " & ");
+ return;
+ } else if ("JCMemberReference".equals(simpleName)) {
+ printMemberReference0(tree);
+ return;
+ } else if ("JCLambda".equals(simpleName)) {
+ printLambda0(tree);
+ return;
+ } else if ("JCAnnotatedType".equals(simpleName)) {
+ printAnnotatedType0(tree);
+ return;
+ }
+
+ throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree);
+ }
+
+ private void printMemberReference0(JCTree tree) {
+ print(readObject(tree, "expr", (JCExpression) null));
+ print("::");
+ List<JCExpression> typeArgs = readObject(tree, "typeargs", List.<JCExpression>nil());
+ if (typeArgs != null && !typeArgs.isEmpty()) {
+ print("<");
+ print(typeArgs, ", ");
+ print(">");
+ }
+ print(readObject(tree, "mode", new Object()).toString().equals("INVOKE") ? readObject(tree, "name", (Name) null) : "new");
+ }
+
+ private void printLambda0(JCTree tree) {
+ List<JCVariableDecl> params = readObject(tree, "params", List.<JCVariableDecl>nil());
+ boolean explicit = true;
+ int paramLength = params.size();
+ if (paramLength != 1) print("(");
+ try {
+ explicit = readObject(tree, "paramKind", new Object()).toString().equals("EXPLICIT");
+ } catch (Exception e) {}
+ if (explicit) {
+ boolean first = true;
+ for (JCVariableDecl vd : params) {
+ if (!first) print(", ");
+ first = false;
+ printVarDefInline(vd);
+ }
+ } else {
+ String sep = "";
+ for (JCVariableDecl param : params) {
+ print(sep);
+ print(param.name);
+ sep = ", ";
+ }
+ }
+ if (paramLength != 1) print(")");
+ print(" -> ");
+ JCTree body = readObject(tree, "body", (JCTree) null);
+ if (body instanceof JCBlock) {
+ println("{");
+ indent++;
+ print(((JCBlock) body).stats, "");
+ indent--;
+ aPrint("}");
+ } else {
+ print(body);
+ }
+ }
+
+ private void printAnnotatedType0(JCTree tree) {
+ JCTree underlyingType = readObject(tree, "underlyingType", (JCTree) null);
+ if (underlyingType instanceof JCFieldAccess) {
+ print(((JCFieldAccess) underlyingType).selected);
+ print(".");
+ print(readObject(tree, "annotations", List.<JCExpression>nil()), " ");
+ print(" ");
+ print(((JCFieldAccess) underlyingType).name);
+ } else {
+ print(readObject(tree, "annotations", List.<JCExpression>nil()), " ");
+ print(" ");
+ print(underlyingType);
+ }
+ }
+}
diff --git a/test/pretty/resource/after/Cast.java b/test/pretty/resource/after/Cast.java
index 95237b0f..e32150c3 100644
--- a/test/pretty/resource/after/Cast.java
+++ b/test/pretty/resource/after/Cast.java
@@ -1,6 +1,6 @@
import java.util.*;
public class Cast {
public void test(List<?> list) {
- RandomAccess r = (/*before*/ RandomAccess /*after*/)list;
+ RandomAccess r = (/*before*/ RandomAccess /*after*/) list;
}
} \ No newline at end of file
diff --git a/test/pretty/resource/after/CastWithIntersection.java b/test/pretty/resource/after/CastWithIntersection.java
index 2eebdee1..dc0904f6 100644
--- a/test/pretty/resource/after/CastWithIntersection.java
+++ b/test/pretty/resource/after/CastWithIntersection.java
@@ -1,6 +1,6 @@
import java.util.*;
public class CastWithIntersection {
public void test(List<?> list) {
- RandomAccess r = (RandomAccess & java.io.Serializable)list;
+ RandomAccess r = (RandomAccess & java.io.Serializable) list;
}
} \ No newline at end of file
diff --git a/test/pretty/resource/after/DefaultMethod.java b/test/pretty/resource/after/DefaultMethod.java
index 864ba60f..fe9594b8 100644
--- a/test/pretty/resource/after/DefaultMethod.java
+++ b/test/pretty/resource/after/DefaultMethod.java
@@ -3,6 +3,6 @@ interface DefaultMethod {
default boolean isEmpty() {
return size() == 0;
}
- default strictfp void run() {
+ strictfp default void run() {
}
} \ No newline at end of file
diff --git a/test/pretty/resource/after/Enum.java b/test/pretty/resource/after/Enum.java
index dd738b5b..a3b2b643 100644
--- a/test/pretty/resource/after/Enum.java
+++ b/test/pretty/resource/after/Enum.java
@@ -1,13 +1,8 @@
enum Ranks {
- CLUBS,
- HEARTS,
- DIAMONDS,
- SPADES;
+ CLUBS, HEARTS, DIAMONDS, SPADES;
}
enum Complex {
- RED("ff0000"),
- GREEN("00ff00"),
- BLUE("0000f");
+ RED("ff0000"), GREEN("00ff00"), BLUE("0000f");
private final String webColour;
Complex(String webColour) {
this.webColour = webColour;
diff --git a/test/pretty/resource/after/Interfaces.java b/test/pretty/resource/after/Interfaces.java
index 6c0a6770..f7f386c0 100644
--- a/test/pretty/resource/after/Interfaces.java
+++ b/test/pretty/resource/after/Interfaces.java
@@ -1,10 +1,7 @@
@SuppressWarnings("all")
interface Interfaces {
enum Ranks {
- CLUBS,
- HEARTS,
- DIAMONDS,
- SPADES;
+ CLUBS, HEARTS, DIAMONDS, SPADES;
}
int x = 10;
void y();
diff --git a/test/pretty/resource/before/Cast.java b/test/pretty/resource/before/Cast.java
index 95237b0f..e32150c3 100644
--- a/test/pretty/resource/before/Cast.java
+++ b/test/pretty/resource/before/Cast.java
@@ -1,6 +1,6 @@
import java.util.*;
public class Cast {
public void test(List<?> list) {
- RandomAccess r = (/*before*/ RandomAccess /*after*/)list;
+ RandomAccess r = (/*before*/ RandomAccess /*after*/) list;
}
} \ No newline at end of file
diff --git a/test/transform/resource/after-delombok/Accessors.java b/test/transform/resource/after-delombok/Accessors.java
index 3f4698e0..a04ea171 100644
--- a/test/transform/resource/after-delombok/Accessors.java
+++ b/test/transform/resource/after-delombok/Accessors.java
@@ -81,8 +81,8 @@ class AccessorsPrefix3 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof AccessorsPrefix3)) return false;
- final AccessorsPrefix3 other = (AccessorsPrefix3)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final AccessorsPrefix3 other = (AccessorsPrefix3) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
final java.lang.Object this$fName = this.getName();
final java.lang.Object other$fName = other.getName();
if (this$fName == null ? other$fName != null : !this$fName.equals(other$fName)) return false;
diff --git a/test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java b/test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java
index a47fa244..ff5278ff 100644
--- a/test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java
+++ b/test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java
@@ -5,8 +5,8 @@ class ConflictingStaticConstructorNames {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof ConflictingStaticConstructorNames)) return false;
- final ConflictingStaticConstructorNames other = (ConflictingStaticConstructorNames)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final ConflictingStaticConstructorNames other = (ConflictingStaticConstructorNames) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
diff --git a/test/transform/resource/after-delombok/DataConfiguration.java b/test/transform/resource/after-delombok/DataConfiguration.java
index b83204b8..aadb35b6 100644
--- a/test/transform/resource/after-delombok/DataConfiguration.java
+++ b/test/transform/resource/after-delombok/DataConfiguration.java
@@ -16,8 +16,8 @@ class DataConfiguration {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof DataConfiguration)) return false;
- final DataConfiguration other = (DataConfiguration)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final DataConfiguration other = (DataConfiguration) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getX() != other.getX()) return false;
return true;
}
diff --git a/test/transform/resource/after-delombok/DataExtended.java b/test/transform/resource/after-delombok/DataExtended.java
index 25180429..175738ad 100644
--- a/test/transform/resource/after-delombok/DataExtended.java
+++ b/test/transform/resource/after-delombok/DataExtended.java
@@ -20,8 +20,8 @@ class DataExtended {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof DataExtended)) return false;
- final DataExtended other = (DataExtended)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final DataExtended other = (DataExtended) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getX() != other.getX()) return false;
return true;
}
diff --git a/test/transform/resource/after-delombok/DataIgnore.java b/test/transform/resource/after-delombok/DataIgnore.java
index 0d40a5a8..d5a3d81e 100644
--- a/test/transform/resource/after-delombok/DataIgnore.java
+++ b/test/transform/resource/after-delombok/DataIgnore.java
@@ -18,8 +18,8 @@ class DataIgnore {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof DataIgnore)) return false;
- final DataIgnore other = (DataIgnore)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final DataIgnore other = (DataIgnore) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getX() != other.getX()) return false;
return true;
}
diff --git a/test/transform/resource/after-delombok/DataOnLocalClass.java b/test/transform/resource/after-delombok/DataOnLocalClass.java
index 44b069fd..0e15ab4c 100644
--- a/test/transform/resource/after-delombok/DataOnLocalClass.java
+++ b/test/transform/resource/after-delombok/DataOnLocalClass.java
@@ -29,8 +29,8 @@ class DataOnLocalClass1 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof Local)) return false;
- final Local other = (Local)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final Local other = (Local) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getX() != other.getX()) return false;
final java.lang.Object this$name = this.getName();
final java.lang.Object other$name = other.getName();
@@ -97,8 +97,8 @@ class DataOnLocalClass2 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof Local.InnerLocal)) return false;
- final InnerLocal other = (InnerLocal)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final InnerLocal other = (InnerLocal) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
final java.lang.Object this$name = this.getName();
final java.lang.Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
@@ -142,8 +142,8 @@ class DataOnLocalClass2 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof Local)) return false;
- final Local other = (Local)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final Local other = (Local) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getX() != other.getX()) return false;
return true;
}
diff --git a/test/transform/resource/after-delombok/DataPlain.java b/test/transform/resource/after-delombok/DataPlain.java
index cfb72656..ccebc55e 100644
--- a/test/transform/resource/after-delombok/DataPlain.java
+++ b/test/transform/resource/after-delombok/DataPlain.java
@@ -28,8 +28,8 @@ class Data1 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof Data1)) return false;
- final Data1 other = (Data1)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final Data1 other = (Data1) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getX() != other.getX()) return false;
final java.lang.Object this$name = this.getName();
final java.lang.Object other$name = other.getName();
@@ -89,8 +89,8 @@ class Data2 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof Data2)) return false;
- final Data2 other = (Data2)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final Data2 other = (Data2) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getX() != other.getX()) return false;
final java.lang.Object this$name = this.getName();
final java.lang.Object other$name = other.getName();
@@ -150,7 +150,7 @@ final class Data3 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof Data3)) return false;
- final Data3 other = (Data3)o;
+ final Data3 other = (Data3) o;
if (this.getX() != other.getX()) return false;
final java.lang.Object this$name = this.getName();
final java.lang.Object other$name = other.getName();
@@ -201,8 +201,8 @@ final class Data4 extends java.util.Timer {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof Data4)) return false;
- final Data4 other = (Data4)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final Data4 other = (Data4) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (!super.equals(o)) return false;
if (this.getX() != other.getX()) return false;
return true;
@@ -234,8 +234,8 @@ class Data5 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof Data5)) return false;
- final Data5 other = (Data5)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final Data5 other = (Data5) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
diff --git a/test/transform/resource/after-delombok/DataWithGetter.java b/test/transform/resource/after-delombok/DataWithGetter.java
index f849e0f8..fb51e262 100644
--- a/test/transform/resource/after-delombok/DataWithGetter.java
+++ b/test/transform/resource/after-delombok/DataWithGetter.java
@@ -24,8 +24,8 @@ class DataWithGetter {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof DataWithGetter)) return false;
- final DataWithGetter other = (DataWithGetter)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final DataWithGetter other = (DataWithGetter) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getX() != other.getX()) return false;
if (this.getY() != other.getY()) return false;
final java.lang.Object this$z = this.getZ();
diff --git a/test/transform/resource/after-delombok/DataWithGetterNone.java b/test/transform/resource/after-delombok/DataWithGetterNone.java
index c46be723..e332db02 100644
--- a/test/transform/resource/after-delombok/DataWithGetterNone.java
+++ b/test/transform/resource/after-delombok/DataWithGetterNone.java
@@ -24,8 +24,8 @@ class DataWithGetterNone {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof DataWithGetterNone)) return false;
- final DataWithGetterNone other = (DataWithGetterNone)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final DataWithGetterNone other = (DataWithGetterNone) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.x != other.x) return false;
if (this.y != other.y) return false;
final java.lang.Object this$z = this.z;
diff --git a/test/transform/resource/after-delombok/DelegateOnGetter.java b/test/transform/resource/after-delombok/DelegateOnGetter.java
index 5b5090e9..1d25dcc0 100644
--- a/test/transform/resource/after-delombok/DelegateOnGetter.java
+++ b/test/transform/resource/after-delombok/DelegateOnGetter.java
@@ -12,7 +12,7 @@ class DelegateOnGetter {
synchronized (this.bar) {
value = this.bar.get();
if (value == null) {
- final Bar actualValue = new Bar(){
+ final Bar actualValue = new Bar() {
public void setList(java.util.ArrayList<String> list) {
}
public int getInt() {
@@ -24,7 +24,7 @@ class DelegateOnGetter {
}
}
}
- return (Bar)(value == this.bar ? null : value);
+ return (Bar) (value == this.bar ? null : value);
}
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
diff --git a/test/transform/resource/after-delombok/EqualsAndHashCode.java b/test/transform/resource/after-delombok/EqualsAndHashCode.java
index d0ed4067..7ade594a 100644
--- a/test/transform/resource/after-delombok/EqualsAndHashCode.java
+++ b/test/transform/resource/after-delombok/EqualsAndHashCode.java
@@ -10,8 +10,8 @@ class EqualsAndHashCode {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof EqualsAndHashCode)) return false;
- final EqualsAndHashCode other = (EqualsAndHashCode)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final EqualsAndHashCode other = (EqualsAndHashCode) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.x != other.x) return false;
if (!java.util.Arrays.equals(this.y, other.y)) return false;
if (!java.util.Arrays.deepEquals(this.z, other.z)) return false;
@@ -56,7 +56,7 @@ final class EqualsAndHashCode2 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof EqualsAndHashCode2)) return false;
- final EqualsAndHashCode2 other = (EqualsAndHashCode2)o;
+ final EqualsAndHashCode2 other = (EqualsAndHashCode2) o;
if (this.x != other.x) return false;
if (this.y != other.y) return false;
if (java.lang.Float.compare(this.f, other.f) != 0) return false;
@@ -72,10 +72,10 @@ final class EqualsAndHashCode2 {
int result = 1;
result = result * PRIME + this.x;
final long $y = this.y;
- result = result * PRIME + (int)($y >>> 32 ^ $y);
+ result = result * PRIME + (int) ($y >>> 32 ^ $y);
result = result * PRIME + java.lang.Float.floatToIntBits(this.f);
final long $d = java.lang.Double.doubleToLongBits(this.d);
- result = result * PRIME + (int)($d >>> 32 ^ $d);
+ result = result * PRIME + (int) ($d >>> 32 ^ $d);
result = result * PRIME + (this.b ? 79 : 97);
return result;
}
@@ -87,8 +87,8 @@ final class EqualsAndHashCode3 extends EqualsAndHashCode {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof EqualsAndHashCode3)) return false;
- final EqualsAndHashCode3 other = (EqualsAndHashCode3)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final EqualsAndHashCode3 other = (EqualsAndHashCode3) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
@@ -111,8 +111,8 @@ class EqualsAndHashCode4 extends EqualsAndHashCode {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof EqualsAndHashCode4)) return false;
- final EqualsAndHashCode4 other = (EqualsAndHashCode4)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final EqualsAndHashCode4 other = (EqualsAndHashCode4) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (!super.equals(o)) return false;
return true;
}
diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java b/test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java
index 5c9316b4..6978bf00 100644
--- a/test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java
+++ b/test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java
@@ -21,8 +21,8 @@ final class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithE
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof EqualsAndHashCodeWithExistingMethods3)) return false;
- final EqualsAndHashCodeWithExistingMethods3 other = (EqualsAndHashCodeWithExistingMethods3)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final EqualsAndHashCodeWithExistingMethods3 other = (EqualsAndHashCodeWithExistingMethods3) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (!super.equals(o)) return false;
if (this.x != other.x) return false;
return true;
diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeWithOnParam.java b/test/transform/resource/after-delombok/EqualsAndHashCodeWithOnParam.java
index 69b69d29..4cf00601 100644
--- a/test/transform/resource/after-delombok/EqualsAndHashCodeWithOnParam.java
+++ b/test/transform/resource/after-delombok/EqualsAndHashCodeWithOnParam.java
@@ -13,8 +13,8 @@ class EqualsAndHashCodeWithOnParam {
public boolean equals(@Nullable final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof EqualsAndHashCodeWithOnParam)) return false;
- final EqualsAndHashCodeWithOnParam other = (EqualsAndHashCodeWithOnParam)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final EqualsAndHashCodeWithOnParam other = (EqualsAndHashCodeWithOnParam) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.x != other.x) return false;
if (!java.util.Arrays.equals(this.y, other.y)) return false;
if (!java.util.Arrays.deepEquals(this.z, other.z)) return false;
diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeWithSomeExistingMethods.java b/test/transform/resource/after-delombok/EqualsAndHashCodeWithSomeExistingMethods.java
index 37eeb8df..b3a1fb0d 100644
--- a/test/transform/resource/after-delombok/EqualsAndHashCodeWithSomeExistingMethods.java
+++ b/test/transform/resource/after-delombok/EqualsAndHashCodeWithSomeExistingMethods.java
@@ -28,8 +28,8 @@ class EqualsAndHashCodeWithSomeExistingMethods2 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof EqualsAndHashCodeWithSomeExistingMethods2)) return false;
- final EqualsAndHashCodeWithSomeExistingMethods2 other = (EqualsAndHashCodeWithSomeExistingMethods2)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final EqualsAndHashCodeWithSomeExistingMethods2 other = (EqualsAndHashCodeWithSomeExistingMethods2) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.x != other.x) return false;
return true;
}
@@ -75,8 +75,8 @@ class EqualsAndHashCodeWithNoExistingMethods {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof EqualsAndHashCodeWithNoExistingMethods)) return false;
- final EqualsAndHashCodeWithNoExistingMethods other = (EqualsAndHashCodeWithNoExistingMethods)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final EqualsAndHashCodeWithNoExistingMethods other = (EqualsAndHashCodeWithNoExistingMethods) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.x != other.x) return false;
return true;
}
diff --git a/test/transform/resource/after-delombok/GetterLazy.java b/test/transform/resource/after-delombok/GetterLazy.java
index 9c7db37b..2ea3cbf2 100644
--- a/test/transform/resource/after-delombok/GetterLazy.java
+++ b/test/transform/resource/after-delombok/GetterLazy.java
@@ -16,6 +16,6 @@ class GetterLazy {
}
}
}
- return (ValueType)(value == this.fieldName ? null : value);
+ return (ValueType) (value == this.fieldName ? null : value);
}
}
diff --git a/test/transform/resource/after-delombok/GetterLazyBoolean.java b/test/transform/resource/after-delombok/GetterLazyBoolean.java
index f9a42e66..41349447 100644
--- a/test/transform/resource/after-delombok/GetterLazyBoolean.java
+++ b/test/transform/resource/after-delombok/GetterLazyBoolean.java
@@ -10,8 +10,8 @@ class GetterLazyBoolean {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof GetterLazyBoolean)) return false;
- final GetterLazyBoolean other = (GetterLazyBoolean)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final GetterLazyBoolean other = (GetterLazyBoolean) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.isBooleanValue() != other.isBooleanValue()) return false;
return true;
}
@@ -49,7 +49,7 @@ class GetterLazyBoolean {
}
}
}
- return (java.lang.Boolean)value;
+ return (java.lang.Boolean) value;
}
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
@@ -65,6 +65,6 @@ class GetterLazyBoolean {
}
}
}
- return (java.lang.Boolean)value;
+ return (java.lang.Boolean) value;
}
}
diff --git a/test/transform/resource/after-delombok/GetterLazyEahcToString.java b/test/transform/resource/after-delombok/GetterLazyEahcToString.java
index db075cde..973eb6f1 100644
--- a/test/transform/resource/after-delombok/GetterLazyEahcToString.java
+++ b/test/transform/resource/after-delombok/GetterLazyEahcToString.java
@@ -9,8 +9,8 @@ class GetterLazyEahcToString {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof GetterLazyEahcToString)) return false;
- final GetterLazyEahcToString other = (GetterLazyEahcToString)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final GetterLazyEahcToString other = (GetterLazyEahcToString) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
final java.lang.Object this$value = this.getValue();
final java.lang.Object other$value = other.getValue();
if (this$value == null ? other$value != null : !this$value.equals(other$value)) return false;
@@ -62,11 +62,10 @@ class GetterLazyEahcToString {
}
}
}
- return (String)(value == this.value ? null : value);
+ return (String) (value == this.value ? null : value);
}
@java.lang.SuppressWarnings("all")
-
@javax.annotation.Generated("lombok")
public String getValue2() {
return this.value2;
diff --git a/test/transform/resource/after-delombok/GetterLazyNative.java b/test/transform/resource/after-delombok/GetterLazyNative.java
index 50e3ff2b..0d88558d 100644
--- a/test/transform/resource/after-delombok/GetterLazyNative.java
+++ b/test/transform/resource/after-delombok/GetterLazyNative.java
@@ -22,7 +22,7 @@ class GetterLazyNative {
}
}
}
- return (java.lang.Boolean)value;
+ return (java.lang.Boolean) value;
}
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
@@ -38,7 +38,7 @@ class GetterLazyNative {
}
}
}
- return (java.lang.Byte)value;
+ return (java.lang.Byte) value;
}
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
@@ -54,7 +54,7 @@ class GetterLazyNative {
}
}
}
- return (java.lang.Short)value;
+ return (java.lang.Short) value;
}
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
@@ -70,7 +70,7 @@ class GetterLazyNative {
}
}
}
- return (java.lang.Integer)value;
+ return (java.lang.Integer) value;
}
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
@@ -86,7 +86,7 @@ class GetterLazyNative {
}
}
}
- return (java.lang.Long)value;
+ return (java.lang.Long) value;
}
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
@@ -102,7 +102,7 @@ class GetterLazyNative {
}
}
}
- return (java.lang.Float)value;
+ return (java.lang.Float) value;
}
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
@@ -118,7 +118,7 @@ class GetterLazyNative {
}
}
}
- return (java.lang.Double)value;
+ return (java.lang.Double) value;
}
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
@@ -134,7 +134,7 @@ class GetterLazyNative {
}
}
}
- return (java.lang.Character)value;
+ return (java.lang.Character) value;
}
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
@@ -144,12 +144,12 @@ class GetterLazyNative {
synchronized (this.intArrayField) {
value = this.intArrayField.get();
if (value == null) {
- final int[] actualValue = new int[]{1};
+ final int[] actualValue = new int[] {1};
value = actualValue == null ? this.intArrayField : actualValue;
this.intArrayField.set(value);
}
}
}
- return (int[])(value == this.intArrayField ? null : value);
+ return (int[]) (value == this.intArrayField ? null : value);
}
}
diff --git a/test/transform/resource/after-delombok/GetterSetterJavadoc.java b/test/transform/resource/after-delombok/GetterSetterJavadoc.java
index 45a99c9d..f156de92 100644
--- a/test/transform/resource/after-delombok/GetterSetterJavadoc.java
+++ b/test/transform/resource/after-delombok/GetterSetterJavadoc.java
@@ -33,8 +33,8 @@ class GetterSetterJavadoc1 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof GetterSetterJavadoc1)) return false;
- final GetterSetterJavadoc1 other = (GetterSetterJavadoc1)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final GetterSetterJavadoc1 other = (GetterSetterJavadoc1) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getFieldName() != other.getFieldName()) return false;
return true;
}
diff --git a/test/transform/resource/after-delombok/InjectField.java b/test/transform/resource/after-delombok/InjectField.java
index 55390a60..8215f8d0 100644
--- a/test/transform/resource/after-delombok/InjectField.java
+++ b/test/transform/resource/after-delombok/InjectField.java
@@ -1,8 +1,7 @@
import java.util.logging.Level;
enum InjectField1 {
- A,
- B;
+ A, B;
@java.lang.SuppressWarnings("all")
diff --git a/test/transform/resource/after-delombok/LoggerSlf4jTypes.java b/test/transform/resource/after-delombok/LoggerSlf4jTypes.java
index e987d807..a4e13afc 100644
--- a/test/transform/resource/after-delombok/LoggerSlf4jTypes.java
+++ b/test/transform/resource/after-delombok/LoggerSlf4jTypes.java
@@ -3,7 +3,7 @@ interface LoggerSlf4jTypesInterface {
@interface LoggerSlf4jTypesAnnotation {
}
enum LoggerSlf4jTypesEnum {
-;
+ ;
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4jTypesEnum.class);
diff --git a/test/transform/resource/after-delombok/UtilityClass.java b/test/transform/resource/after-delombok/UtilityClass.java
index 7731b49c..6b3c1761 100644
--- a/test/transform/resource/after-delombok/UtilityClass.java
+++ b/test/transform/resource/after-delombok/UtilityClass.java
@@ -24,8 +24,7 @@ class UtilityInner {
}
}
enum UtilityInsideEnum {
- FOO,
- BAR;
+ FOO, BAR;
static final class InsideEnum {
static int member;
@java.lang.SuppressWarnings("all")
diff --git a/test/transform/resource/after-delombok/UtilityClassErrors.java b/test/transform/resource/after-delombok/UtilityClassErrors.java
index 9626461a..072edf91 100644
--- a/test/transform/resource/after-delombok/UtilityClassErrors.java
+++ b/test/transform/resource/after-delombok/UtilityClassErrors.java
@@ -8,7 +8,7 @@ final class UtilityClassErrors1 {
}
}
enum UtilityClassErrors2 {
-;
+ ;
}
class UtilityClassErrors3 {
class NonStaticInner {
diff --git a/test/transform/resource/after-delombok/ValAnonymousSubclassWithGenerics.java b/test/transform/resource/after-delombok/ValAnonymousSubclassWithGenerics.java
index 25a9e0ce..07093e5a 100644
--- a/test/transform/resource/after-delombok/ValAnonymousSubclassWithGenerics.java
+++ b/test/transform/resource/after-delombok/ValAnonymousSubclassWithGenerics.java
@@ -1,6 +1,6 @@
import java.util.*;
public class ValAnonymousSubclassWithGenerics {
- Object object = new Object(){
+ Object object = new Object() {
void foo() {
final int j = 1;
}
@@ -9,7 +9,7 @@ public class ValAnonymousSubclassWithGenerics {
final int k = super.hashCode();
int x = k;
}
- java.util.List<String> names = new java.util.ArrayList<String>(){
+ java.util.List<String> names = new java.util.ArrayList<String>() {
public String get(int i) {
final java.lang.String result = super.get(i);
return result;
diff --git a/test/transform/resource/after-delombok/ValLambda.java b/test/transform/resource/after-delombok/ValLambda.java
index 0b13b5a1..40b056f3 100644
--- a/test/transform/resource/after-delombok/ValLambda.java
+++ b/test/transform/resource/after-delombok/ValLambda.java
@@ -1,21 +1,21 @@
// version 8:
class ValLambda {
public void easyLambda() {
- final java.lang.Runnable foo = (Runnable)() -> {
+ final java.lang.Runnable foo = (Runnable) () -> {
};
}
public void easyIntersectionLambda() {
- final java.lang.Object foo = (Runnable & java.io.Serializable)() -> {
+ final java.lang.Object foo = (Runnable & java.io.Serializable) () -> {
};
- final java.lang.Object bar = (java.io.Serializable & Runnable)() -> {
+ final java.lang.Object bar = (java.io.Serializable & Runnable) () -> {
};
}
public void easyLubLambda() {
- final java.lang.Runnable foo = (System.currentTimeMillis() > 0) ? (Runnable)() -> {
- } : (Runnable)System.out::println;
+ final java.lang.Runnable foo = (System.currentTimeMillis() > 0) ? (Runnable) () -> {
+ } : (Runnable) System.out::println;
}
// public void castLubLambda() {
-// Runnable foo = (Runnable)((System.currentTimeMillis() > 0) ? ()-> {} : System.out::println);
-// lombok.val foo = (Runnable)((System.currentTimeMillis() > 0) ? ()-> {} : System.out::println);
+// Runnable foo = (Runnable) ((System.currentTimeMillis() > 0) ? () -> {} : System.out::println);
+// lombok.val foo = (Runnable) ((System.currentTimeMillis() > 0) ? () -> {} : System.out::println);
// }
} \ No newline at end of file
diff --git a/test/transform/resource/after-delombok/ValRawType.java b/test/transform/resource/after-delombok/ValRawType.java
index dc297046..122eabda 100644
--- a/test/transform/resource/after-delombok/ValRawType.java
+++ b/test/transform/resource/after-delombok/ValRawType.java
@@ -5,7 +5,7 @@ public class ValRawType {
public void test() {
Element propElement = new Element();
for (final java.lang.Object attribute : propElement.attributes()) {
- final ValRawType.Attribute attr = (Attribute)attribute;
+ final ValRawType.Attribute attr = (Attribute) attribute;
}
}
diff --git a/test/transform/resource/after-delombok/ValWeirdTypes.java b/test/transform/resource/after-delombok/ValWeirdTypes.java
index 2c2905ed..996ce662 100644
--- a/test/transform/resource/after-delombok/ValWeirdTypes.java
+++ b/test/transform/resource/after-delombok/ValWeirdTypes.java
@@ -18,7 +18,7 @@ public class ValWeirdTypes<Z> {
final long y = 5 + 3L;
}
public void testAnonymousInnerClass() {
- final java.lang.Runnable y = new Runnable(){
+ final java.lang.Runnable y = new Runnable() {
public void run() {
}
};
@@ -48,8 +48,8 @@ public class ValWeirdTypes<Z> {
final java.lang.Object nully = null;
}
public void testArrays() {
- final int[] intArray = new int[]{1, 2, 3};
- final java.lang.Object[][] multiDimArray = new Object[][]{{}};
+ final int[] intArray = new int[] {1, 2, 3};
+ final java.lang.Object[][] multiDimArray = new Object[][] {{}};
final int[] copy = intArray;
final java.lang.Object[] single = multiDimArray[0];
final int singleInt = copy[0];
diff --git a/test/transform/resource/after-delombok/ValWithLocalClasses.java b/test/transform/resource/after-delombok/ValWithLocalClasses.java
index b739b10e..6487eb82 100644
--- a/test/transform/resource/after-delombok/ValWithLocalClasses.java
+++ b/test/transform/resource/after-delombok/ValWithLocalClasses.java
@@ -1,6 +1,6 @@
class ValWithLocalClasses1 {
{
- final ValWithLocalClasses2 f2 = new ValWithLocalClasses2(){
+ final ValWithLocalClasses2 f2 = new ValWithLocalClasses2() {
};
}
}
diff --git a/test/transform/resource/after-delombok/ValuePlain.java b/test/transform/resource/after-delombok/ValuePlain.java
index 8cc19c1e..056cdacf 100644
--- a/test/transform/resource/after-delombok/ValuePlain.java
+++ b/test/transform/resource/after-delombok/ValuePlain.java
@@ -24,7 +24,7 @@ final class Value1 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof Value1)) return false;
- final Value1 other = (Value1)o;
+ final Value1 other = (Value1) o;
if (this.getX() != other.getX()) return false;
final java.lang.Object this$name = this.getName();
final java.lang.Object other$name = other.getName();
@@ -75,8 +75,8 @@ class Value2 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof Value2)) return false;
- final Value2 other = (Value2)o;
- if (!other.canEqual((java.lang.Object)this)) return false;
+ final Value2 other = (Value2) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getX() != other.getX()) return false;
final java.lang.Object this$name = this.getName();
final java.lang.Object other$name = other.getName();
@@ -132,7 +132,7 @@ final class Value3 {
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof Value3)) return false;
- final Value3 other = (Value3)o;
+ final Value3 other = (Value3) o;
if (this.getX() != other.getX()) return false;
if (this.getY() != other.getY()) return false;
return true;