22
22
import software .amazon .smithy .model .shapes .Shape ;
23
23
import software .amazon .smithy .model .shapes .StructureShape ;
24
24
import software .amazon .smithy .model .shapes .UnionShape ;
25
- import software .amazon .smithy .model .traits .InputTrait ;
26
25
import software .amazon .smithy .model .traits .RequiredTrait ;
27
26
import software .amazon .smithy .model .traits .StreamingTrait ;
28
27
@@ -45,20 +44,24 @@ public abstract class StructureExampleGenerator {
45
44
* };
46
45
* ```
47
46
*/
48
- public static String generateStructuralHintDocumentation (Shape shape , Model model , boolean isComment ) {
47
+ public static String generateStructuralHintDocumentation (
48
+ Shape shape ,
49
+ Model model ,
50
+ boolean isComment ,
51
+ boolean isInput
52
+ ) {
49
53
StringBuilder buffer = new StringBuilder ();
50
- boolean isInput = shape .hasTrait (InputTrait .class );
51
54
shape (shape , buffer , model , 0 , new ShapeTracker (), isInput );
52
55
53
56
// replace non-leading whitespace with single space.
54
57
String s = Arrays .stream (
55
58
buffer .toString ()
56
- .split ("\n " ))
57
- .map (line -> line .replaceAll (
58
- "([\\ w\\ \" ,:\\ [\\ {] )\\ s+" ,
59
- "$1" )
60
- .replaceAll ("\\ s+$" , "" ))
61
- .collect (Collectors .joining ((isComment ) ? "\n // " : "\n " ));
59
+ .split ("\n " ))
60
+ .map (line -> line .replaceAll (
61
+ "([\\ w\\ \" ,:\\ [\\ {] )\\ s+" ,
62
+ "$1" )
63
+ .replaceAll ("\\ s+$" , "" ))
64
+ .collect (Collectors .joining ((isComment ) ? "\n // " : "\n " ));
62
65
63
66
return ((isComment ) ? "// " : "" ) + s .replaceAll (",$" , ";" );
64
67
}
@@ -74,9 +77,9 @@ private static void structure(StructureShape structureShape,
74
77
checkRequired (indentation , buffer , structureShape );
75
78
} else {
76
79
append (indentation , buffer ,
77
- "{" + (shapeTracker .getOccurrenceCount (structureShape ) == 1
78
- ? " // " + structureShape .getId ().getName ()
79
- : "" ));
80
+ "{" + (shapeTracker .getOccurrenceCount (structureShape ) == 1
81
+ ? " // " + structureShape .getId ().getName ()
82
+ : "" ));
80
83
checkRequired (indentation , buffer , structureShape );
81
84
structureShape .getAllMembers ().values ().forEach (member -> {
82
85
append (indentation + 2 , buffer , member .getMemberName () + ": " );
@@ -93,8 +96,8 @@ private static void union(UnionShape unionShape,
93
96
ShapeTracker shapeTracker ,
94
97
boolean isInput ) {
95
98
append (indentation , buffer , "{" + (shapeTracker .getOccurrenceCount (unionShape ) == 1
96
- ? " // " + unionShape .getId ().getName ()
97
- : "// " ) + " Union: only one key present" );
99
+ ? " // " + unionShape .getId ().getName ()
100
+ : "// " ) + " Union: only one key present" );
98
101
checkRequired (indentation , buffer , unionShape );
99
102
unionShape .getAllMembers ().values ().forEach (member -> {
100
103
append (indentation + 2 , buffer , member .getMemberName () + ": " );
@@ -183,22 +186,22 @@ private static void shape(Shape shape,
183
186
case SET :
184
187
case LIST :
185
188
append (indentation , buffer , "[" + (shapeTracker .getOccurrenceCount (target ) == 1
186
- ? " // " + target .getId ().getName ()
187
- : "" ));
189
+ ? " // " + target .getId ().getName ()
190
+ : "" ));
188
191
checkRequired (indentation , buffer , shape );
189
192
ListShape list = (ListShape ) target ;
190
193
shape (list .getMember (), buffer , model , indentation + 2 , shapeTracker , isInput );
191
194
append (indentation , buffer , "],\n " );
192
195
break ;
193
196
case MAP :
194
197
append (indentation , buffer , "{" + (shapeTracker .getOccurrenceCount (target ) == 1
195
- ? " // " + target .getId ().getName ()
196
- : "" ));
198
+ ? " // " + target .getId ().getName ()
199
+ : "" ));
197
200
checkRequired (indentation , buffer , shape );
198
201
append (indentation + 2 , buffer , "\" <keys>\" : " );
199
202
MapShape map = (MapShape ) target ;
200
203
shape (model .getShape (map .getValue ().getTarget ()).get (), buffer , model , indentation + 2 ,
201
- shapeTracker , isInput );
204
+ shapeTracker , isInput );
202
205
append (indentation , buffer , "},\n " );
203
206
break ;
204
207
@@ -214,19 +217,19 @@ private static void shape(Shape shape,
214
217
case ENUM :
215
218
EnumShape enumShape = (EnumShape ) target ;
216
219
String enumeration = enumShape .getEnumValues ()
217
- .values ()
218
- .stream ()
219
- .map (s -> "\" " + s + "\" " )
220
- .collect (Collectors .joining (" || " ));
220
+ .values ()
221
+ .stream ()
222
+ .map (s -> "\" " + s + "\" " )
223
+ .collect (Collectors .joining (" || " ));
221
224
append (indentation , buffer , enumeration + "," );
222
225
break ;
223
226
case INT_ENUM :
224
227
IntEnumShape intEnumShape = (IntEnumShape ) target ;
225
228
String intEnumeration = intEnumShape .getEnumValues ()
226
- .values ()
227
- .stream ()
228
- .map (i -> Integer .toString (i ))
229
- .collect (Collectors .joining (" || " ));
229
+ .values ()
230
+ .stream ()
231
+ .map (i -> Integer .toString (i ))
232
+ .collect (Collectors .joining (" || " ));
230
233
append (indentation , buffer , intEnumeration + "," );
231
234
break ;
232
235
case OPERATION :
@@ -311,8 +314,8 @@ public void mark(Shape shape, int depth) {
311
314
*/
312
315
public boolean shouldTruncate (Shape shape ) {
313
316
return (shape instanceof MapShape || shape instanceof UnionShape || shape instanceof StructureShape
314
- || shape instanceof ListShape || shape instanceof SetShape )
315
- && (getOccurrenceCount (shape ) > 5 || getOccurrenceDepths (shape ) > 2 );
317
+ || shape instanceof ListShape || shape instanceof SetShape )
318
+ && (getOccurrenceCount (shape ) > 5 || getOccurrenceDepths (shape ) > 2 );
316
319
}
317
320
318
321
/**
0 commit comments