use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class AbstractServiceSettingsClassComposer method createNestedBuilderApplyToAllUnaryMethod.
private static MethodDefinition createNestedBuilderApplyToAllUnaryMethod(Service service, TypeStore typeStore) {
TypeNode builderType = typeStore.get(BUILDER_CLASS_NAME);
String javaMethodName = "applyToAllUnaryMethods";
TypeNode unaryCallSettingsType = TypeNode.withReference(ConcreteReference.builder().setClazz(UnaryCallSettings.Builder.class).setGenerics(Arrays.asList(TypeNode.WILDCARD_REFERENCE, TypeNode.WILDCARD_REFERENCE)).build());
VariableExpr settingsUpdaterVarExpr = VariableExpr.withVariable(Variable.builder().setName("settingsUpdater").setType(TypeNode.withReference(FIXED_TYPESTORE.get("ApiFunction").reference().copyAndSetGenerics(Arrays.asList(unaryCallSettingsType.reference(), TypeNode.VOID_OBJECT.reference())))).build());
MethodInvocationExpr builderMethodExpr = MethodInvocationExpr.builder().setMethodName("getStubSettingsBuilder").build();
builderMethodExpr = MethodInvocationExpr.builder().setExprReferenceExpr(builderMethodExpr).setMethodName("unaryMethodSettingsBuilders").build();
MethodInvocationExpr applyMethodExpr = MethodInvocationExpr.builder().setExprReferenceExpr(ValueExpr.withValue(SuperObjectValue.withType(TypeNode.withReference(ConcreteReference.withClazz(ClientSettings.Builder.class))))).setMethodName(javaMethodName).setArguments(Arrays.asList(builderMethodExpr, settingsUpdaterVarExpr)).build();
return MethodDefinition.builder().setHeaderCommentStatements(SettingsCommentComposer.APPLY_TO_ALL_UNARY_METHODS_METHOD_COMMENTS).setScope(ScopeNode.PUBLIC).setReturnType(builderType).setName(javaMethodName).setArguments(Arrays.asList(settingsUpdaterVarExpr.toBuilder().setIsDecl(true).build())).setBody(Arrays.asList(ExprStatement.withExpr(applyMethodExpr))).setReturnExpr(ValueExpr.withValue(ThisObjectValue.withType(builderType))).build();
}
use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class AbstractServiceSettingsClassComposer method createNestedBuilderConstructorMethods.
private static List<MethodDefinition> createNestedBuilderConstructorMethods(Service service, TypeStore typeStore) {
TypeNode builderType = typeStore.get(BUILDER_CLASS_NAME);
MethodDefinition noArgCtor = MethodDefinition.constructorBuilder().setScope(ScopeNode.PROTECTED).setReturnType(builderType).setThrowsExceptions(Arrays.asList(FIXED_TYPESTORE.get("IOException"))).setBody(Arrays.asList(ExprStatement.withExpr(ReferenceConstructorExpr.thisBuilder().setType(builderType).setArguments(CastExpr.builder().setType(FIXED_TYPESTORE.get("ClientContext")).setExpr(ValueExpr.createNullExpr()).build()).build()))).build();
BiFunction<VariableExpr, Expr, MethodDefinition> ctorMakerFn = (ctorArg, superArg) -> MethodDefinition.constructorBuilder().setScope(ScopeNode.PROTECTED).setReturnType(builderType).setArguments(Arrays.asList(ctorArg.toBuilder().setIsDecl(true).build())).setBody(Arrays.asList(ExprStatement.withExpr(ReferenceConstructorExpr.superBuilder().setType(FIXED_TYPESTORE.get("ClientSettings")).setArguments(superArg).build()))).build();
VariableExpr clientContextVarExpr = VariableExpr.withVariable(Variable.builder().setName("clientContext").setType(FIXED_TYPESTORE.get("ClientContext")).build());
MethodDefinition clientContextCtor = ctorMakerFn.apply(clientContextVarExpr, MethodInvocationExpr.builder().setStaticReferenceType(typeStore.get(ClassNames.getServiceStubSettingsClassName(service))).setMethodName("newBuilder").setArguments(Arrays.asList(clientContextVarExpr)).build());
VariableExpr settingsVarExpr = VariableExpr.withVariable(Variable.builder().setName("settings").setType(typeStore.get(ClassNames.getServiceSettingsClassName(service))).build());
MethodInvocationExpr settingsBuilderMethodExpr = MethodInvocationExpr.builder().setExprReferenceExpr(settingsVarExpr).setMethodName("getStubSettings").build();
settingsBuilderMethodExpr = MethodInvocationExpr.builder().setExprReferenceExpr(settingsBuilderMethodExpr).setMethodName("toBuilder").build();
MethodDefinition settingsCtor = ctorMakerFn.apply(settingsVarExpr, settingsBuilderMethodExpr);
TypeNode stubSettingsBuilderType = getStubSettingsBuilderType(service);
VariableExpr stubSettingsVarExpr = VariableExpr.withVariable(Variable.builder().setName("stubSettings").setType(stubSettingsBuilderType).build());
MethodDefinition stubSettingsCtor = ctorMakerFn.apply(stubSettingsVarExpr, stubSettingsVarExpr);
return Arrays.asList(noArgCtor, clientContextCtor, settingsCtor, stubSettingsCtor);
}
use of com.google.api.generator.engine.ast.VariableExpr 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.VariableExpr 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.VariableExpr in project gapic-generator-java by googleapis.
the class AbstractServiceClientClassComposer method createBackgroundResourceMethods.
private static List<MethodDefinition> createBackgroundResourceMethods(Service service, TypeStore typeStore) {
List<MethodDefinition> methods = new ArrayList<>();
VariableExpr stubVarExpr = VariableExpr.withVariable(Variable.builder().setType(typeStore.get(ClassNames.getServiceStubClassName(service))).setName("stub").build());
MethodDefinition closeMethod = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC).setIsFinal(true).setReturnType(TypeNode.VOID).setName("close").setBody(Arrays.asList(ExprStatement.withExpr(MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("close").build()))).build();
methods.add(closeMethod);
MethodDefinition shutdownMethod = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC).setReturnType(TypeNode.VOID).setName("shutdown").setBody(Arrays.asList(ExprStatement.withExpr(MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("shutdown").build()))).build();
methods.add(shutdownMethod);
MethodDefinition isShutdownMethod = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC).setReturnType(TypeNode.BOOLEAN).setName("isShutdown").setReturnExpr(MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("isShutdown").setReturnType(TypeNode.BOOLEAN).build()).build();
methods.add(isShutdownMethod);
MethodDefinition isTerminatedMethod = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC).setReturnType(TypeNode.BOOLEAN).setName("isTerminated").setReturnExpr(MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("isTerminated").setReturnType(TypeNode.BOOLEAN).build()).build();
methods.add(isTerminatedMethod);
MethodDefinition shutdownNowMethod = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC).setReturnType(TypeNode.VOID).setName("shutdownNow").setBody(Arrays.asList(ExprStatement.withExpr(MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("shutdownNow").build()))).build();
methods.add(shutdownNowMethod);
List<VariableExpr> arguments = Arrays.asList(VariableExpr.builder().setVariable(Variable.builder().setName("duration").setType(TypeNode.LONG).build()).build(), VariableExpr.builder().setVariable(Variable.builder().setName("unit").setType(typeStore.get("TimeUnit")).build()).build());
MethodDefinition awaitTerminationMethod = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC).setReturnType(TypeNode.BOOLEAN).setName("awaitTermination").setArguments(arguments.stream().map(v -> v.toBuilder().setIsDecl(true).build()).collect(Collectors.toList())).setThrowsExceptions(Arrays.asList(typeStore.get("InterruptedException"))).setReturnExpr(MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("awaitTermination").setArguments(arguments.stream().map(v -> (Expr) v).collect(Collectors.toList())).setReturnType(TypeNode.BOOLEAN).build()).build();
methods.add(awaitTerminationMethod);
return methods;
}
Aggregations