Search in sources :

Example 31 with ImportTypeTable

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

the class JavaSurfaceTransformer method addApiImports.

private void addApiImports(InterfaceContext context) {
    ImportTypeTable typeTable = context.getImportTypeTable();
    typeTable.saveNicknameFor("com.google.api.core.BetaApi");
    typeTable.saveNicknameFor("com.google.api.gax.core.BackgroundResource");
    typeTable.saveNicknameFor("com.google.api.gax.rpc.UnaryCallable");
    typeTable.saveNicknameFor("com.google.api.pathtemplate.PathTemplate");
    typeTable.saveNicknameFor("java.io.Closeable");
    typeTable.saveNicknameFor("java.io.IOException");
    typeTable.saveNicknameFor("java.util.concurrent.TimeUnit");
    typeTable.saveNicknameFor("javax.annotation.Generated");
    if (context.getInterfaceConfig().hasLongRunningOperations()) {
        typeTable.saveNicknameFor("com.google.api.gax.longrunning.OperationFuture");
        typeTable.saveNicknameFor("com.google.longrunning.Operation");
        typeTable.saveNicknameFor("com.google.longrunning.OperationsClient");
    }
    switch(context.getProductConfig().getTransportProtocol()) {
        case HTTP:
            typeTable.saveNicknameFor("java.util.List");
            typeTable.saveNicknameFor("java.util.ArrayList");
            typeTable.saveNicknameFor("java.util.concurrent.ScheduledExecutorService");
    }
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

Example 32 with ImportTypeTable

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

the class JavaSampleImportTransformer method addInitCodeImports.

@Override
protected void addInitCodeImports(MethodContext context, ImportTypeTable initCodeTypeTable, Iterable<InitCodeNode> nodes) {
    super.addInitCodeImports(context, initCodeTypeTable, nodes);
    ImportTypeTable typeTable = context.getTypeTable();
    for (InitCodeNode node : nodes) {
        switch(node.getLineType()) {
            case ListInitLine:
                typeTable.saveNicknameFor("java.util.List");
                typeTable.saveNicknameFor("java.util.Arrays");
                break;
            case MapInitLine:
                typeTable.saveNicknameFor("java.util.Map");
                typeTable.saveNicknameFor("java.util.HashMap");
                break;
            case ReadFileInitLine:
                typeTable.saveNicknameFor("java.nio.file.Files");
                typeTable.saveNicknameFor("java.nio.file.Path");
                typeTable.saveNicknameFor("java.nio.file.Paths");
                break;
            case SimpleInitLine:
            case StructureInitLine:
                // fall through
                break;
            default:
                throw new IllegalArgumentException("Unrecognized line type: " + node.getLineType());
        }
    }
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) InitCodeNode(com.google.api.codegen.metacode.InitCodeNode)

Example 33 with ImportTypeTable

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

the class JavaSurfaceTestTransformer method transform.

@Override
public List<ViewModel> transform(ApiModelT model, GapicProductConfig productConfig) {
    SurfaceNamer namer = surfaceTransformer.createSurfaceNamer(productConfig);
    List<ViewModel> views = 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);
        views.add(createUnitTestFileView(context));
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty());
            views.add(createSmokeTestClassView(context));
        }
    }
    for (InterfaceModel apiInterface : mockServiceTransformer.getGrpcInterfacesToMock(model, productConfig)) {
        ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
        InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable);
        views.add(createMockServiceImplFileView(context));
        context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty());
        views.add(createMockServiceView(context));
    }
    return views;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceContext(com.google.api.codegen.config.InterfaceContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

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