-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor trait codegen javadoc integration to support member document…
…ation (#2265) Refactors the trait codegen javadoc integration to correctly support documentation on enum variants and structure members. Also moves the addition of annotations to a new AnnotationIntegration.
- Loading branch information
Showing
30 changed files
with
881 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...a/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.traitcodegen.integrations.annotations; | ||
|
||
import java.util.List; | ||
import software.amazon.smithy.traitcodegen.TraitCodegenContext; | ||
import software.amazon.smithy.traitcodegen.integrations.TraitCodegenIntegration; | ||
import software.amazon.smithy.traitcodegen.integrations.javadoc.JavaDocIntegration; | ||
import software.amazon.smithy.traitcodegen.writer.TraitCodegenWriter; | ||
import software.amazon.smithy.utils.CodeInterceptor; | ||
import software.amazon.smithy.utils.CodeSection; | ||
import software.amazon.smithy.utils.ListUtils; | ||
|
||
/** | ||
* Adds Java annotations to generated Java classes. | ||
*/ | ||
public class AnnotationIntegration implements TraitCodegenIntegration { | ||
@Override | ||
public String name() { | ||
return "annotations"; | ||
} | ||
|
||
@Override | ||
public List<String> runBefore() { | ||
return ListUtils.of(JavaDocIntegration.NAME); | ||
} | ||
|
||
@Override | ||
public List<? extends CodeInterceptor<? extends CodeSection, TraitCodegenWriter>> interceptors( | ||
TraitCodegenContext codegenContext) { | ||
return ListUtils.of( | ||
new SmithyGeneratedAnnotationInterceptor(), | ||
new DeprecatedAnnotationInterceptor(), | ||
new UnstableAnnotationInterceptor() | ||
); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../amazon/smithy/traitcodegen/integrations/annotations/DeprecatedAnnotationInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.traitcodegen.integrations.annotations; | ||
|
||
import software.amazon.smithy.model.traits.DeprecatedTrait; | ||
import software.amazon.smithy.traitcodegen.sections.ClassSection; | ||
import software.amazon.smithy.traitcodegen.sections.EnumVariantSection; | ||
import software.amazon.smithy.traitcodegen.sections.GetterSection; | ||
import software.amazon.smithy.traitcodegen.writer.TraitCodegenWriter; | ||
import software.amazon.smithy.utils.CodeInterceptor; | ||
import software.amazon.smithy.utils.CodeSection; | ||
|
||
/** | ||
* Adds the {@link Deprecated} annotation to generated code for shapes with the {@link DeprecatedTrait}. | ||
*/ | ||
final class DeprecatedAnnotationInterceptor implements CodeInterceptor.Prepender<CodeSection, TraitCodegenWriter> { | ||
|
||
@Override | ||
public Class<CodeSection> sectionType() { | ||
return CodeSection.class; | ||
} | ||
|
||
@Override | ||
public boolean isIntercepted(CodeSection section) { | ||
if (section instanceof ClassSection) { | ||
return ((ClassSection) section).shape().hasTrait(DeprecatedTrait.class); | ||
} else if (section instanceof GetterSection) { | ||
return ((GetterSection) section).shape().hasTrait(DeprecatedTrait.class); | ||
} else if (section instanceof EnumVariantSection) { | ||
return ((EnumVariantSection) section).memberShape().hasTrait(DeprecatedTrait.class); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void prepend(TraitCodegenWriter writer, CodeSection section) { | ||
writer.write("@$T", Deprecated.class); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...on/smithy/traitcodegen/integrations/annotations/SmithyGeneratedAnnotationInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.traitcodegen.integrations.annotations; | ||
|
||
import software.amazon.smithy.traitcodegen.sections.ClassSection; | ||
import software.amazon.smithy.traitcodegen.writer.TraitCodegenWriter; | ||
import software.amazon.smithy.utils.CodeInterceptor; | ||
import software.amazon.smithy.utils.SmithyGenerated; | ||
|
||
/** | ||
* Adds the {@link software.amazon.smithy.utils.SmithyGenerated} annotation to all generated classes. | ||
*/ | ||
final class SmithyGeneratedAnnotationInterceptor | ||
implements CodeInterceptor.Prepender<ClassSection, TraitCodegenWriter> { | ||
@Override | ||
public Class<ClassSection> sectionType() { | ||
return ClassSection.class; | ||
} | ||
|
||
@Override | ||
public void prepend(TraitCodegenWriter writer, ClassSection section) { | ||
writer.write("@$T", SmithyGenerated.class); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...re/amazon/smithy/traitcodegen/integrations/annotations/UnstableAnnotationInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.traitcodegen.integrations.annotations; | ||
|
||
import software.amazon.smithy.model.traits.UnstableTrait; | ||
import software.amazon.smithy.traitcodegen.sections.ClassSection; | ||
import software.amazon.smithy.traitcodegen.sections.EnumVariantSection; | ||
import software.amazon.smithy.traitcodegen.sections.GetterSection; | ||
import software.amazon.smithy.traitcodegen.writer.TraitCodegenWriter; | ||
import software.amazon.smithy.utils.CodeInterceptor; | ||
import software.amazon.smithy.utils.CodeSection; | ||
import software.amazon.smithy.utils.SmithyUnstableApi; | ||
|
||
/** | ||
* Adds the {@link software.amazon.smithy.utils.SmithyUnstableApi} annotation to generated code for | ||
* shapes with the {@link UnstableTrait}. | ||
*/ | ||
final class UnstableAnnotationInterceptor implements CodeInterceptor.Prepender<CodeSection, TraitCodegenWriter> { | ||
@Override | ||
public Class<CodeSection> sectionType() { | ||
return CodeSection.class; | ||
} | ||
|
||
@Override | ||
public boolean isIntercepted(CodeSection section) { | ||
if (section instanceof ClassSection) { | ||
return ((ClassSection) section).shape().hasTrait(UnstableTrait.class); | ||
} else if (section instanceof GetterSection) { | ||
return ((GetterSection) section).shape().hasTrait(UnstableTrait.class); | ||
} else if (section instanceof EnumVariantSection) { | ||
return ((EnumVariantSection) section).memberShape().hasTrait(UnstableTrait.class); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void prepend(TraitCodegenWriter writer, CodeSection section) { | ||
writer.write("@$T", SmithyUnstableApi.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...va/software/amazon/smithy/traitcodegen/integrations/core/JavadocFormatterInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.traitcodegen.integrations.core; | ||
|
||
import software.amazon.smithy.traitcodegen.sections.JavaDocSection; | ||
import software.amazon.smithy.traitcodegen.writer.TraitCodegenWriter; | ||
import software.amazon.smithy.utils.CodeInterceptor; | ||
|
||
/** | ||
* Formats any populated Javadoc comment sections as documentation comments. | ||
* | ||
* <p>This interceptor will run after all other Javadoc interceptors to ensure it picks up all content | ||
* added to Jav doc sections. Javadoc sections with no content are discarded. | ||
*/ | ||
public class JavadocFormatterInterceptor implements CodeInterceptor<JavaDocSection, TraitCodegenWriter> { | ||
|
||
@Override | ||
public Class<JavaDocSection> sectionType() { | ||
return JavaDocSection.class; | ||
} | ||
|
||
@Override | ||
public void write(TraitCodegenWriter writer, String previousText, JavaDocSection section) { | ||
if (!previousText.isEmpty()) { | ||
writer.writeDocString(previousText); | ||
} | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
...e/amazon/smithy/traitcodegen/integrations/javadoc/BuilderClassSectionDocsInterceptor.java
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
...ava/software/amazon/smithy/traitcodegen/integrations/javadoc/ClassJavaDocInterceptor.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.