Skip to content

Commit 8eebc72

Browse files
authored
Improve documentation of has* methods based on customer feedback. (#2644)
1 parent 0cdc91e commit 8eebc72

File tree

9 files changed

+438
-199
lines changed

9 files changed

+438
-199
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/internal/DocumentationUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public final class DocumentationUtils {
3636

3737
private static final String DEFAULT_GETTER_PARAM = "The value of the %s property for this object.";
3838

39-
private static final String DEFAULT_EXISTENCE_CHECK = "Returns true if the %s property was specified by the sender "
40-
+ "(it may be empty), or false if the sender did not specify "
41-
+ "the value (it will be empty). For responses returned by the SDK, "
42-
+ "the sender is the AWS service.";
39+
private static final String DEFAULT_EXISTENCE_CHECK =
40+
"For responses, this returns true if the service returned a value for the %s property. This DOES NOT check that the "
41+
+ "value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful because "
42+
+ "the SDK will never return a null collection or map, but you may need to differentiate between the service returning "
43+
+ "nothing (or null) and the service returning an empty collection or map. For requests, this returns true if a value "
44+
+ "for the property was specified in the request builder, and false if a value was not specified.";
4345

4446
private static final String DEFAULT_FLUENT_RETURN =
4547
"Returns a reference to this object so that method calls can be chained together.";

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/MemberModel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ public String getGetterDocumentation() {
433433

434434
if (getAutoConstructClassIfExists().isPresent()) {
435435
appendParagraph(docBuilder,
436-
"You can use {@link #%s()} to see if a value was sent in this field.",
436+
"This method will never return null. If you would like to know whether the service returned this "
437+
+ "field (so that you can differentiate between null and empty), you can use the {@link #%s} method.",
437438
getExistenceCheckMethodName());
438439
}
439440

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/model/alltypesrequest.java

Lines changed: 152 additions & 70 deletions
Large diffs are not rendered by default.

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/model/alltypesresponse.java

Lines changed: 152 additions & 70 deletions
Large diffs are not rendered by default.

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/model/existencechecknamingrequest.java

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ private ExistenceCheckNamingRequest(BuilderImpl builder) {
109109
}
110110

111111
/**
112-
* Returns true if the Build property was specified by the sender (it may be empty), or false if the sender did not
113-
* specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
112+
* For responses, this returns true if the service returned a value for the Build property. This DOES NOT check that
113+
* the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful
114+
* because the SDK will never return a null collection or map, but you may need to differentiate between the service
115+
* returning nothing (or null) and the service returning an empty collection or map. For requests, this returns true
116+
* if a value for the property was specified in the request builder, and false if a value was not specified.
114117
*/
115118
public final boolean hasBuild() {
116119
return build != null && !(build instanceof SdkAutoConstructList);
@@ -122,7 +125,8 @@ public final boolean hasBuild() {
122125
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
123126
* </p>
124127
* <p>
125-
* You can use {@link #hasBuild()} to see if a value was sent in this field.
128+
* This method will never return null. If you would like to know whether the service returned this field (so that
129+
* you can differentiate between null and empty), you can use the {@link #hasBuild} method.
126130
* </p>
127131
*
128132
* @return The value of the Build property for this object.
@@ -132,8 +136,11 @@ public final List<String> build() {
132136
}
133137

134138
/**
135-
* Returns true if the Super property was specified by the sender (it may be empty), or false if the sender did not
136-
* specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
139+
* For responses, this returns true if the service returned a value for the Super property. This DOES NOT check that
140+
* the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful
141+
* because the SDK will never return a null collection or map, but you may need to differentiate between the service
142+
* returning nothing (or null) and the service returning an empty collection or map. For requests, this returns true
143+
* if a value for the property was specified in the request builder, and false if a value was not specified.
137144
*/
138145
public final boolean hasSuperValue() {
139146
return superValue != null && !(superValue instanceof SdkAutoConstructList);
@@ -145,7 +152,8 @@ public final boolean hasSuperValue() {
145152
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
146153
* </p>
147154
* <p>
148-
* You can use {@link #hasSuperValue()} to see if a value was sent in this field.
155+
* This method will never return null. If you would like to know whether the service returned this field (so that
156+
* you can differentiate between null and empty), you can use the {@link #hasSuperValue} method.
149157
* </p>
150158
*
151159
* @return The value of the Super property for this object.
@@ -155,8 +163,12 @@ public final List<String> superValue() {
155163
}
156164

157165
/**
158-
* Returns true if the ToString property was specified by the sender (it may be empty), or false if the sender did
159-
* not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
166+
* For responses, this returns true if the service returned a value for the ToString property. This DOES NOT check
167+
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
168+
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
169+
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
170+
* returns true if a value for the property was specified in the request builder, and false if a value was not
171+
* specified.
160172
*/
161173
public final boolean hasToStringValue() {
162174
return toStringValue != null && !(toStringValue instanceof SdkAutoConstructMap);
@@ -168,7 +180,8 @@ public final boolean hasToStringValue() {
168180
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
169181
* </p>
170182
* <p>
171-
* You can use {@link #hasToStringValue()} to see if a value was sent in this field.
183+
* This method will never return null. If you would like to know whether the service returned this field (so that
184+
* you can differentiate between null and empty), you can use the {@link #hasToStringValue} method.
172185
* </p>
173186
*
174187
* @return The value of the ToString property for this object.
@@ -178,8 +191,12 @@ public final Map<String, String> toStringValue() {
178191
}
179192

180193
/**
181-
* Returns true if the Equals property was specified by the sender (it may be empty), or false if the sender did not
182-
* specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
194+
* For responses, this returns true if the service returned a value for the Equals property. This DOES NOT check
195+
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
196+
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
197+
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
198+
* returns true if a value for the property was specified in the request builder, and false if a value was not
199+
* specified.
183200
*/
184201
public final boolean hasEqualsValue() {
185202
return equalsValue != null && !(equalsValue instanceof SdkAutoConstructMap);
@@ -191,7 +208,8 @@ public final boolean hasEqualsValue() {
191208
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
192209
* </p>
193210
* <p>
194-
* You can use {@link #hasEqualsValue()} to see if a value was sent in this field.
211+
* This method will never return null. If you would like to know whether the service returned this field (so that
212+
* you can differentiate between null and empty), you can use the {@link #hasEqualsValue} method.
195213
* </p>
196214
*
197215
* @return The value of the Equals property for this object.

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/model/existencechecknamingresponse.java

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ private ExistenceCheckNamingResponse(BuilderImpl builder) {
107107
}
108108

109109
/**
110-
* Returns true if the Build property was specified by the sender (it may be empty), or false if the sender did not
111-
* specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
110+
* For responses, this returns true if the service returned a value for the Build property. This DOES NOT check that
111+
* the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful
112+
* because the SDK will never return a null collection or map, but you may need to differentiate between the service
113+
* returning nothing (or null) and the service returning an empty collection or map. For requests, this returns true
114+
* if a value for the property was specified in the request builder, and false if a value was not specified.
112115
*/
113116
public final boolean hasBuild() {
114117
return build != null && !(build instanceof SdkAutoConstructList);
@@ -120,7 +123,8 @@ public final boolean hasBuild() {
120123
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
121124
* </p>
122125
* <p>
123-
* You can use {@link #hasBuild()} to see if a value was sent in this field.
126+
* This method will never return null. If you would like to know whether the service returned this field (so that
127+
* you can differentiate between null and empty), you can use the {@link #hasBuild} method.
124128
* </p>
125129
*
126130
* @return The value of the Build property for this object.
@@ -130,8 +134,11 @@ public final List<String> build() {
130134
}
131135

132136
/**
133-
* Returns true if the Super property was specified by the sender (it may be empty), or false if the sender did not
134-
* specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
137+
* For responses, this returns true if the service returned a value for the Super property. This DOES NOT check that
138+
* the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful
139+
* because the SDK will never return a null collection or map, but you may need to differentiate between the service
140+
* returning nothing (or null) and the service returning an empty collection or map. For requests, this returns true
141+
* if a value for the property was specified in the request builder, and false if a value was not specified.
135142
*/
136143
public final boolean hasSuperValue() {
137144
return superValue != null && !(superValue instanceof SdkAutoConstructList);
@@ -143,7 +150,8 @@ public final boolean hasSuperValue() {
143150
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
144151
* </p>
145152
* <p>
146-
* You can use {@link #hasSuperValue()} to see if a value was sent in this field.
153+
* This method will never return null. If you would like to know whether the service returned this field (so that
154+
* you can differentiate between null and empty), you can use the {@link #hasSuperValue} method.
147155
* </p>
148156
*
149157
* @return The value of the Super property for this object.
@@ -153,8 +161,12 @@ public final List<String> superValue() {
153161
}
154162

155163
/**
156-
* Returns true if the ToString property was specified by the sender (it may be empty), or false if the sender did
157-
* not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
164+
* For responses, this returns true if the service returned a value for the ToString property. This DOES NOT check
165+
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
166+
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
167+
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
168+
* returns true if a value for the property was specified in the request builder, and false if a value was not
169+
* specified.
158170
*/
159171
public final boolean hasToStringValue() {
160172
return toStringValue != null && !(toStringValue instanceof SdkAutoConstructMap);
@@ -166,7 +178,8 @@ public final boolean hasToStringValue() {
166178
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
167179
* </p>
168180
* <p>
169-
* You can use {@link #hasToStringValue()} to see if a value was sent in this field.
181+
* This method will never return null. If you would like to know whether the service returned this field (so that
182+
* you can differentiate between null and empty), you can use the {@link #hasToStringValue} method.
170183
* </p>
171184
*
172185
* @return The value of the ToString property for this object.
@@ -176,8 +189,12 @@ public final Map<String, String> toStringValue() {
176189
}
177190

178191
/**
179-
* Returns true if the Equals property was specified by the sender (it may be empty), or false if the sender did not
180-
* specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
192+
* For responses, this returns true if the service returned a value for the Equals property. This DOES NOT check
193+
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
194+
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
195+
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
196+
* returns true if a value for the property was specified in the request builder, and false if a value was not
197+
* specified.
181198
*/
182199
public final boolean hasEqualsValue() {
183200
return equalsValue != null && !(equalsValue instanceof SdkAutoConstructMap);
@@ -189,7 +206,8 @@ public final boolean hasEqualsValue() {
189206
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
190207
* </p>
191208
* <p>
192-
* You can use {@link #hasEqualsValue()} to see if a value was sent in this field.
209+
* This method will never return null. If you would like to know whether the service returned this field (so that
210+
* you can differentiate between null and empty), you can use the {@link #hasEqualsValue} method.
193211
* </p>
194212
*
195213
* @return The value of the Equals property for this object.

0 commit comments

Comments
 (0)