Search in sources :

Example 21 with ImportTypeTable

use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.

the class CSharpSurfaceNamer method getAndSavePagedResponseTypeName.

@Override
public String getAndSavePagedResponseTypeName(MethodContext methodContext, FieldConfig resourceFieldConfig) {
    ImportTypeTable typeTable = methodContext.getTypeTable();
    String inputTypeName = methodContext.getMethodModel().getAndSaveRequestTypeName(methodContext.getTypeTable(), methodContext.getNamer());
    String outputTypeName = methodContext.getMethodModel().getAndSaveResponseTypeName(methodContext.getTypeTable(), methodContext.getNamer());
    String resourceTypeName = getResourceTypeName(typeTable, resourceFieldConfig);
    return typeTable.getAndSaveNicknameForContainer("Google.Api.Gax.PagedEnumerable", inputTypeName, outputTypeName, resourceTypeName);
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

Example 22 with ImportTypeTable

use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.

the class GoGapicSurfaceTransformer method addXExampleImports.

@VisibleForTesting
void addXExampleImports(InterfaceContext context, Iterable<? extends MethodModel> methods) {
    ImportTypeTable typeTable = context.getImportTypeTable();
    typeTable.saveNicknameFor("context;;;");
    typeTable.saveNicknameFor(context.getProductConfig().getPackageName() + ";" + context.getNamer().getLocalPackageName() + ";;");
    for (MethodModel method : methods) {
        method.getAndSaveRequestTypeName(context.getImportTypeTable(), context.getNamer());
    }
    addContextImports(context, ImportContext.EXAMPLE, methods);
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 23 with ImportTypeTable

use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.

the class CSharpSampleImportTransformer method addSampleBodyImports.

@Override
protected void addSampleBodyImports(MethodContext context, CallingForm form) {
    ImportTypeTable typeTable = context.getTypeTable();
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    if (namer.usesAsyncAwaitPattern(form)) {
        typeTable.saveNicknameFor("System.Threading.Tasks.Task");
    }
    switch(form) {
        case RequestPaged:
        case FlattenedPaged:
        case RequestPagedAll:
        case FlattenedPagedAll:
            typeTable.saveNicknameFor("Google.Api.Gax.PagedEnumerable");
            break;
        case RequestAsyncPaged:
        case FlattenedAsyncPaged:
        case RequestAsyncPagedAll:
        case FlattenedAsyncPagedAll:
            typeTable.saveNicknameFor("Google.Api.Gax.PagedAsyncEnumerable");
            break;
        case RequestPagedPageSize:
        case FlattenedPagedPageSize:
            typeTable.saveNicknameFor("Google.Api.Gax.Page");
            break;
    }
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 24 with ImportTypeTable

use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.

the class CSharpSampleImportTransformer method addOutputImports.

@Override
protected void addOutputImports(MethodContext context, OutputContext outputContext) {
    ImportTypeTable typeTable = context.getTypeTable();
    OutputTransformer.ScopeTable scopeTable = outputContext.scopeTable();
    for (TypeModel type : scopeTable.allTypes()) {
        if (type == null) {
            saveResourceTypeName(context);
        } else {
            typeTable.getAndSaveNicknameFor(type);
        }
    }
    if (outputContext.hasMaps()) {
        typeTable.getAndSaveNicknameFor("System.Collections.Generic.KeyValuePair");
    }
    if (outputContext.hasBytesFileOutput()) {
        typeTable.getAndSaveNicknameFor("System.Linq.Enumerable");
        typeTable.getAndSaveNicknameFor("System.IO.File");
    }
    if (outputContext.hasStringFileOutput()) {
        typeTable.getAndSaveNicknameFor("System.IO.File");
    }
    if (outputContext.hasPrints()) {
        typeTable.getAndSaveNicknameFor("System.Console");
    }
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) TypeModel(com.google.api.codegen.config.TypeModel) OutputTransformer(com.google.api.codegen.transformer.OutputTransformer)

Example 25 with ImportTypeTable

use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.

the class JavaApiMethodTransformer method generateGrpcStreamingMethods.

private List<StaticLangApiMethodView> generateGrpcStreamingMethods(MethodContext methodContext, @Nullable SampleContext sampleContext) {
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    InterfaceContext interfaceContext = methodContext.getSurfaceInterfaceContext();
    List<CallingForm> callingForms;
    ImportTypeTable typeTable = interfaceContext.getImportTypeTable();
    MethodConfig methodConfig = methodContext.getMethodConfig();
    switch(methodConfig.getGrpcStreamingType()) {
        case BidiStreaming:
            typeTable.saveNicknameFor("com.google.api.gax.rpc.BidiStreamingCallable");
            callingForms = Collections.singletonList(CallingForm.CallableStreamingBidi);
            break;
        case ClientStreaming:
            typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientStreamingCallable");
            callingForms = Collections.singletonList(CallingForm.CallableStreamingClient);
            break;
        case ServerStreaming:
            typeTable.saveNicknameFor("com.google.api.gax.rpc.ServerStreamingCallable");
            callingForms = Collections.singletonList(CallingForm.CallableStreamingServer);
            break;
        default:
            throw new IllegalArgumentException("Invalid streaming type: " + methodConfig.getGrpcStreamingType());
    }
    apiMethods.add(generateCallableMethod(methodContext.withCallingForms(callingForms), sampleContext));
    return apiMethods;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) CallingForm(com.google.api.codegen.viewmodel.CallingForm) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) ArrayList(java.util.ArrayList) InterfaceContext(com.google.api.codegen.config.InterfaceContext)

Aggregations

ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)33 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)8 MethodModel (com.google.api.codegen.config.MethodModel)5 ArrayList (java.util.ArrayList)5 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)3 InterfaceContext (com.google.api.codegen.config.InterfaceContext)3 InterfaceModel (com.google.api.codegen.config.InterfaceModel)3 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)3 ViewModel (com.google.api.codegen.viewmodel.ViewModel)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 MethodConfig (com.google.api.codegen.config.MethodConfig)2 TypeModel (com.google.api.codegen.config.TypeModel)2 OutputTransformer (com.google.api.codegen.transformer.OutputTransformer)2 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)1 InitCodeNode (com.google.api.codegen.metacode.InitCodeNode)1 InterfaceContext (com.google.api.codegen.transformer.InterfaceContext)1 MethodContext (com.google.api.codegen.transformer.MethodContext)1 TypeName (com.google.api.codegen.util.TypeName)1 CallingForm (com.google.api.codegen.viewmodel.CallingForm)1 PackageInfoView (com.google.api.codegen.viewmodel.PackageInfoView)1