Search in sources :

Example 6 with ImportTypeTable

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

the class JavaSurfaceTransformer method transform.

public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = surfaceTransformer.createSurfaceNamer(productConfig);
    List<ServiceDocView> serviceDocs = new ArrayList<>();
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
        InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable);
        StaticLangFileView<StaticLangApiView> apiFile = generateApiFile(context, productConfig);
        surfaceDocs.add(apiFile);
        serviceDocs.add(apiFile.classView().doc());
        StaticLangApiMethodView exampleApiMethod = getExampleApiMethod(apiFile.classView().apiMethods());
        context = context.withNewTypeTable(namer.getStubPackageName());
        StaticLangFileView<StaticLangStubSettingsView> stubSettingsFile = generateStubSettingsFile(context, productConfig, exampleApiMethod);
        context = context.withNewTypeTable(namer.getRootPackageName());
        StaticLangFileView<StaticLangSettingsView> settingsFile = generateSettingsFile(context, productConfig, exampleApiMethod, stubSettingsFile.classView());
        surfaceDocs.add(settingsFile);
        surfaceDocs.add(stubSettingsFile);
        context = context.withNewTypeTable(namer.getStubPackageName());
        StaticLangFileView<StaticLangStubInterfaceView> stubInterfaceFile = generateStubInterfaceFile(context, productConfig);
        surfaceDocs.add(stubInterfaceFile);
        context = context.withNewTypeTable(namer.getStubPackageName());
        StaticLangFileView<StaticLangRpcStubView> grpcStubFile = generateRpcStubClassFile(context, productConfig);
        surfaceDocs.add(grpcStubFile);
        surfaceDocs.add(generateCallableFactoryClassFile(context, productConfig));
    }
    PackageInfoView packageInfo = generatePackageInfo(model, productConfig, namer, serviceDocs);
    surfaceDocs.add(packageInfo);
    return surfaceDocs;
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) StaticLangStubInterfaceView(com.google.api.codegen.viewmodel.StaticLangStubInterfaceView) ArrayList(java.util.ArrayList) PackageInfoView(com.google.api.codegen.viewmodel.PackageInfoView) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceContext(com.google.api.codegen.config.InterfaceContext) ServiceDocView(com.google.api.codegen.viewmodel.ServiceDocView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) StaticLangSettingsView(com.google.api.codegen.viewmodel.StaticLangSettingsView) StaticLangStubSettingsView(com.google.api.codegen.viewmodel.StaticLangStubSettingsView) StaticLangRpcStubView(com.google.api.codegen.viewmodel.StaticLangRpcStubView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView)

Example 7 with ImportTypeTable

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

the class CSharpSurfaceNamer method getAndSaveCallerAsyncPagedResponseTypeName.

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

Example 8 with ImportTypeTable

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

the class CSharpSurfaceNamer method getAndSaveCallerPagedResponseTypeName.

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

Example 9 with ImportTypeTable

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

the class GoGapicSurfaceTransformer method addXApiImports.

@VisibleForTesting
void addXApiImports(InterfaceContext context, Collection<MethodModel> methods) {
    ImportTypeTable typeTable = context.getImportTypeTable();
    typeTable.saveNicknameFor("context;;;");
    typeTable.saveNicknameFor("math;;;");
    typeTable.saveNicknameFor("google.golang.org/grpc;;;");
    typeTable.saveNicknameFor("github.com/googleapis/gax-go/v2;gax;;");
    typeTable.saveNicknameFor("google.golang.org/api/option;;;");
    typeTable.saveNicknameFor("google.golang.org/api/transport;;;");
    typeTable.saveNicknameFor("google.golang.org/grpc/metadata;;;");
    typeTable.getImports().remove(EMPTY_PROTO_PKG);
    addContextImports(context, ImportContext.CLIENT, methods);
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 10 with ImportTypeTable

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

the class JavaSampleImportTransformer 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("java.util.Map");
    }
    if (outputContext.hasBytesFileOutput()) {
        typeTable.getAndSaveNicknameFor("java.io.FileOutputStream");
        typeTable.getAndSaveNicknameFor("java.io.OutputStream");
    }
    if (outputContext.hasStringFileOutput()) {
        typeTable.getAndSaveNicknameFor("java.io.FileWriter");
    }
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) TypeModel(com.google.api.codegen.config.TypeModel) OutputTransformer(com.google.api.codegen.transformer.OutputTransformer)

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