Search in sources :

Example 21 with TypeModel

use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.

the class OutputTransformer method stringInterpolationView.

private OutputView.StringInterpolationView stringInterpolationView(MethodContext methodContext, SampleContext sampleContext, OutputContext outputContext, List<String> configs) {
    String format = configs.get(0);
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (String path : configs.subList(1, configs.size())) {
        OutputView.VariableView variable = accessor(new Scanner(path), methodContext, sampleContext, outputContext.scopeTable());
        TypeModel type = variable.type();
        // resource names, but should include them as well for completeness
        if (type != null) {
            outputContext.stringFormattedVariableTypes().add(type);
        }
        String formattedArg = methodContext.getNamer().getFormattedPrintArgName(methodContext.getTypeTable(), type, variable.variable(), variable.accessors());
        builder.add(formattedArg);
    }
    ImmutableList<String> args = builder.build();
    ImmutableList<String> stringWithInterpolatedArgs = methodContext.getNamer().getInterpolatedFormatAndArgs(format, args);
    return OutputView.StringInterpolationView.newBuilder().format(stringWithInterpolatedArgs.get(0)).args(stringWithInterpolatedArgs.subList(1, stringWithInterpolatedArgs.size())).build();
}
Also used : Scanner(com.google.api.codegen.util.Scanner) OutputView(com.google.api.codegen.viewmodel.OutputView) ImmutableList(com.google.common.collect.ImmutableList) TypeModel(com.google.api.codegen.config.TypeModel)

Example 22 with TypeModel

use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.

the class StaticLangApiMethodTransformer method generateOperationCallableMethod.

public StaticLangApiMethodView generateOperationCallableMethod(MethodContext context, SampleContext sampleContext) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
    setCommonFields(context, methodViewBuilder);
    methodViewBuilder.name(namer.getOperationCallableMethodName(method));
    methodViewBuilder.exampleName(context.getNamer().getOperationCallableMethodExampleName(method));
    setCallableMethodFields(context, namer.getOperationCallableName(method), methodViewBuilder, context.getCallingForms(), sampleContext);
    TypeModel returnType = context.getLongRunningConfig().getReturnType();
    methodViewBuilder.responseTypeName(context.getTypeTable().getAndSaveNicknameFor(returnType));
    methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context));
    return methodViewBuilder.type(ClientMethodType.OperationCallableMethod).build();
}
Also used : Builder(com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) TypeModel(com.google.api.codegen.config.TypeModel)

Example 23 with TypeModel

use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.

the class StaticLangApiMethodTransformer method generateAsyncOperationFlattenedMethod.

// Used by CSharp (and indirectly by Java via the overload above)
public StaticLangApiMethodView generateAsyncOperationFlattenedMethod(MethodContext context, List<ParamWithSimpleDoc> additionalParams, ClientMethodType type, boolean requiresOperationMethod, SampleContext sampleContext) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
    setCommonFields(context, methodViewBuilder);
    methodViewBuilder.name(namer.getAsyncApiMethodName(context.getMethodModel(), context.getMethodConfig().getVisibility()));
    methodViewBuilder.exampleName(namer.getAsyncApiMethodExampleName(method));
    methodViewBuilder.callableName(namer.getCallableName(method));
    setFlattenedMethodFields(context, additionalParams, Synchronicity.Async, methodViewBuilder, context.getCallingForms(), sampleContext);
    if (requiresOperationMethod) {
        methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context));
    }
    TypeModel returnType = context.getLongRunningConfig().getReturnType();
    methodViewBuilder.responseTypeName(context.getTypeTable().getAndSaveNicknameFor(returnType));
    methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context));
    return methodViewBuilder.type(type).build();
}
Also used : Builder(com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) TypeModel(com.google.api.codegen.config.TypeModel)

Example 24 with TypeModel

use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.

the class StaticLangApiMethodTransformer method generateOperationFlattenedMethod.

// Used by: C#
public StaticLangApiMethodView generateOperationFlattenedMethod(MethodContext context, List<ParamWithSimpleDoc> additionalParams, SampleContext sampleContext) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
    setCommonFields(context, methodViewBuilder);
    methodViewBuilder.name(namer.getApiMethodName(method, context.getMethodConfig().getVisibility()));
    methodViewBuilder.exampleName(namer.getApiMethodExampleName(context.getInterfaceConfig(), method));
    methodViewBuilder.callableName(namer.getCallableName(method));
    setFlattenedMethodFields(context, additionalParams, Synchronicity.Sync, methodViewBuilder, context.getCallingForms(), sampleContext);
    methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context));
    TypeModel returnType = context.getLongRunningConfig().getReturnType();
    methodViewBuilder.responseTypeName(context.getTypeTable().getAndSaveNicknameFor(returnType));
    return methodViewBuilder.type(ClientMethodType.OperationFlattenedMethod).build();
}
Also used : Builder(com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) TypeModel(com.google.api.codegen.config.TypeModel)

Example 25 with TypeModel

use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.

the class StaticLangApiMethodTransformer method generateOperationRequestObjectMethod.

// Used by: C#
public StaticLangApiMethodView generateOperationRequestObjectMethod(MethodContext context, List<ParamWithSimpleDoc> additionalParams, SampleContext sampleContext) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
    setCommonFields(context, methodViewBuilder);
    methodViewBuilder.name(namer.getApiMethodName(method, context.getMethodConfig().getVisibility()));
    methodViewBuilder.exampleName(namer.getApiMethodExampleName(context.getInterfaceConfig(), method));
    setRequestObjectMethodFields(context, namer.getCallableMethodName(method), Synchronicity.Sync, additionalParams, methodViewBuilder, context.getCallingForms(), sampleContext);
    methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context));
    TypeModel returnType = context.getLongRunningConfig().getReturnType();
    methodViewBuilder.responseTypeName(context.getTypeTable().getAndSaveNicknameFor(returnType));
    return methodViewBuilder.type(ClientMethodType.OperationRequestObjectMethod).build();
}
Also used : Builder(com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) TypeModel(com.google.api.codegen.config.TypeModel)

Aggregations

TypeModel (com.google.api.codegen.config.TypeModel)32 MethodModel (com.google.api.codegen.config.MethodModel)12 Test (org.junit.Test)12 Scanner (com.google.api.codegen.util.Scanner)10 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)10 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)10 OutputView (com.google.api.codegen.viewmodel.OutputView)8 FieldModel (com.google.api.codegen.config.FieldModel)7 ImmutableList (com.google.common.collect.ImmutableList)4 LongRunningConfig (com.google.api.codegen.config.LongRunningConfig)3 ArrayList (java.util.ArrayList)3 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)2 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)2 OutputTransformer (com.google.api.codegen.transformer.OutputTransformer)2 LongRunningOperationDetailView (com.google.api.codegen.viewmodel.LongRunningOperationDetailView)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 HashSet (java.util.HashSet)2 OutputSpec (com.google.api.codegen.OutputSpec)1 SampleValueSet (com.google.api.codegen.SampleValueSet)1 FieldConfig (com.google.api.codegen.config.FieldConfig)1