Skip to content

Commit 7aefbeb

Browse files
committed
Handle response class generation for nested values in paginators
1 parent c6492ee commit 7aefbeb

File tree

21 files changed

+515
-216
lines changed

21 files changed

+515
-216
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/PaginatorsGeneratorTasks.java

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
/*
2-
* Copyright 2011-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at:
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
77
*
8-
* http://aws.amazon.com/apache2.0
8+
* http://aws.amazon.com/apache2.0
99
*
10-
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
11-
* OR CONDITIONS OF ANY KIND, either express or implied. See the
12-
* License for the specific language governing permissions and
13-
* limitations under the License.
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
1414
*/
15+
1516
package software.amazon.awssdk.codegen.emitters.tasks;
1617

18+
import static software.amazon.awssdk.utils.FunctionalUtils.safeFunction;
19+
20+
import java.io.IOException;
21+
import java.util.List;
22+
import java.util.Map;
23+
import java.util.stream.Collectors;
1724
import software.amazon.awssdk.codegen.emitters.GeneratorTask;
1825
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
1926
import software.amazon.awssdk.codegen.emitters.PoetGeneratorTask;
2027
import software.amazon.awssdk.codegen.model.service.PaginatorDefinition;
2128
import software.amazon.awssdk.codegen.poet.ClassSpec;
2229
import software.amazon.awssdk.codegen.poet.model.PaginatorResponseClassSpec;
2330

