use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class AbstractServiceSettingsClassComposer method createNestedBuilderCreatorMethods.
protected List<MethodDefinition> createNestedBuilderCreatorMethods(Service service, TypeStore typeStore, String newBuilderMethodName, String createDefaultMethodName) {
MethodInvocationExpr ctorArg = MethodInvocationExpr.builder().setStaticReferenceType(typeStore.get(ClassNames.getServiceStubSettingsClassName(service))).setMethodName(newBuilderMethodName).build();
TypeNode builderType = typeStore.get(BUILDER_CLASS_NAME);
return ImmutableList.of(MethodDefinition.builder().setScope(ScopeNode.PRIVATE).setIsStatic(true).setReturnType(builderType).setName(createDefaultMethodName).setReturnExpr(NewObjectExpr.builder().setType(builderType).setArguments(ctorArg).build()).build());
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class AbstractServiceSettingsClassComposer method createConstructorMethod.
private static MethodDefinition createConstructorMethod(Service service, TypeStore typeStore) {
VariableExpr settingsBuilderVarExpr = VariableExpr.withVariable(Variable.builder().setName("settingsBuilder").setType(typeStore.get(BUILDER_CLASS_NAME)).build());
TypeNode thisClassType = typeStore.get(ClassNames.getServiceSettingsClassName(service));
return MethodDefinition.constructorBuilder().setScope(ScopeNode.PROTECTED).setReturnType(thisClassType).setArguments(Arrays.asList(settingsBuilderVarExpr.toBuilder().setIsDecl(true).build())).setThrowsExceptions(Arrays.asList(FIXED_TYPESTORE.get("IOException"))).setBody(Arrays.asList(ExprStatement.withExpr(ReferenceConstructorExpr.superBuilder().setType(FIXED_TYPESTORE.get("ClientSettings")).setArguments(settingsBuilderVarExpr).build()))).build();
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class AbstractServiceSettingsClassComposer method createCreatorMethod.
private static MethodDefinition createCreatorMethod(Service service, TypeStore typeStore) {
TypeNode stubClassType = typeStore.get(ClassNames.getServiceStubSettingsClassName(service));
VariableExpr stubVarExpr = VariableExpr.withVariable(Variable.builder().setName("stub").setType(stubClassType).build());
TypeNode thisClassType = typeStore.get(ClassNames.getServiceSettingsClassName(service));
MethodInvocationExpr stubBuilderMethodExpr = MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("toBuilder").build();
TypeNode stubBuilderType = TypeNode.withReference(VaporReference.builder().setName("Builder").setEnclosingClassNames(ClassNames.getServiceSettingsClassName(service)).setPakkage(service.pakkage()).build());
Expr returnMethodExpr = NewObjectExpr.builder().setType(stubBuilderType).setArguments(stubBuilderMethodExpr).build();
returnMethodExpr = MethodInvocationExpr.builder().setExprReferenceExpr(returnMethodExpr).setMethodName("build").setReturnType(thisClassType).build();
return MethodDefinition.builder().setScope(ScopeNode.PUBLIC).setIsStatic(true).setIsFinal(true).setReturnType(thisClassType).setName("create").setArguments(Arrays.asList(stubVarExpr.toBuilder().setIsDecl(true).build())).setThrowsExceptions(Arrays.asList(FIXED_TYPESTORE.get("IOException"))).setReturnExpr(returnMethodExpr).build();
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class AbstractServiceStubClassComposer method createCallableGetterHelper.
private MethodDefinition createCallableGetterHelper(Method method, TypeStore typeStore, boolean isLroCallable, boolean isPaged) {
TypeNode returnType;
switch(method.stream()) {
case CLIENT:
returnType = typeStore.get("ClientStreamingCallable");
break;
case SERVER:
returnType = typeStore.get("ServerStreamingCallable");
break;
case BIDI:
returnType = typeStore.get("BidiStreamingCallable");
break;
case NONE:
// Fall through.
default:
returnType = typeStore.get(isLroCallable ? "OperationCallable" : "UnaryCallable");
}
String methodName = String.format("%s%sCallable", JavaStyle.toLowerCamelCase(method.name()), (isLroCallable ? "Operation" : isPaged ? "Paged" : ""));
List<Reference> genericRefs = new ArrayList<>();
genericRefs.add(method.inputType().reference());
if (method.hasLro() && isLroCallable) {
genericRefs.add(method.lro().responseType().reference());
genericRefs.add(method.lro().metadataType().reference());
} else if (isPaged) {
genericRefs.add(typeStore.get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())).reference());
} else {
genericRefs.add(method.outputType().reference());
}
List<AnnotationNode> annotations = method.isDeprecated() ? Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED)) : Collections.emptyList();
returnType = TypeNode.withReference(returnType.reference().copyAndSetGenerics(genericRefs));
return createCallableGetterMethodDefinition(returnType, methodName, annotations, typeStore);
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class AbstractServiceStubClassComposer method createClassMethods.
private List<MethodDefinition> createClassMethods(Service service, Map<String, Message> messageTypes, TypeStore typeStore) {
List<MethodDefinition> methods = new ArrayList<>();
if (service.hasStandardLroMethods()) {
TypeNode operationsStubType = service.operationServiceStubType();
methods.addAll(createOperationsStubGetters(typeStore, operationsStubType));
}
if (service.operationPollingMethod() != null) {
methods.addAll(createLongRunningClientGetters(typeStore));
}
methods.addAll(createCallableGetters(service, messageTypes, typeStore));
methods.addAll(createBackgroundResourceMethodOverrides());
return methods;
}
Aggregations