Skip to content

Commit

Permalink
Revert "fix: fixes regionTag breakage (#1068)"
Browse files Browse the repository at this point in the history
This reverts commit cd35be8.
  • Loading branch information
emmileaf authored Nov 3, 2022
1 parent e8521e9 commit 0c731de
Show file tree
Hide file tree
Showing 306 changed files with 746 additions and 1,118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,9 @@ protected List<CommentStatement> createClassHeaderComments(
ServiceClientHeaderSampleComposer.composeClassHeaderSample(
service, clientType, resourceNames, messageTypes);
Sample credentialsSampleCode =
ServiceClientHeaderSampleComposer.composeSetCredentialsSample(
clientType, settingsType, service);
ServiceClientHeaderSampleComposer.composeSetCredentialsSample(clientType, settingsType);
Sample endpointSampleCode =
ServiceClientHeaderSampleComposer.composeSetEndpointSample(
clientType, settingsType, service);
ServiceClientHeaderSampleComposer.composeSetEndpointSample(clientType, settingsType);
samples.addAll(Arrays.asList(classMethodSampleCode, credentialsSampleCode, endpointSampleCode));
return ServiceClientCommentComposer.createClassHeaderComments(
service,
Expand Down Expand Up @@ -582,8 +580,7 @@ private static List<MethodDefinition> createServiceMethods(
messageTypes,
typeStore,
resourceNames,
samples,
service);
samples);

// Collect data for gapic_metadata.json.
grpcRpcToJavaMethodMetadata
Expand All @@ -601,8 +598,7 @@ private static List<MethodDefinition> createServiceMethods(
messageTypes,
typeStore,
resourceNames,
samples,
service);
samples);

