From e70266fd38b6c3762cc4892a35e57e3477143212 Mon Sep 17 00:00:00 2001 From: Richard Chen Date: Wed, 27 Nov 2024 14:39:56 -0500 Subject: [PATCH] minor refactors --- .../ShouldHaveUsedTimestampValidator.java | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/ShouldHaveUsedTimestampValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/ShouldHaveUsedTimestampValidator.java index dc9224f5953..13d23c2f884 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/ShouldHaveUsedTimestampValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/ShouldHaveUsedTimestampValidator.java @@ -31,7 +31,6 @@ import software.amazon.smithy.model.shapes.ShapeType; import software.amazon.smithy.model.shapes.ShapeVisitor; import software.amazon.smithy.model.shapes.StructureShape; -import software.amazon.smithy.model.shapes.TimestampShape; import software.amazon.smithy.model.shapes.UnionShape; import software.amazon.smithy.model.validation.AbstractValidator; import software.amazon.smithy.model.validation.ValidationEvent; @@ -114,7 +113,7 @@ public List validate(Model model) { @Override protected List getDefault(Shape shape) { if (shape.isStringShape() || shape instanceof NumberShape) { - return validateSimpleShape(shape, patterns); + return validateSimpleShape(shape); } else { return Collections.emptyList(); } @@ -122,17 +121,12 @@ protected List getDefault(Shape shape) { @Override public List structureShape(StructureShape shape) { - return validateStructure(shape, model, patterns); + return validateStructure(shape, model); } @Override public List unionShape(UnionShape shape) { - return validateUnion(shape, model, patterns); - } - - @Override - public List timestampShape(TimestampShape shape) { - return Collections.emptyList(); + return validateUnion(shape, model); } @Override @@ -146,43 +140,39 @@ public List enumShape(EnumShape shape) { private List validateStructure( StructureShape structure, - Model model, - List patterns + Model model ) { return structure .getAllMembers() .entrySet() .stream() - .flatMap(entry -> validateTargetShape(entry.getKey(), entry.getValue(), model, patterns)) + .flatMap(entry -> validateTargetShape(entry.getKey(), entry.getValue(), model)) .collect(Collectors.toList()); } private List validateUnion( UnionShape union, - Model model, - List patterns + Model model ) { return union .getAllMembers() .entrySet() .stream() - .flatMap(entry -> validateTargetShape(entry.getKey(), entry.getValue(), model, patterns)) + .flatMap(entry -> validateTargetShape(entry.getKey(), entry.getValue(), model)) .collect(Collectors.toList()); } private Stream validateTargetShape( String name, MemberShape memberShape, - Model model, - List patterns + Model model ) { return OptionalUtils.stream(model.getShape(memberShape.getTarget()) .flatMap(targetShape -> validateName(name, targetShape, memberShape, patterns, model))); } private List validateSimpleShape( - Shape shape, - List patterns + Shape shape ) { String name = shape.getId().getName(); @@ -201,9 +191,7 @@ private Optional validateName( Model model ) { ShapeType type = targetShape.getType(); - if (type == ShapeType.TIMESTAMP) { - return Optional.empty(); - } else if (type == ShapeType.ENUM) { + if (type == ShapeType.TIMESTAMP || type == ShapeType.ENUM) { return Optional.empty(); } else if (type == ShapeType.STRUCTURE || type == ShapeType.LIST) { if (this.onlyContainsTimestamps(targetShape, model)) {