1010import software .amazon .smithy .model .Model ;
1111import software .amazon .smithy .model .knowledge .KnowledgeIndex ;
1212import software .amazon .smithy .model .selector .Selector ;
13+ import software .amazon .smithy .model .shapes .MemberShape ;
1314import software .amazon .smithy .model .shapes .Shape ;
1415import software .amazon .smithy .model .shapes .ShapeId ;
1516import software .amazon .smithy .model .shapes .ToShapeId ;
2829 */
2930public class SerdeElisionIndex implements KnowledgeIndex {
3031 private final Map <ShapeId , Boolean > elisionBinding = new HashMap <>();
31- private final Map <String , Class > mutatingTraits = MapUtils .of (
32- "jsonName" , JsonNameTrait .class ,
33- "streaming" , StreamingTrait .class ,
34- "mediaType" , MediaTypeTrait .class ,
35- "sparse" , SparseTrait .class ,
36- "idempotencyToken" , IdempotencyTokenTrait .class
37- );
32+ private final Map <String , ShapeId > mutatingTraits = MapUtils .of (
33+ "jsonName" , JsonNameTrait .ID ,
34+ "streaming" , StreamingTrait .ID ,
35+ "mediaType" , MediaTypeTrait .ID ,
36+ "sparse" , SparseTrait .ID ,
37+ "idempotencyToken" , IdempotencyTokenTrait .ID
38+ );
3839
3940 public SerdeElisionIndex (Model model ) {
4041 for (Shape shape : model .toSet ()) {
@@ -58,15 +59,17 @@ private boolean canBeElided(Shape shape, Model model) {
5859 }
5960
6061 private boolean hasMutatingTraits (Shape shape , Model model ) {
61- for (Map . Entry < String , Class > entry : mutatingTraits .entrySet ()) {
62+ for (var entry : mutatingTraits .entrySet ()) {
6263 if (shape .hasTrait (entry .getValue ())) {
6364 return true ;
6465 }
65- if (shape .getMemberTrait (model , entry .getValue ()).isPresent ()) {
66- return true ;
66+ if (shape instanceof MemberShape memberShape ) {
67+ if (model .expectShape (memberShape .getTarget ()).hasTrait (entry .getValue ())) {
68+ return true ;
69+ }
6770 }
6871 Selector selector = Selector .parse (
69- "[id = '" + shape .getId () + "']" + " ~> [trait|" + entry .getKey () + "]" );
72+ "[id = '" + shape .getId () + "']" + " ~> [trait|" + entry .getKey () + "]" );
7073 if (!selector .select (model ).isEmpty ()) {
7174 return true ;
7275 }
@@ -91,15 +94,15 @@ private boolean hasIncompatibleTypes(Shape shape, Model model, int depth) {
9194 return hasIncompatibleTypes (target .asSetShape ().get ().getMember (), model , depth + 1 );
9295 case STRUCTURE :
9396 return target .asStructureShape ().get ().getAllMembers ().values ().stream ().anyMatch (
94- s -> hasIncompatibleTypes (s , model , depth + 1 )
97+ s -> hasIncompatibleTypes (s , model , depth + 1 )
9598 );
9699 case UNION :
97100 return target .asUnionShape ().get ().getAllMembers ().values ().stream ().anyMatch (
98- s -> hasIncompatibleTypes (s , model , depth + 1 )
101+ s -> hasIncompatibleTypes (s , model , depth + 1 )
99102 );
100103 case MAP :
101104 return hasIncompatibleTypes (model .getShape (target .asMapShape ().get ().getValue ().getTarget ()).get (),
102- model , depth + 1 );
105+ model , depth + 1 );
103106 case BIG_DECIMAL :
104107 case BIG_INTEGER :
105108 case BLOB :
0 commit comments