// Collect data for gapic_metadata.json.
grpcRpcToJavaMethodMetadata.get(method.name()).add(javaMethodNameFn.apply(generatedMethod));
Expand Down Expand Up @@ -642,8 +638,7 @@ private static List<MethodDefinition> createMethodVariants(
Map<String, Message> messageTypes,
TypeStore typeStore,
Map<String, ResourceName> resourceNames,
List<Sample> samples,
Service service) {
List<Sample> samples) {
List<MethodDefinition> javaMethods = new ArrayList<>();
String methodName = JavaStyle.toLowerCamelCase(method.name());
TypeNode methodInputType = method.inputType();
Expand Down Expand Up @@ -707,12 +702,7 @@ private static List<MethodDefinition> createMethodVariants(
Optional<Sample> methodSample =
Optional.of(
ServiceClientHeaderSampleComposer.composeShowcaseMethodSample(
method,
typeStore.get(clientName),
signature,
resourceNames,
messageTypes,
service));
method, typeStore.get(clientName), signature, resourceNames, messageTypes));
Optional<String> methodDocSample = Optional.empty();
if (methodSample.isPresent()) {
samples.add(methodSample.get());
Expand Down Expand Up @@ -756,8 +746,7 @@ private static MethodDefinition createMethodDefaultMethod(
Map<String, Message> messageTypes,
TypeStore typeStore,
Map<String, ResourceName> resourceNames,
List<Sample> samples,
Service service) {
List<Sample> samples) {
String methodName = JavaStyle.toLowerCamelCase(method.name());
TypeNode methodInputType = method.inputType();
TypeNode methodOutputType =
Expand Down Expand Up @@ -801,7 +790,7 @@ private static MethodDefinition createMethodDefaultMethod(
Optional<Sample> defaultMethodSample =
Optional.of(
ServiceClientMethodSampleComposer.composeCanonicalSample(
method, typeStore.get(clientName), resourceNames, messageTypes, service));
method, typeStore.get(clientName), resourceNames, messageTypes));
Optional<String> defaultMethodDocSample = Optional.empty();
if (defaultMethodSample.isPresent()) {
samples.add(defaultMethodSample.get());
Expand Down Expand Up @@ -943,17 +932,15 @@ private static MethodDefinition createCallableMethod(
method,
typeStore.get(ClassNames.getServiceClientClassName(service)),
resourceNames,
messageTypes,
service));
messageTypes));
} else if (callableMethodKind.equals(CallableMethodKind.PAGED)) {
sampleCode =
Optional.of(
ServiceClientCallableMethodSampleComposer.composePagedCallableMethod(
method,
typeStore.get(ClassNames.getServiceClientClassName(service)),
resourceNames,
messageTypes,
service));
messageTypes));
} else if (callableMethodKind.equals(CallableMethodKind.REGULAR)) {
if (method.stream().equals(Stream.NONE)) {
sampleCode =
Expand All @@ -962,17 +949,15 @@ private static MethodDefinition createCallableMethod(
method,
typeStore.get(ClassNames.getServiceClientClassName(service)),
resourceNames,
messageTypes,
service));
messageTypes));
} else {
sampleCode =
Optional.of(
ServiceClientCallableMethodSampleComposer.composeStreamCallableMethod(
method,
typeStore.get(ClassNames.getServiceClientClassName(service)),
resourceNames,
messageTypes,
service));
messageTypes));
}
}
Optional<String> sampleDocCode = Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ protected List<CommentStatement> createClassHeaderComments(
ServiceClientHeaderSampleComposer.composeClassHeaderSample(
service, clientType, resourceNames, messageTypes);
Sample credentialsSampleCode =
ServiceClientHeaderSampleComposer.composeSetCredentialsSample(
clientType, settingsType, service);
ServiceClientHeaderSampleComposer.composeSetCredentialsSample(clientType, settingsType);
Sample endpointSampleCode =
ServiceClientHeaderSampleComposer.composeSetEndpointSample(
clientType, settingsType, service);
ServiceClientHeaderSampleComposer.composeSetEndpointSample(clientType, settingsType);
Sample transportSampleCode =
ServiceClientHeaderSampleComposer.composeTransportSample(
clientType, settingsType, "newHttpJsonBuilder", service);
clientType, settingsType, "newHttpJsonBuilder");
samples.addAll(
Arrays.asList(
classMethodSampleCode, credentialsSampleCode, endpointSampleCode, transportSampleCode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.engine.ast.WhileStatement;
import com.google.api.generator.gapic.composer.defaultvalue.DefaultValueComposer;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.Field;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.Method;
import com.google.api.generator.gapic.model.RegionTag;
import com.google.api.generator.gapic.model.ResourceName;
import com.google.api.generator.gapic.model.Sample;
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.utils.JavaStyle;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
Expand All @@ -61,7 +61,7 @@

public class ServiceClientCallableMethodSampleComposer {
private static Sample composeUnaryOrLroCallableSample(
Method method, VariableExpr clientVarExpr, VariableExpr requestVarExpr, Service service) {
Method method, VariableExpr clientVarExpr, VariableExpr requestVarExpr) {
List<Statement> bodyStatements = new ArrayList<>();
// Create api future variable expression, and assign it with a value by invoking callable
// method.
Expand Down Expand Up @@ -125,7 +125,8 @@ private static Sample composeUnaryOrLroCallableSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(service.name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
Expand All @@ -140,8 +141,7 @@ private static Sample composePagedCallableSample(
Method method,
VariableExpr clientVarExpr,
VariableExpr requestVarExpr,
Map<String, Message> messageTypes,
Service service) {
Map<String, Message> messageTypes) {
// Find the repeated field.
Message methodOutputMessage = messageTypes.get(method.outputType().reference().fullName());
Field repeatedPagedResultsField = methodOutputMessage.findAndUnwrapPaginatedRepeatedField();
Expand Down Expand Up @@ -280,7 +280,8 @@ private static Sample composePagedCallableSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(service.name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setOverloadDisambiguation("Paged")
.setIsAsynchronous(true)
Expand All @@ -296,8 +297,7 @@ public static Sample composeLroCallableMethod(
Method method,
TypeNode clientType,
Map<String, ResourceName> resourceNames,
Map<String, Message> messageTypes,
Service service) {
Map<String, Message> messageTypes) {
VariableExpr clientVarExpr =
VariableExpr.withVariable(
Variable.builder()
Expand Down Expand Up @@ -397,7 +397,7 @@ public static Sample composeLroCallableMethod(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(service.name())
.setServiceName(ClassNames.getPureServiceName(clientType.reference().name()))
.setRpcName(method.name())
.setIsAsynchronous(true)
.setOverloadDisambiguation("LRO")
Expand All @@ -418,8 +418,7 @@ public static Sample composePagedCallableMethod(
Method method,
TypeNode clientType,
Map<String, ResourceName> resourceNames,
Map<String, Message> messageTypes,
Service service) {
Map<String, Message> messageTypes) {
VariableExpr clientVarExpr =
VariableExpr.withVariable(
Variable.builder()
Expand Down Expand Up @@ -535,7 +534,7 @@ public static Sample composePagedCallableMethod(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(service.name())
.setServiceName(ClassNames.getPureServiceName(clientType.reference().name()))
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
Expand All @@ -547,8 +546,7 @@ public static Sample composeRegularCallableMethod(
Method method,
TypeNode clientType,
Map<String, ResourceName> resourceNames,
Map<String, Message> messageTypes,
Service service) {
Map<String, Message> messageTypes) {
VariableExpr clientVarExpr =
VariableExpr.withVariable(
Variable.builder()
Expand Down Expand Up @@ -580,13 +578,13 @@ public static Sample composeRegularCallableMethod(
RegionTag regionTag;
if (method.isPaged()) {
Sample pagedCallable =
composePagedCallableSample(method, clientVarExpr, requestVarExpr, messageTypes, service);
composePagedCallableSample(method, clientVarExpr, requestVarExpr, messageTypes);
bodyStatements.addAll(pagedCallable.body());
regionTag = pagedCallable.regionTag();
} else {
// e.g. echoClient.echoCallable().futureCall(request)
Sample unaryOrLroCallable =
composeUnaryOrLroCallableSample(method, clientVarExpr, requestVarExpr, service);
composeUnaryOrLroCallableSample(method, clientVarExpr, requestVarExpr);
bodyStatements.addAll(unaryOrLroCallable.body());
regionTag = unaryOrLroCallable.regionTag();
}
Expand All @@ -606,8 +604,7 @@ public static Sample composeStreamCallableMethod(
Method method,
TypeNode clientType,
Map<String, ResourceName> resourceNames,
Map<String, Message> messageTypes,
Service service) {
Map<String, Message> messageTypes) {
VariableExpr clientVarExpr =
VariableExpr.withVariable(
Variable.builder()
Expand Down Expand Up @@ -636,19 +633,16 @@ public static Sample composeStreamCallableMethod(
List<Statement> bodyStatements = new ArrayList<>();
if (method.stream().equals(Method.Stream.SERVER)) {
// e.g. ServerStream<EchoResponse> stream = echoClient.expandCallable().call(request);
Sample streamServer =
composeStreamServerSample(method, clientVarExpr, requestAssignmentExpr, service);
Sample streamServer = composeStreamServerSample(method, clientVarExpr, requestAssignmentExpr);
bodyStatements.addAll(streamServer.body());
regionTag = streamServer.regionTag();
} else if (method.stream().equals(Method.Stream.BIDI)) {
// e.g. echoClient.collect().clientStreamingCall(responseObserver);
Sample streamBidi =
composeStreamBidiSample(method, clientVarExpr, requestAssignmentExpr, service);
Sample streamBidi = composeStreamBidiSample(method, clientVarExpr, requestAssignmentExpr);
bodyStatements.addAll(streamBidi.body());
regionTag = streamBidi.regionTag();
} else if (method.stream().equals(Method.Stream.CLIENT)) {
Sample streamClient =
composeStreamClientSample(method, clientVarExpr, requestAssignmentExpr, service);
Sample streamClient = composeStreamClientSample(method, clientVarExpr, requestAssignmentExpr);
bodyStatements.addAll(streamClient.body());
regionTag = streamClient.regionTag();
}
Expand All @@ -665,10 +659,7 @@ public static Sample composeStreamCallableMethod(
}

private static Sample composeStreamServerSample(
Method method,
VariableExpr clientVarExpr,
AssignmentExpr requestAssignmentExpr,
Service service) {
Method method, VariableExpr clientVarExpr, AssignmentExpr requestAssignmentExpr) {
List<Expr> bodyExprs = new ArrayList<>();
bodyExprs.add(requestAssignmentExpr);

Expand Down Expand Up @@ -729,18 +720,16 @@ private static Sample composeStreamServerSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(service.name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
return Sample.builder().setBody(bodyStatements).setRegionTag(regionTag).build();
}

private static Sample composeStreamBidiSample(
Method method,
VariableExpr clientVarExpr,
AssignmentExpr requestAssignmentExpr,
Service service) {
Method method, VariableExpr clientVarExpr, AssignmentExpr requestAssignmentExpr) {
List<Expr> bodyExprs = new ArrayList<>();

// Create bidi stream variable expression and assign it with invoking client's bidi stream
Expand Down Expand Up @@ -811,18 +800,16 @@ private static Sample composeStreamBidiSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(service.name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
return Sample.builder().setBody(bodyStatements).setRegionTag(regionTag).build();
}

private static Sample composeStreamClientSample(
Method method,
VariableExpr clientVarExpr,
AssignmentExpr requestAssignmentExpr,
Service service) {
Method method, VariableExpr clientVarExpr, AssignmentExpr requestAssignmentExpr) {
List<Expr> bodyExprs = new ArrayList<>();

// Create responseObserver variable expression.
Expand Down Expand Up @@ -946,7 +933,8 @@ private static Sample composeStreamClientSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(service.name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
Expand Down
Loading

0 comments on commit 0c731de

Please sign in to comment.