Skip to content

Commit

Permalink
Minor cleanups to ControlFlow (openrewrite#2114)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLLeitschuh authored Aug 6, 2022
1 parent 1045561 commit 4bd8cbe
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
package org.openrewrite.marker;

import lombok.With;
import org.openrewrite.Incubating;

import java.util.UUID;

/**
* A Search Result matching a <link href="https://en.wikipedia.org/wiki/DOT_(graph_description_language)">DOT Format</link>.
*/
@With
@Incubating(since = "7.27.2")
public class DotResult extends SearchResult {
public DotResult(UUID id, String dotResult) {
super(id, dotResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@Incubating(since = "7.25.0")
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class ControlFlow {
public final class ControlFlow {
private static final String CONTROL_FLOW_MESSAGE_KEY = "__CONTROL_FLOW_SUMMARY";

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.LinkedHashSet;
import java.util.Set;

class ControlFlowIllegalStateException extends IllegalStateException {
final class ControlFlowIllegalStateException extends IllegalStateException {

ControlFlowIllegalStateException(Message.MessageBuilder message) {
super(message.build().createMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,50 @@
package org.openrewrite.java.controlflow;

import lombok.AllArgsConstructor;
import org.openrewrite.Cursor;
import org.openrewrite.PrintOutputCapture;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaPrinter;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JRightPadded;
import org.openrewrite.java.tree.Space;
import org.openrewrite.java.tree.Statement;
import org.openrewrite.marker.Marker;

import java.util.List;

@AllArgsConstructor
public class ControlFlowJavaPrinter<P> extends JavaPrinter<P> {
final class ControlFlowJavaPrinter<P> extends JavaPrinter<P> {
final List<J> nodesToPrint;

@Override
public J visitAssert(J.Assert azzert, PrintOutputCapture<P> p) {
maybeEnableOrDisable(azzert, p);
J j = super.visitAssert(azzert, p);
return j;
return super.visitAssert(azzert, p);
}

@Override
public J visitAssignment(J.Assignment assignment, PrintOutputCapture<P> p) {
maybeEnableOrDisable(assignment, p);
J j = super.visitAssignment(assignment, p);
return j;
return super.visitAssignment(assignment, p);
}

@Override
public J visitAssignmentOperation(J.AssignmentOperation assignOp, PrintOutputCapture<P> p) {
maybeEnableOrDisable(assignOp, p);
J j = super.visitAssignmentOperation(assignOp, p);
return j;
return super.visitAssignmentOperation(assignOp, p);
}

@Override
public J visitBinary(J.Binary binary, PrintOutputCapture<P> p) {
maybeEnableOrDisable(binary, p);
J j = super.visitBinary(binary, p);
return j;
return super.visitBinary(binary, p);
}

@Override
public J visitBlock(J.Block block, PrintOutputCapture<P> p) {
maybeEnableOrDisable(block, p);
visitSpace(block.getEnd(), Space.Location.BLOCK_PREFIX, p);
visitMarkers(block.getMarkers(), p);


if (block.isStatic()) {
p.append("static");
visitRightPadded(block.getPadding().getStatic(), JRightPadded.Location.STATIC_INIT, p);
}

p.append('{');
visitStatements(block.getPadding().getStatements(), JRightPadded.Location.BLOCK_STATEMENT, p);
visitSpace(block.getEnd(), Space.Location.BLOCK_END, p);
p.append('}');
return block;
// Customize the block to change the prefix that starts this block
// This results in a block that is more readable when printed
J.Block customized = block.withPrefix(block.getEnd());
return super.visitBlock(customized, p);
}

@Override
Expand All @@ -91,36 +74,31 @@ protected void visitStatement(@Nullable JRightPadded<Statement> paddedStat, JRig
@Override
public J visitBreak(J.Break breakStatement, PrintOutputCapture<P> p) {
maybeEnableOrDisable(breakStatement, p);
J j = super.visitBreak(breakStatement, p);
return j;
return super.visitBreak(breakStatement, p);
}

@Override
public J visitCase(J.Case caze, PrintOutputCapture<P> p) {
maybeEnableOrDisable(caze, p);
J j = super.visitCase(caze, p);
return j;
return super.visitCase(caze, p);
}

@Override
public J visitCatch(J.Try.Catch catzh, PrintOutputCapture<P> p) {
maybeEnableOrDisable(catzh, p);
J j = super.visitCatch(catzh, p);
return j;
return super.visitCatch(catzh, p);
}

@Override
public J visitClassDeclaration(J.ClassDeclaration classDecl, PrintOutputCapture<P> p) {
maybeEnableOrDisable(classDecl, p);
J j = super.visitClassDeclaration(classDecl, p);
return j;
return super.visitClassDeclaration(classDecl, p);
}

@Override
public J visitContinue(J.Continue continueStatement, PrintOutputCapture<P> p) {
maybeEnableOrDisable(continueStatement, p);
J j = super.visitContinue(continueStatement, p);
return j;
return super.visitContinue(continueStatement, p);
}

@Override
Expand All @@ -138,50 +116,43 @@ public <T extends J> J visitControlParentheses(J.ControlParentheses<T> controlPa
return super.visitControlParentheses(controlParens, p);
}
maybeEnableOrDisable(controlParens, p);
J j = super.visitControlParentheses(controlParens, p);
return j;
return super.visitControlParentheses(controlParens, p);
}

@Override
public J visitDoWhileLoop(J.DoWhileLoop doWhileLoop, PrintOutputCapture<P> p) {
maybeEnableOrDisable(doWhileLoop, p);
J j = super.visitDoWhileLoop(doWhileLoop, p);
return j;
return super.visitDoWhileLoop(doWhileLoop, p);
}

@Override
public J visitEnumValue(J.EnumValue enoom, PrintOutputCapture<P> p) {
maybeEnableOrDisable(enoom, p);
J j = super.visitEnumValue(enoom, p);
return j;
return super.visitEnumValue(enoom, p);
}

@Override
public J visitEnumValueSet(J.EnumValueSet enums, PrintOutputCapture<P> p) {
maybeEnableOrDisable(enums, p);
J j = super.visitEnumValueSet(enums, p);
return j;
return super.visitEnumValueSet(enums, p);
}

@Override
public J visitFieldAccess(J.FieldAccess fieldAccess, PrintOutputCapture<P> p) {
maybeEnableOrDisable(fieldAccess, p);
J j = super.visitFieldAccess(fieldAccess, p);
return j;
return super.visitFieldAccess(fieldAccess, p);
}

@Override
public J visitForLoop(J.ForLoop forLoop, PrintOutputCapture<P> p) {
maybeEnableOrDisable(forLoop, p);
J j = super.visitForLoop(forLoop, p);
return j;
return super.visitForLoop(forLoop, p);
}

@Override
public J visitForEachLoop(J.ForEachLoop forEachLoop, PrintOutputCapture<P> p) {
maybeEnableOrDisable(forEachLoop, p);
J j = super.visitForEachLoop(forEachLoop, p);
return j;
return super.visitForEachLoop(forEachLoop, p);
}

@Override
Expand Down Expand Up @@ -211,141 +182,121 @@ public J visitIdentifier(J.Identifier ident, PrintOutputCapture<P> p) {
return super.visitIdentifier(ident, p);
}
maybeEnableOrDisable(ident, p);
J j = super.visitIdentifier(ident, p);
return j;
return super.visitIdentifier(ident, p);
}

@Override
public J visitIf(J.If iff, PrintOutputCapture<P> p) {
maybeEnableOrDisable(iff, p);
J j = super.visitIf(iff, p);
return j;
return super.visitIf(iff, p);
}

@Override
public J visitInstanceOf(J.InstanceOf instanceOf, PrintOutputCapture<P> p) {
maybeEnableOrDisable(instanceOf, p);
J j = super.visitInstanceOf(instanceOf, p);
return j;
return super.visitInstanceOf(instanceOf, p);
}

@Override
public J visitLambda(J.Lambda lambda, PrintOutputCapture<P> p) {
maybeEnableOrDisable(lambda, p);
J j = super.visitLambda(lambda, p);
return j;
return super.visitLambda(lambda, p);
}

@Override
public J visitLiteral(J.Literal literal, PrintOutputCapture<P> p) {
maybeEnableOrDisable(literal, p);
J j = super.visitLiteral(literal, p);
return j;
return super.visitLiteral(literal, p);
}

@Override
public J visitMemberReference(J.MemberReference memberRef, PrintOutputCapture<P> p) {
maybeEnableOrDisable(memberRef, p);
J j = super.visitMemberReference(memberRef, p);
return j;
return super.visitMemberReference(memberRef, p);
}

@Override
public J visitMethodDeclaration(J.MethodDeclaration method, PrintOutputCapture<P> p) {
maybeEnableOrDisable(method, p);
J j = super.visitMethodDeclaration(method, p);
return j;
return super.visitMethodDeclaration(method, p);
}

@Override
public J visitMethodInvocation(J.MethodInvocation method, PrintOutputCapture<P> p) {
maybeEnableOrDisable(method, p);
J j = super.visitMethodInvocation(method, p);
return j;
return super.visitMethodInvocation(method, p);
}

@Override
public J visitMultiCatch(J.MultiCatch multiCatch, PrintOutputCapture<P> p) {
maybeEnableOrDisable(multiCatch, p);
J j = super.visitMultiCatch(multiCatch, p);
return j;
return super.visitMultiCatch(multiCatch, p);
}

@Override
public J visitVariableDeclarations(J.VariableDeclarations multiVariable, PrintOutputCapture<P> p) {
maybeEnableOrDisable(multiVariable, p);
J j = super.visitVariableDeclarations(multiVariable, p);
return j;
return super.visitVariableDeclarations(multiVariable, p);
}

@Override
public J visitNewArray(J.NewArray newArray, PrintOutputCapture<P> p) {
maybeEnableOrDisable(newArray, p);
J j = super.visitNewArray(newArray, p);
return j;
return super.visitNewArray(newArray, p);
}

@Override
public <T extends J> J visitParentheses(J.Parentheses<T> parens, PrintOutputCapture<P> p) {
maybeEnableOrDisable(parens, p);
J j = super.visitParentheses(parens, p);
return j;
return super.visitParentheses(parens, p);
}

@Override
public J visitSwitch(J.Switch switzh, PrintOutputCapture<P> p) {
maybeEnableOrDisable(switzh, p);
J j = super.visitSwitch(switzh, p);
return j;
return super.visitSwitch(switzh, p);
}

@Override
public J visitSynchronized(J.Synchronized synch, PrintOutputCapture<P> p) {
maybeEnableOrDisable(synch, p);
J j = super.visitSynchronized(synch, p);
return j;
return super.visitSynchronized(synch, p);
}

@Override
public J visitTernary(J.Ternary ternary, PrintOutputCapture<P> p) {
maybeEnableOrDisable(ternary, p);
J j = super.visitTernary(ternary, p);
return j;
return super.visitTernary(ternary, p);
}

@Override
public J visitThrow(J.Throw thrown, PrintOutputCapture<P> p) {
maybeEnableOrDisable(thrown, p);
J j = super.visitThrow(thrown, p);
return j;
return super.visitThrow(thrown, p);
}

@Override
public J visitTry(J.Try tryable, PrintOutputCapture<P> p) {
maybeEnableOrDisable(tryable, p);
J j = super.visitTry(tryable, p);
return j;
return super.visitTry(tryable, p);
}

@Override
public J visitUnary(J.Unary unary, PrintOutputCapture<P> p) {
maybeEnableOrDisable(unary, p);
J j = super.visitUnary(unary, p);
return j;
return super.visitUnary(unary, p);
}

@Override
public J visitVariable(J.VariableDeclarations.NamedVariable variable, PrintOutputCapture<P> p) {
maybeEnableOrDisable(variable, p);
J j = super.visitVariable(variable, p);
return j;
return super.visitVariable(variable, p);
}

@Override
public J visitWhileLoop(J.WhileLoop whileLoop, PrintOutputCapture<P> p) {
maybeEnableOrDisable(whileLoop, p);
J j = super.visitWhileLoop(whileLoop, p);
return j;
return super.visitWhileLoop(whileLoop, p);
}

static class ControlFlowPrintOutputCapture<P> extends PrintOutputCapture<P> {
Expand Down
Loading

0 comments on commit 4bd8cbe

Please sign in to comment.