Skip to content

Commit

Permalink
Format Java.
Browse files Browse the repository at this point in the history
  • Loading branch information
petervdonovan committed Jun 16, 2023
1 parent d969c2b commit fd198c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/lflang/ast/MalleableString.java
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ private Leaf(String[] possibilities) {
}

private Leaf(String possibility) {
this.possibilities = new String[]{possibility};
this.possibilities = new String[] {possibility};
}

@Override
Expand Down
26 changes: 21 additions & 5 deletions core/src/main/java/org/lflang/ast/ToLf.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ public MalleableString caseStateVar(StateVar object) {
}
msb.append("state ").append(object.getName());
msb.append(typeAnnotationFor(object.getType()));
if (object.getInit() != null) msb.append(doSwitch(object.getInit()).transform(ToLf::whitespaceInitializer));
if (object.getInit() != null)
msb.append(doSwitch(object.getInit()).transform(ToLf::whitespaceInitializer));

return msb.get();
}
Expand Down Expand Up @@ -945,9 +946,16 @@ public MalleableString caseParameter(Parameter object) {
.get();
}

/** Ensure that equals signs are surrounded by spaces if neither the text before nor the text after has spaces and is not a string. */
private static Function<String, String> conditionalWhitespaceInitializer(MalleableString before, MalleableString after) {
return it -> before.isEmpty() && !(after.toString().contains(" ") || after.toString().startsWith("\"")) ? it : whitespaceInitializer(it);
/**
* Ensure that equals signs are surrounded by spaces if neither the text before nor the text after
* has spaces and is not a string.
*/
private static Function<String, String> conditionalWhitespaceInitializer(
MalleableString before, MalleableString after) {
return it ->
before.isEmpty() && !(after.toString().contains(" ") || after.toString().startsWith("\""))
? it
: whitespaceInitializer(it);
}

/** Ensure that equals signs are surrounded by spaces. */
Expand Down Expand Up @@ -1073,7 +1081,15 @@ private MalleableString list(
})
.collect(new Joiner(separator, prefix, suffix));
if (whitespaceRigid) return rigid;
var rigidList = list(separator.strip() + "\n", "", suffixSameLine ? "" : "\n", nothingIfEmpty, true, suffixSameLine, items);
var rigidList =
list(
separator.strip() + "\n",
"",
suffixSameLine ? "" : "\n",
nothingIfEmpty,
true,
suffixSameLine,
items);
return MalleableString.anyOf(
rigid,
new Builder()
Expand Down

0 comments on commit fd198c1

Please sign in to comment.