Skip to content

Commit

Permalink
Add missing whitespace for enum generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Aug 5, 2024
1 parent 5886c13 commit 8836bc2
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,18 @@ public void writeFields(Append writer) {
writer.append(" private static final Map<%s, %s> toValue = new EnumMap<>(%s.class);", shortName, returnTypeStr, shortName).eol();
writer.append(" private static final Map<%s, %s> toEnum = new HashMap<>();", returnTypeStr, shortName).eol();
}
writer.append(" private final %s adapter;", adapterShortType).eol();
writer.eol();
writer.append(" private final %s adapter;", adapterShortType).eol().eol();
}

@Override
public void writeConstructor(Append writer) {
writer.append(" this.adapter = jsonb.adapter(%s);", genericType.asTypeDeclaration().replace("? extends ", "")).eol();
if (isEnum) {
writer.append(" if(toValue.isEmpty()) {").eol();
writer.append(" for(final var enumConst : %s.values()) {", shortName).eol();
writer.append(" if (toValue.isEmpty()) {").eol();
writer.append(" for (final var enumConst : %s.values()) {", shortName).eol();
writer.append(" var val = enumConst.%s();", method.getSimpleName()).eol();
writer.append(" toValue.put(enumConst, val);").eol();
writer.append(" if(toEnum.containsKey(val)) throw new IllegalArgumentException(\"Duplicate value \"+ val + \" from enum method %s. @Json.Value methods must return unique values\");",method.getSimpleName()).eol();
writer.append(" if (toEnum.containsKey(val)) throw new IllegalArgumentException(\"Duplicate value \" + val + \" from enum method %s. @Json.Value methods must return unique values\");",method.getSimpleName()).eol();
writer.append(" toEnum.put(val, enumConst);").eol();
writer.append(" }").eol();
writer.append(" }").eol();
Expand Down Expand Up @@ -147,10 +146,9 @@ public void writeFromJson(Append writer) {

if (!isEnum) {
var constructMethod =
constructor.getKind() == ElementKind.CONSTRUCTOR
? "new " + shortName
: shortName + "." + constructor.getSimpleName();

constructor.getKind() == ElementKind.CONSTRUCTOR
? "new " + shortName
: shortName + "." + constructor.getSimpleName();
writer.append(" return %s(adapter.fromJson(reader));", constructMethod).eol();

} else {
Expand Down

0 comments on commit 8836bc2

Please sign in to comment.