Skip to content

Commit

Permalink
Updated Java printer
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Sep 27, 2024
1 parent e3b86e0 commit b5d3a59
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,6 @@ public J visitNewClass(J.NewClass newClass, PrintOutputCapture<P> p) {
p.append("new");
visit(newClass.getClazz(), p);
visitContainer("(", newClass.getPadding().getArguments(), JContainer.Location.NEW_CLASS_ARGUMENTS, ",", ")", p);
} else {
visitContainer("{", newClass.getPadding().getArguments(), JContainer.Location.NEW_CLASS_ARGUMENTS, ",", "}", p);
}
visit(newClass.getBody(), p);
afterSyntax(newClass, p);
Expand All @@ -670,6 +668,19 @@ public <T extends J> J visitControlParentheses(J.ControlParentheses<T> controlPa
return controlParens;
}

@Override
protected void visitStatements(List<JRightPadded<Statement>> statements, JRightPadded.Location location, PrintOutputCapture<P> p) {
boolean objectLiteral = getCursor().getParent(0).getValue() instanceof J.Block &&
getCursor().getParent(1).getValue() instanceof J.NewClass;
for (int i = 0; i < statements.size(); i++) {
JRightPadded<Statement> paddedStat = statements.get(i);
visitStatement(paddedStat, location, p);
if (i < statements.size() - 1 && objectLiteral) {
p.append(',');
}
}
}

@Override
public J visitTypeCast(J.TypeCast typeCast, PrintOutputCapture<P> p) {
beforeSyntax(typeCast, Space.Location.TYPE_CAST_PREFIX, p);
Expand All @@ -683,6 +694,8 @@ public J visitTypeCast(J.TypeCast typeCast, PrintOutputCapture<P> p) {

@Override
public J visitVariableDeclarations(J.VariableDeclarations multiVariable, PrintOutputCapture<P> p) {
boolean objectLiteral = getCursor().getParent(1).getValue() instanceof J.Block &&
getCursor().getParent(2).getValue() instanceof J.NewClass;
beforeSyntax(multiVariable, Space.Location.VARIABLE_DECLARATIONS_PREFIX, p);
visit(multiVariable.getLeadingAnnotations(), p);
multiVariable.getModifiers().forEach(it -> visitModifier(it, p));
Expand All @@ -708,7 +721,7 @@ public J visitVariableDeclarations(J.VariableDeclarations multiVariable, PrintOu
}

if (variable.getElement().getInitializer() != null) {
JavaScriptPrinter.this.visitLeftPadded(variable.getElement().getMarkers().findFirst(Colon.class).isPresent() ? ":" : "=",
JavaScriptPrinter.this.visitLeftPadded(objectLiteral ? ":" : "=",
variable.getElement().getPadding().getInitializer(), JLeftPadded.Location.VARIABLE_INITIALIZER, p);
}

Expand Down

0 comments on commit b5d3a59

Please sign in to comment.