Skip to content

Commit 29d03d1

Browse files
committed
Null checks -> Optional
1 parent 4f2daea commit 29d03d1

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

tools/code-generation/smithy/cpp-codegen/smithy-cpp-codegen/src/main/java/com/amazonaws/util/awsclientsmithygenerator/generators/model/MemberRenderer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,13 @@ public static void renderClassDocComment(CppWriter writer, Shape shape,
273273
}
274274
}
275275

276+
/**
277+
* Collapses all runs of whitespace in {@code text} to single spaces and trims the result.
278+
*
279+
* @param text the documentation text to normalize; must not be null
280+
* @return the whitespace-collapsed text
281+
*/
276282
public static String collapseWhitespace(String text) {
277-
if (text == null) {
278-
return null;
279-
}
280283
return text.replaceAll("\\s+", " ").trim();
281284
}
282285

tools/code-generation/smithy/cpp-codegen/smithy-cpp-codegen/src/main/java/com/amazonaws/util/awsclientsmithygenerator/generators/model/renderers/EventStreamRenderer.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.util.ArrayList;
2626
import java.util.List;
27+
import java.util.Optional;
2728

2829
/**
2930
* Renders C++ event stream artifacts for response-side (simplex) streaming operations:
@@ -59,10 +60,11 @@ public EventStreamRenderer(List<EventStreamInfo> eventStreams, Model model, Serv
5960
@Override
6061
public void render(CppWriterDelegator writerDelegator) {
6162
for (EventStreamInfo info : eventStreams) {
62-
UnionShape union = findStreamingUnion(info.resultShape());
63-
if (union == null) {
63+
Optional<UnionShape> streamingUnion = findStreamingUnion(info.resultShape());
64+
if (streamingUnion.isEmpty()) {
6465
continue;
6566
}
67+
UnionShape union = streamingUnion.get();
6668
List<MemberShape> events = new ArrayList<>();
6769
List<MemberShape> exceptions = new ArrayList<>();
6870
partitionMembers(union, events, exceptions);
@@ -74,15 +76,15 @@ public void render(CppWriterDelegator writerDelegator) {
7476
}
7577
}
7678

77-
/** Finds the @streaming union targeted by a member of the result structure. */
78-
private UnionShape findStreamingUnion(StructureShape resultShape) {
79+
/** Finds the @streaming union targeted by a member of the result structure, if any. */
80+
private Optional<UnionShape> findStreamingUnion(StructureShape resultShape) {
7981
for (MemberShape member : resultShape.getAllMembers().values()) {
8082
Shape target = model.expectShape(member.getTarget());
8183
if (target.isUnionShape() && target.hasTrait(StreamingTrait.class)) {
82-
return target.asUnionShape().get();
84+
return target.asUnionShape();
8385
}
8486
}
85-
return null;
87+
return Optional.empty();
8688
}
8789

8890
/** Splits union members into events (non-exception) and exceptions, preserving order. */

0 commit comments

Comments
 (0)