Skip to content

Commit

Permalink
formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Mar 24, 2023
1 parent 0ac2c72 commit 22033c1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public static String generateStructuralHintDocumentation(Shape shape, Model mode
buffer.toString()
.split("\n"))
.map(line -> line.replaceAll(
"([\\w\\\",:] )\\s+",
"([\\w\\\",:\\[\\{] )\\s+",
"$1"))
.collect(Collectors.joining("\n"));

return s;
return s.replaceAll(",$", ";");
}

private static void structure(StructureShape structureShape,
StringBuilder buffer, Model model,
int indentation,
ShapeTracker shapeTracker) {
if (structureShape.getAllMembers().size() == 0) {
append(indentation, buffer, "{}");
append(indentation, buffer, "{},");
checkRequired(indentation, buffer, structureShape);
} else {
append(indentation, buffer, "{");
Expand All @@ -73,7 +73,7 @@ private static void structure(StructureShape structureShape,
append(indentation + 2, buffer, member.getMemberName() + ": ");
shape(member, buffer, model, indentation + 2, shapeTracker);
});
append(indentation, buffer, "}\n");
append(indentation, buffer, "},\n");
}
}

Expand All @@ -88,7 +88,7 @@ private static void union(UnionShape unionShape,
append(indentation + 2, buffer, member.getMemberName() + ": ");
shape(member, buffer, model, indentation + 2, shapeTracker);
});
append(indentation, buffer, "}\n");
append(indentation, buffer, "},\n");
}

private static void shape(Shape shape,
Expand All @@ -104,8 +104,8 @@ private static void shape(Shape shape,
}

shapeTracker.mark(shape, indentation);
if (shapeTracker.getOccurrenceDepths(shape) > 5) {
append(indentation, buffer, "\"<" + shape.getId().getName() + ">\"");
if (shapeTracker.getOccurrenceDepths(shape) > 2) {
append(indentation, buffer, "\"<" + shape.getId().getName() + ">\"\n");
} else {
switch (target.getType()) {
case BIG_DECIMAL:
Expand Down Expand Up @@ -186,7 +186,7 @@ private static void shape(Shape shape,
.stream()
.map(s -> "\"" + s + "\"")
.collect(Collectors.joining(" || "));
append(indentation, buffer, enumeration);
append(indentation, buffer, enumeration + ",");
break;
case INT_ENUM:
IntEnumShape intEnumShape = (IntEnumShape) target;
Expand All @@ -195,7 +195,7 @@ private static void shape(Shape shape,
.stream()
.map(i -> Integer.toString(i))
.collect(Collectors.joining(" || "));
append(indentation, buffer, intEnumeration);
append(indentation, buffer, intEnumeration + ",");
break;
case OPERATION:
case RESOURCE:
Expand All @@ -205,37 +205,37 @@ private static void shape(Shape shape,
append(indentation, buffer, "\"...\",");
break;
}
}

switch (target.getType()) {
case STRUCTURE:
case UNION:
case LIST:
case SET:
case MAP:
break;
case BIG_DECIMAL:
case BIG_INTEGER:
case BLOB:
case BOOLEAN:
case BYTE:
case DOCUMENT:
case DOUBLE:
case ENUM:
case FLOAT:
case INTEGER:
case INT_ENUM:
case LONG:
case MEMBER:
case OPERATION:
case RESOURCE:
case SERVICE:
case SHORT:
case STRING:
case TIMESTAMP:
default:
checkRequired(indentation, buffer, shape);
break;
switch (target.getType()) {
case STRUCTURE:
case UNION:
case LIST:
case SET:
case MAP:
break;
case BIG_DECIMAL:
case BIG_INTEGER:
case BLOB:
case BOOLEAN:
case BYTE:
case DOCUMENT:
case DOUBLE:
case ENUM:
case FLOAT:
case INTEGER:
case INT_ENUM:
case LONG:
case MEMBER:
case OPERATION:
case RESOURCE:
case SERVICE:
case SHORT:
case STRING:
case TIMESTAMP:
default:
checkRequired(indentation, buffer, shape);
break;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class StructureExampleGeneratorTest {
public void generatesStructuralHintDocumentation_map() {
assertThat(
StructureExampleGenerator.generateStructuralHintDocumentation(map, model),
equalTo("{\n \"<keys>\": \"STRING_VALUE\", \n},"));
equalTo("{\n \"<keys>\": \"STRING_VALUE\", \n};"));
}

@Test
Expand All @@ -75,19 +75,19 @@ public void generatesStructuralHintDocumentation_structure() {
StructureExampleGenerator.generateStructuralHintDocumentation(structure, model),
equalTo("{\n"
+ " string: \"STRING_VALUE\", \n"
+ " list: [ \n"
+ " list: [ \n"
+ " \"STRING_VALUE\", \n"
+ " ],\n"
+ " map: { \n"
+ " map: { \n"
+ " \"<keys>\": \"STRING_VALUE\", \n"
+ " },\n"
+ "}"));
+ "};"));
}

@Test
public void generatesStructuralHintDocumentation_list() {
assertThat(
StructureExampleGenerator.generateStructuralHintDocumentation(list, model),
equalTo("[\n \"STRING_VALUE\", \n],"));
equalTo("[\n \"STRING_VALUE\", \n];"));
}
}

0 comments on commit 22033c1

Please sign in to comment.