24-
import java.io.IOException;
25-
import java.util.ArrayList;
26-
import java.util.List;
27-
import java.util.Map;
28-
29-
import static software.amazon.awssdk.utils.FunctionalUtils.safeFunction;
30-
3131
public class PaginatorsGeneratorTasks extends BaseGeneratorTasks {
3232

3333
private final String modelClassDir;
@@ -39,19 +39,15 @@ public PaginatorsGeneratorTasks(GeneratorTaskParams dependencies) {
3939

4040
@Override
4141
protected boolean hasTasks() {
42-
return model.getHasPaginators();
42+
return model.hasPaginators();
4343
}
4444

4545
@Override
4646
protected List<GeneratorTask> createTasks() throws Exception {
4747
info("Emitting paginator classes");
48-
List<GeneratorTask> tasks = new ArrayList<>();
49-
50-
model.getPaginators().entrySet().stream()
48+
return model.getPaginators().entrySet().stream()
5149
.map(safeFunction(this::createTask))
52-
.forEach(tasks::add);
53-
54-
return tasks;
50+
.collect(Collectors.toList());
5551
}
5652

5753
private GeneratorTask createTask(Map.Entry<String, PaginatorDefinition> entry) throws IOException {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import java.util.Map;
2626
import software.amazon.awssdk.codegen.internal.Utils;
2727
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
28+
import software.amazon.awssdk.codegen.model.service.PaginatorDefinition;
2829
import software.amazon.awssdk.core.AmazonWebServiceResult;
2930
import software.amazon.awssdk.core.ResponseMetadata;
3031
import software.amazon.awssdk.core.util.ValidationUtils;
31-
import software.amazon.awssdk.codegen.model.service.PaginatorDefinition;
3232
import software.amazon.awssdk.utils.IoUtils;
3333

3434
public final class IntermediateModel {
@@ -180,7 +180,7 @@ public boolean getHasWaiters() {
180180
return waiters.size() > 0;
181181
}
182182

183-
public boolean getHasPaginators() {
183+
public boolean hasPaginators() {
184184
return paginators.size() > 0;
185185
}
186186

codegen/src/main/java/software/amazon/awssdk/codegen/model/service/PaginatorDefinition.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/*
2-
* Copyright 2011-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at:
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
77
*
8-
* http://aws.amazon.com/apache2.0
8+
* http://aws.amazon.com/apache2.0
99
*
10-
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
11-
* OR CONDITIONS OF ANY KIND, either express or implied. See the
12-
* License for the specific language governing permissions and
13-
* limitations under the License.
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
1414
*/
1515

1616
package software.amazon.awssdk.codegen.model.service;

codegen/src/main/java/software/amazon/awssdk/codegen/model/service/Paginators.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/*
2-
* Copyright 2011-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at:
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
77
*
8-
* http://aws.amazon.com/apache2.0
8+
* http://aws.amazon.com/apache2.0
99
*
10-
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
11-
* OR CONDITIONS OF ANY KIND, either express or implied. See the
12-
* License for the specific language governing permissions and
13-
* limitations under the License.
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
1414
*/
1515

1616
package software.amazon.awssdk.codegen.model.service;

codegen/src/main/java/software/amazon/awssdk/codegen/naming/DefaultNamingStrategy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,5 @@ public String getBeanStyleSetterMethodName(String memberName) {
181181
public String getFluentSetterMethodName(String memberName) {
182182
return Utils.unCapitialize(memberName);
183183
}
184+
184185
}

codegen/src/main/java/software/amazon/awssdk/codegen/naming/NamingStrategy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,5 @@ public interface NamingStrategy {
9292
* @return Appropriate name to use for fluent setter method (i.e. withFoo) for a model class member.
9393
*/
9494
String getFluentSetterMethodName(String memberName);
95+
9596
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/PoetExtensions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import com.squareup.javapoet.ClassName;
1919
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
20-
import software.amazon.awssdk.utils.StringUtils;
2120

2221
/**
2322
* Extension and convenience methods to Poet that use the intermediate model.

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientClass.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
import software.amazon.awssdk.codegen.poet.client.specs.JsonProtocolSpec;
4141
import software.amazon.awssdk.codegen.poet.client.specs.ProtocolSpec;
4242
import software.amazon.awssdk.codegen.poet.client.specs.QueryXmlProtocolSpec;
43+
import software.amazon.awssdk.codegen.utils.PaginatorUtils;
4344
import software.amazon.awssdk.core.auth.presign.PresignerParams;
4445
import software.amazon.awssdk.core.client.ClientHandler;
4546
import software.amazon.awssdk.core.config.AdvancedClientOption;
4647
import software.amazon.awssdk.core.config.ClientConfiguration;
4748
import software.amazon.awssdk.core.config.SyncClientConfiguration;
48-
import software.amazon.awssdk.codegen.utils.PaginatorUtils;
4949

5050
public class SyncClientClass implements ClassSpec {
5151

@@ -158,11 +158,13 @@ private List<MethodSpec> operationMethodSpecs(OperationModel opModel) {
158158

159159
// Add extra methods for paginated operations
160160
if (model.getPaginators().keySet().contains(opModel.getOperationName())) {
161-
methods.add(SyncClientInterface.operationMethodSignature(model, opModel, PaginatorUtils.getSyncMethodName(opModel.getMethodName()))
161+
methods.add(SyncClientInterface.operationMethodSignature(model, opModel,
162+
PaginatorUtils.getSyncMethodName(opModel.getMethodName()))
162163
.addAnnotation(Override.class)
163164
.returns(poetExtensions.getResponseClassForPaginatedOperation(opModel.getOperationName()))
164165
.addCode("\n")
165-
.addStatement("$T firstPage = $L($L)", returnType, opModel.getMethodName(), opModel.getInput().getVariableName())
166+
.addStatement("$T firstPage = $L($L)", returnType, opModel.getMethodName(),
167+
opModel.getInput().getVariableName())
166168
.addCode("\n")
167169
.addStatement("return new $T(this, $L, firstPage)",
168170
poetExtensions.getResponseClassForPaginatedOperation(opModel.getOperationName()),

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientInterface.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ static MethodSpec.Builder operationMethodSignature(IntermediateModel model, Oper
211211
}
212212

213213

214-
private MethodSpec.Builder operationSimpleMethodSignature(IntermediateModel model, OperationModel opModel, String methodName) {
214+
private MethodSpec.Builder operationSimpleMethodSignature(IntermediateModel model,
215+
OperationModel opModel,
216+
String methodName) {
217+
215218
TypeName returnType = ClassName.get(model.getMetadata().getFullModelPackageName(),
216219
opModel.getReturnType().getReturnType());
217220

0 commit comments

Comments
 (0)