Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Java: don't use List<ResourceName> in flattened methods (#2131)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamlin authored Jul 3, 2018
1 parent ad05c95 commit 05e0b02
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 76 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/google/api/codegen/config/FlatteningConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,20 @@ public FlatteningConfig withResourceNamesInSamplesOnly() {
Map.Entry::getKey, e -> e.getValue().withResourceNameInSampleOnly()));
return new AutoValue_FlatteningConfig(newFlattenedFieldConfigs, getFlatteningName());
}

public static boolean hasAnyRepeatedResourceNameParameter(FlatteningConfig flatteningGroup) {
// Used in Java to prevent generating a flattened method with List<ResourceName> as a parameter
// because that has the same type erasure as the version of the flattened method with
// List<String> as a parameter.

// TODO(gapic-generator issue #2137) Only use raw String type for repeated params
// not for singular params in the same flattened method.
return flatteningGroup
.getFlattenedFieldConfigs()
.values()
.stream()
.anyMatch(
(FieldConfig fieldConfig) ->
fieldConfig.getField().isRepeated() && fieldConfig.useResourceNameType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ private RequestObjectParamView getRequestObjectParams(
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext =
context.asFlattenedMethodContext(method, flatteningGroup);
if (FlatteningConfig.hasAnyRepeatedResourceNameParameter(flatteningGroup)) {
flattenedMethodContext = flattenedMethodContext.withResourceNamesInSamplesOnly();
}
Iterable<FieldConfig> fieldConfigs =
flattenedMethodContext.getFlatteningConfig().getFlattenedFieldConfigs().values();
for (FieldConfig fieldConfig : fieldConfigs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ public List<StaticLangApiMethodView> generateApiMethods(InterfaceContext context
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext =
context.asFlattenedMethodContext(method, flatteningGroup);
apiMethods.add(
clientMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext));
if (!FlatteningConfig.hasAnyRepeatedResourceNameParameter(flatteningGroup)) {
apiMethods.add(
clientMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext));
}
if (hasAnyResourceNameParameter(flatteningGroup)) {
apiMethods.add(
clientMethodTransformer.generatePagedFlattenedMethod(
Expand Down Expand Up @@ -105,6 +107,9 @@ public List<StaticLangApiMethodView> generateApiMethods(InterfaceContext context
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext =
context.asFlattenedMethodContext(method, flatteningGroup);
if (FlatteningConfig.hasAnyRepeatedResourceNameParameter(flatteningGroup)) {
flattenedMethodContext = flattenedMethodContext.withResourceNamesInSamplesOnly();
}
apiMethods.add(
clientMethodTransformer.generateAsyncOperationFlattenedMethod(
flattenedMethodContext));
Expand All @@ -126,6 +131,9 @@ public List<StaticLangApiMethodView> generateApiMethods(InterfaceContext context
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext =
context.asFlattenedMethodContext(method, flatteningGroup);
if (FlatteningConfig.hasAnyRepeatedResourceNameParameter(flatteningGroup)) {
flattenedMethodContext = flattenedMethodContext.withResourceNamesInSamplesOnly();
}
apiMethods.add(clientMethodTransformer.generateFlattenedMethod(flattenedMethodContext));

if (hasAnyResourceNameParameter(flatteningGroup)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ SmokeTestClassView.Builder createSmokeTestClassViewBuilder(InterfaceContext cont
testCaseTransformer.getSmokeTestFlatteningGroup(
context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
MethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
if (FlatteningConfig.hasAnyRepeatedResourceNameParameter(flatteningGroup)) {
methodContext = methodContext.withResourceNamesInSamplesOnly();
}

SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
StaticLangApiMethodView apiMethodView = createSmokeTestCaseApiMethodView(methodContext);
Expand Down Expand Up @@ -304,6 +307,10 @@ private List<TestCaseView> createTestCaseViews(InterfaceContext context) {
}
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
if (FlatteningConfig.hasAnyRepeatedResourceNameParameter(flatteningGroup)) {
methodContext = methodContext.withResourceNamesInSamplesOnly();
flatteningGroup = methodContext.getFlatteningConfig();
}
InitCodeContext initCodeContext =
initCodeTransformer.createRequestInitCodeContext(
methodContext,
Expand Down
Loading

0 comments on commit 05e0b02

Please sign in to comment.