-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Annotate and document members that are modeled as deprecated... (#2622)
* Annotate and document members that are modeled as deprecated... ...and add support for using customization to override specific members as deprecated. ## Motivation and Context As part of a recent change to repurpose the S3 CopyObjectRequest copySource parameter into more user-friendly parameters, we lacked the ability in our ShapeModifiersProcessor to also deprecate the old parameter name. Furthermore, after additional investigation, we also appear to not have been correctly honoring the different service-2.json models that tag certain members as deprecated. E.g., the following parameter is marked as deprecated: https://github.com/aws/aws-sdk-java-v2/blob/54fd5a69c74af0124e97830bef53b3690dfa2015/services/cloudwatchlogs/src/main/resources/codegen-resources/service-2.json#L1393-L1398 But the corresponding generated code and Javadoc (at the time of this writing) do not mark any of the member's methods as deprecated, or expose the deprecatedMessage: https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/cloudwatchlogs/model/FilterLogEventsRequest.Builder.html#interleaved-java.lang.Boolean- ## Description * For service-2.json members that are marked as deprecated, correctly annotate and document these fields as deprecated in their various accessors and builder setters. * Add support to ShapeModifiersProcessor for customization.config files to be able to manually modify the `deprecated` and `deprecatedMessage` attributes. (A follow-up PR will propose marking the before-mentioned copySource parameter as deprecated.) ## Testing * Add a new operation with members that are modeled as deprecated and members that are modified as deprecated, and add accompanying expected generated code (see expected generated code for an example of how the fields are annotated as deprecated).
- Loading branch information
1 parent
54fd5a6
commit 5c7b6dd
Showing
15 changed files
with
769 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"category": "AWS SDK for Java v2", | ||
"contributor": "", | ||
"type": "feature", | ||
"description": "Annotate and document members that are modeled as deprecated" | ||
} |
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
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
55 changes: 55 additions & 0 deletions
55
codegen/src/main/java/software/amazon/awssdk/codegen/poet/model/DeprecationUtils.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,55 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.codegen.poet.model; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
import static software.amazon.awssdk.codegen.internal.Constant.LF; | ||
|
||
import com.squareup.javapoet.AnnotationSpec; | ||
import com.squareup.javapoet.MethodSpec; | ||
import java.util.List; | ||
import software.amazon.awssdk.codegen.model.intermediate.MemberModel; | ||
import software.amazon.awssdk.utils.StringUtils; | ||
|
||
public final class DeprecationUtils { | ||
|
||
private static final AnnotationSpec DEPRECATED = AnnotationSpec.builder(Deprecated.class).build(); | ||
|
||
private DeprecationUtils() { | ||
} | ||
|
||
/** | ||
* If a given member is modeled as deprecated, add the {@link Deprecated} annotation to the method and, if the method | ||
* already has existing Javadoc, append a section with the {@code @deprecated} tag. | ||
*/ | ||
public static MethodSpec checkDeprecated(MemberModel member, MethodSpec method) { | ||
if (!member.isDeprecated() || method.annotations.contains(DEPRECATED)) { | ||
return method; | ||
} | ||
MethodSpec.Builder builder = method.toBuilder().addAnnotation(DEPRECATED); | ||
if (!method.javadoc.isEmpty()) { | ||
builder.addJavadoc(LF + "@deprecated"); | ||
if (StringUtils.isNotBlank(member.getDeprecatedMessage())) { | ||
builder.addJavadoc(" $L", member.getDeprecatedMessage()); | ||
} | ||
} | ||
return builder.build(); | ||
} | ||
|
||
public static List<MethodSpec> checkDeprecated(MemberModel member, List<MethodSpec> methods) { | ||
return methods.stream().map(methodSpec -> checkDeprecated(member, methodSpec)).collect(toList()); | ||
} | ||
} |
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
Oops, something went wrong.