use of com.google.api.generator.engine.ast.ClassDefinition in project gapic-generator-java by googleapis.
the class AbstractServiceStubSettingsClassComposer method generate.
@Override
public GapicClass generate(GapicContext context, Service service) {
// TODO(miraleung): Robustify this against a null serviceConfig.
GapicServiceConfig serviceConfig = context.serviceConfig();
Map<String, Message> messageTypes = context.messages();
String pakkage = String.format("%s.stub", service.pakkage());
TypeStore typeStore = createDynamicTypes(service, pakkage);
List<Sample> samples = new ArrayList<>();
Set<String> deprecatedSettingVarNames = new HashSet<>();
Map<String, VariableExpr> methodSettingsMemberVarExprs = createMethodSettingsClassMemberVarExprs(service, serviceConfig, typeStore, /* isNestedClass= */
false, deprecatedSettingVarNames);
String className = ClassNames.getServiceStubSettingsClassName(service);
List<CommentStatement> classHeaderComments = createClassHeaderComments(service, typeStore.get(className), samples);
ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setHeaderCommentStatements(classHeaderComments).setAnnotations(createClassAnnotations(service)).setScope(ScopeNode.PUBLIC).setName(className).setExtendsType(createExtendsType(service, typeStore)).setStatements(createClassStatements(service, serviceConfig, methodSettingsMemberVarExprs, messageTypes, typeStore)).setMethods(createClassMethods(service, methodSettingsMemberVarExprs, deprecatedSettingVarNames, typeStore)).setNestedClasses(Arrays.asList(createNestedBuilderClass(service, serviceConfig, typeStore))).build();
return GapicClass.create(GapicClass.Kind.STUB, classDef, SampleComposerUtil.handleDuplicateSamples(samples));
}
use of com.google.api.generator.engine.ast.ClassDefinition in project gapic-generator-java by googleapis.
the class AbstractTransportServiceStubClassComposer method generate.
@Override
public GapicClass generate(GapicContext context, Service service) {
String pakkage = service.pakkage() + ".stub";
TypeStore typeStore = createDynamicTypes(service, pakkage);
String className = getTransportContext().classNames().getTransportServiceStubClassName(service);
GapicClass.Kind kind = Kind.STUB;
Map<String, VariableExpr> protoMethodNameToDescriptorVarExprs = createProtoMethodNameToDescriptorClassMembers(service, getTransportContext().methodDescriptorClass());
Map<String, VariableExpr> callableClassMemberVarExprs = createCallableClassMembers(service, typeStore);
Map<String, VariableExpr> classMemberVarExprs = new LinkedHashMap<>();
classMemberVarExprs.put(BACKGROUND_RESOURCES_MEMBER_NAME, VariableExpr.withVariable(Variable.builder().setName(BACKGROUND_RESOURCES_MEMBER_NAME).setType(FIXED_TYPESTORE.get("BackgroundResource")).build()));
if (generateOperationsStubLogic(service)) {
// Transport-specific service stub may have only one element of the following, thus get(0).
TypeNode operationsStubType = getTransportOperationsStubType(service);
classMemberVarExprs.put(getTransportContext().transportOperationsStubNames().get(0), VariableExpr.withVariable(Variable.builder().setName(getTransportContext().transportOperationsStubNames().get(0)).setType(operationsStubType).build()));
}
boolean operationPollingMethod = checkOperationPollingMethod(service);
if (operationPollingMethod) {
VariableExpr longRunningVarExpr = declareLongRunningClient();
if (longRunningVarExpr != null) {
classMemberVarExprs.put("longRunningClient", longRunningVarExpr);
}
}
classMemberVarExprs.put(CALLABLE_FACTORY_MEMBER_NAME, VariableExpr.withVariable(Variable.builder().setName(CALLABLE_FACTORY_MEMBER_NAME).setType(getTransportContext().stubCallableFactoryType()).build()));
Map<String, Message> messageTypes = context.messages();
List<Statement> classStatements = createClassStatements(service, protoMethodNameToDescriptorVarExprs, callableClassMemberVarExprs, classMemberVarExprs, messageTypes);
StubCommentComposer commentComposer = new StubCommentComposer(getTransportContext().transportName());
ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setHeaderCommentStatements(commentComposer.createTransportServiceStubClassHeaderComments(service.name(), service.isDeprecated())).setAnnotations(createClassAnnotations(service)).setScope(ScopeNode.PUBLIC).setName(className).setExtendsType(typeStore.get(getTransportContext().classNames().getServiceStubClassName(service))).setMethods(createClassMethods(context, service, typeStore, classMemberVarExprs, callableClassMemberVarExprs, protoMethodNameToDescriptorVarExprs, classStatements)).setStatements(classStatements).build();
return GapicClass.create(kind, classDef);
}
use of com.google.api.generator.engine.ast.ClassDefinition in project gapic-generator-java by googleapis.
the class AbstractServiceClientClassComposer method generate.
@Override
public GapicClass generate(GapicContext context, Service service) {
Map<String, ResourceName> resourceNames = context.helperResourceNames();
Map<String, Message> messageTypes = context.messages();
TypeStore typeStore = createTypes(service, messageTypes);
String className = ClassNames.getServiceClientClassName(service);
GapicClass.Kind kind = Kind.MAIN;
String pakkage = service.pakkage();
boolean hasLroClient = service.hasStandardLroMethods();
List<Sample> samples = new ArrayList<>();
Map<String, List<String>> grpcRpcsToJavaMethodNames = new HashMap<>();
ClassDefinition classDef = ClassDefinition.builder().setHeaderCommentStatements(createClassHeaderComments(service, typeStore, resourceNames, messageTypes, samples)).setPackageString(pakkage).setAnnotations(createClassAnnotations(service, typeStore)).setScope(ScopeNode.PUBLIC).setName(className).setImplementsTypes(createClassImplements(typeStore)).setStatements(createFieldDeclarations(service, typeStore, hasLroClient)).setMethods(createClassMethods(service, messageTypes, typeStore, resourceNames, hasLroClient, grpcRpcsToJavaMethodNames, samples)).setNestedClasses(createNestedPagingClasses(service, messageTypes, typeStore)).build();
updateGapicMetadata(context, service, className, grpcRpcsToJavaMethodNames);
return GapicClass.create(kind, classDef, SampleComposerUtil.handleDuplicateSamples(samples));
}
use of com.google.api.generator.engine.ast.ClassDefinition in project gapic-generator-java by googleapis.
the class AbstractServiceSettingsClassComposer method generate.
@Override
public GapicClass generate(GapicContext context, Service service) {
String pakkage = service.pakkage();
TypeStore typeStore = createDynamicTypes(service);
String className = ClassNames.getServiceSettingsClassName(service);
GapicClass.Kind kind = Kind.MAIN;
List<Sample> samples = new ArrayList<>();
List<CommentStatement> classHeaderComments = createClassHeaderComments(service, typeStore.get(className), samples);
ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setHeaderCommentStatements(classHeaderComments).setAnnotations(createClassAnnotations(service)).setScope(ScopeNode.PUBLIC).setName(className).setExtendsType(TypeNode.withReference(FIXED_TYPESTORE.get("ClientSettings").reference().copyAndSetGenerics(Arrays.asList(typeStore.get(ClassNames.getServiceSettingsClassName(service)).reference())))).setMethods(createClassMethods(service, typeStore)).setNestedClasses(Arrays.asList(createNestedBuilderClass(service, typeStore))).build();
return GapicClass.create(kind, classDef, SampleComposerUtil.handleDuplicateSamples(samples));
}
use of com.google.api.generator.engine.ast.ClassDefinition in project gapic-generator-java by googleapis.
the class AbstractServiceClientClassComposer method createNestedPagingClasses.
private static List<ClassDefinition> createNestedPagingClasses(Service service, Map<String, Message> messageTypes, TypeStore typeStore) {
List<ClassDefinition> nestedClasses = new ArrayList<>();
for (Method method : service.methods()) {
if (!method.isPaged()) {
continue;
}
// Find the repeated field.
Message methodOutputMessage = messageTypes.get(method.outputType().reference().fullName());
Field repeatedPagedResultsField = methodOutputMessage.findAndUnwrapPaginatedRepeatedField();
Preconditions.checkNotNull(repeatedPagedResultsField, String.format("No repeated field found on message %s for method %s", methodOutputMessage.name(), method.name()));
TypeNode repeatedResponseType = repeatedPagedResultsField.type();
nestedClasses.add(createNestedRpcPagedResponseClass(method, repeatedResponseType, messageTypes, typeStore));
nestedClasses.add(createNestedRpcPageClass(method, repeatedResponseType, messageTypes, typeStore));
nestedClasses.add(createNestedRpcFixedSizeCollectionClass(method, repeatedResponseType, messageTypes, typeStore));
}
return nestedClasses;
}
Aggregations