diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/DeprecatedAnnotationInterceptor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/DeprecatedAnnotationInterceptor.java index ec79c2cee15..3dd961cee60 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/DeprecatedAnnotationInterceptor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/DeprecatedAnnotationInterceptor.java @@ -4,7 +4,9 @@ */ package software.amazon.smithy.traitcodegen.integrations.annotations; +import software.amazon.smithy.model.shapes.Shape; import software.amazon.smithy.model.traits.DeprecatedTrait; +import software.amazon.smithy.model.traits.TraitDefinition; import software.amazon.smithy.traitcodegen.sections.ClassSection; import software.amazon.smithy.traitcodegen.sections.EnumVariantSection; import software.amazon.smithy.traitcodegen.sections.GetterSection; @@ -27,7 +29,8 @@ public boolean isIntercepted(CodeSection section) { if (section instanceof ClassSection) { return ((ClassSection) section).shape().hasTrait(DeprecatedTrait.ID); } else if (section instanceof GetterSection) { - return ((GetterSection) section).shape().hasTrait(DeprecatedTrait.ID); + Shape shape = ((GetterSection) section).shape(); + return shape.hasTrait(DeprecatedTrait.ID) && !shape.hasTrait(TraitDefinition.ID); } else if (section instanceof EnumVariantSection) { return ((EnumVariantSection) section).memberShape().hasTrait(DeprecatedTrait.ID); } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocInjectorInterceptor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocInjectorInterceptor.java index bf8a7b6204a..55259fc8fd3 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocInjectorInterceptor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocInjectorInterceptor.java @@ -5,6 +5,7 @@ package software.amazon.smithy.traitcodegen.integrations.javadoc; import software.amazon.smithy.model.shapes.Shape; +import software.amazon.smithy.model.traits.TraitDefinition; import software.amazon.smithy.traitcodegen.sections.ClassSection; import software.amazon.smithy.traitcodegen.sections.EnumVariantSection; import software.amazon.smithy.traitcodegen.sections.GetterSection; @@ -40,6 +41,9 @@ public void prepend(TraitCodegenWriter writer, CodeSection section) { shape = ((ClassSection) section).shape(); } else if (section instanceof GetterSection) { shape = ((GetterSection) section).shape(); + if (shape.hasTrait(TraitDefinition.ID)) { + return; + } } else if (section instanceof EnumVariantSection) { shape = ((EnumVariantSection) section).memberShape(); } else { diff --git a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationsTest.java b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationsTest.java index 70eab9865ff..99051d761f9 100644 --- a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationsTest.java +++ b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationsTest.java @@ -130,6 +130,48 @@ void unstableAnnotationOnEnumVariant() { assertTrue(fileContents.contains(expected)); } + @Test + void deprecatedAnnotationOnListTrait() { + String fileContents = getFileContentsFromShapeName("DeprecatedList", true); + String expected = "@Deprecated\n" + + "@SmithyGenerated\n" + + "public final class DeprecatedListTrait"; + assertTrue(fileContents.contains(expected)); + } + + @Test + void noDeprecatedAnnotationOnListGetValues() { + String fileContents = getFileContentsFromShapeName("DeprecatedList", true); + String expected = " }\n\n" + + " public List getValues() {"; + assertTrue(fileContents.contains(expected)); + } + + @Test + void deprecatedAnnotationOnMapTrait() { + String fileContents = getFileContentsFromShapeName("DeprecatedMap", true); + String expected = "@Deprecated\n" + + "@SmithyGenerated\n" + + "public final class DeprecatedMapTrait"; + assertTrue(fileContents.contains(expected)); + } + + @Test + void noDeprecatedAnnotationOnMapGetValues() { + String fileContents = getFileContentsFromShapeName("DeprecatedMap", true); + String expected = " }\n\n" + + " public Map getValues() {"; + assertTrue(fileContents.contains(expected)); + } + + @Test + void deprecatedAnnotationOnListMember() { + String fileContents = getFileContentsFromShapeName("DeprecatedStructure", true); + String expected = " @Deprecated\n" + + " public Optional> getDeprecatedMap() {"; + assertTrue(fileContents.contains(expected)); + } + private String getFileContentsFromShapeName(String className, boolean isTrait) { String suffix = isTrait ? "Trait" : ""; String path = String.format("com/example/traits/%s%s.java", className, suffix); diff --git a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavadocTest.java b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavadocTest.java index a69a0e8bad7..c9f75041738 100644 --- a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavadocTest.java +++ b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavadocTest.java @@ -227,6 +227,57 @@ void allDocumentationIncludedTogetherEnumVariant() { assertTrue(fileContents.contains(expected)); } + @Test + void deprecatedAnnotationAndNoteForListTrait() { + String fileContents = getFileContentsFromShapeName("DeprecatedList", true); + String expectedForClass = "/**\n" + + " * A deprecated list trait\n" + + " *\n" + + " * @see Example\n" + + " * @since 4.5\n" + + " * @deprecated As of yesterday. A message\n" + + " */\n" + + "@Deprecated\n" + + "@SmithyGenerated\n" + + "public final class DeprecatedListTrait"; + String expectedForGetter = " }\n\n" + + " public List getValues() {"; + assertTrue(fileContents.contains(expectedForClass)); + assertTrue(fileContents.contains(expectedForGetter)); + } + + @Test + void deprecatedAnnotationAndNoteForMapTrait() { + String fileContents = getFileContentsFromShapeName("DeprecatedMap", true); + String expectedForClass = "/**\n" + + " * A deprecated map trait\n" + + " *\n" + + " * @see Example\n" + + " * @since 4.5\n" + + " * @deprecated As of yesterday. A message\n" + + " */\n" + + "@Deprecated\n" + + "@SmithyGenerated\n" + + "public final class DeprecatedMapTrait"; + String expectedForGetter = " }\n\n" + + " public Map getValues() {"; + assertTrue(fileContents.contains(expectedForClass)); + assertTrue(fileContents.contains(expectedForGetter)); + } + + @Test + void deprecatedAnnotationAndNoteForListMember() { + String fileContents = getFileContentsFromShapeName("DeprecatedStructure", true); + String expected = " /**\n" + + " * @deprecated As of yesterday. A message\n" + + " */\n" + + " @Deprecated\n" + + " public Optional> getDeprecatedList() {\n" + + " return Optional.ofNullable(deprecatedList);\n" + + " }"; + assertTrue(fileContents.contains(expected)); + } + private String getFileContentsFromShapeName(String className, boolean isTrait) { String suffix = isTrait ? "Trait" : ""; String path = String.format("com/example/traits/%s%s.java", className, suffix); diff --git a/smithy-trait-codegen/src/test/resources/software/amazon/smithy/traitcodegen/integrations/annotations/annotations-test.smithy b/smithy-trait-codegen/src/test/resources/software/amazon/smithy/traitcodegen/integrations/annotations/annotations-test.smithy index 8ec5896252a..5301ab69ab4 100644 --- a/smithy-trait-codegen/src/test/resources/software/amazon/smithy/traitcodegen/integrations/annotations/annotations-test.smithy +++ b/smithy-trait-codegen/src/test/resources/software/amazon/smithy/traitcodegen/integrations/annotations/annotations-test.smithy @@ -20,6 +20,14 @@ structure DeprecatedStructure { /// Has docs in addition to deprecated @deprecated deprecatedWithDocs: String + + @deprecated + deprecatedMap: MemberMap +} + +map MemberMap { + key: String + value: Integer } @trait @@ -41,4 +49,15 @@ enum EnumWithAnnotations { UNSTABLE } +@trait +@deprecated +list DeprecatedList { + member: Integer +} +@trait +@deprecated +map DeprecatedMap { + key: String + value: Integer +} diff --git a/smithy-trait-codegen/src/test/resources/software/amazon/smithy/traitcodegen/integrations/javadoc/javadoc-test.smithy b/smithy-trait-codegen/src/test/resources/software/amazon/smithy/traitcodegen/integrations/javadoc/javadoc-test.smithy index d9f154cc0a6..f881b20e951 100644 --- a/smithy-trait-codegen/src/test/resources/software/amazon/smithy/traitcodegen/integrations/javadoc/javadoc-test.smithy +++ b/smithy-trait-codegen/src/test/resources/software/amazon/smithy/traitcodegen/integrations/javadoc/javadoc-test.smithy @@ -31,6 +31,13 @@ structure DeprecatedStructure { /// Has docs in addition to deprecated @deprecated(message: "A message", since: "yesterday") deprecatedWithDocs: String + + @deprecated(message: "A message", since: "yesterday") + deprecatedList: MemberList +} + +list MemberList { + member: Integer } @trait @@ -78,3 +85,21 @@ enum EnumVariantsTest { B } +/// A deprecated list trait +@trait +@deprecated(message: "A message", since: "yesterday") +@externalDocumentation(Example: "https://example.com") +@since("4.5") +list DeprecatedList { + member: Integer +} + +/// A deprecated map trait +@trait +@deprecated(message: "A message", since: "yesterday") +@externalDocumentation(Example: "https://example.com") +@since("4.5") +map DeprecatedMap { + key: String + value: Integer +}