Search in sources :

Example 11 with ImportTypeTable

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

the class JavaSampleImportTransformer method addSampleBodyImports.

@Override
protected void addSampleBodyImports(MethodContext context, CallingForm form) {
    ImportTypeTable typeTable = context.getTypeTable();
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    switch(form) {
        case Request:
        case Flattened:
            saveResponseTypeName(context);
            break;
        case RequestPaged:
            saveResourceTypeName(context);
            break;
        case FlattenedPaged:
        case CallablePaged:
            typeTable.saveNicknameFor(API_FUTURE);
            saveResponseTypeName(context);
            saveResourceTypeName(context);
            break;
        case Callable:
            typeTable.saveNicknameFor(API_FUTURE);
            typeTable.getAndSaveNicknameFor(namer.getGenericAwareResponseTypeName(context));
            break;
        case CallableList:
            saveResponseTypeName(context);
            saveResourceTypeName(context);
            break;
        case CallableStreamingBidi:
            typeTable.saveNicknameFor(BIDI_STEAMING_CALLABLE);
            typeTable.getAndSaveNicknameFor(namer.getGenericAwareResponseTypeName(context));
            break;
        case CallableStreamingClient:
            typeTable.saveNicknameFor(API_STREAM_OBSERVER);
            typeTable.getAndSaveNicknameFor(namer.getGenericAwareResponseTypeName(context));
            break;
        case CallableStreamingServer:
            typeTable.saveNicknameFor(SERVER_STREAM);
            typeTable.getAndSaveNicknameFor(namer.getGenericAwareResponseTypeName(context));
            break;
        case LongRunningFlattenedAsync:
        case LongRunningRequestAsync:
        case LongRunningCallable:
            typeTable.saveNicknameFor(OPERATION_FUTURE);
            saveMetadataTypeNameForLongRunningMethod(context);
            saveResponseTypeNameForLongRunningMethod(context);
            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 12 with ImportTypeTable

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

the class JavaSurfaceTestTransformer method addUnitTestImports.

// ///////////////////////////////// Imports //////////////////////////////////////
private void addUnitTestImports(InterfaceContext context) {
    ImportTypeTable typeTable = context.getImportTypeTable();
    typeTable.saveNicknameFor("com.google.api.gax.core.NoCredentialsProvider");
    typeTable.saveNicknameFor("com.google.api.gax.rpc.InvalidArgumentException");
    typeTable.saveNicknameFor("com.google.common.collect.Lists");
    typeTable.saveNicknameFor("java.io.IOException");
    typeTable.saveNicknameFor("java.util.Arrays");
    typeTable.saveNicknameFor("java.util.List");
    typeTable.saveNicknameFor("org.junit.After");
    typeTable.saveNicknameFor("org.junit.AfterClass");
    typeTable.saveNicknameFor("org.junit.Assert");
    typeTable.saveNicknameFor("org.junit.BeforeClass");
    typeTable.saveNicknameFor("org.junit.Test");
    if (context.getInterfaceConfig().hasLongRunningOperations()) {
        typeTable.saveNicknameFor("com.google.protobuf.Any");
    }
    switch(context.getProductConfig().getTransportProtocol()) {
        case GRPC:
            typeTable.saveNicknameFor("com.google.api.gax.rpc.ApiClientHeaderProvider");
            typeTable.saveNicknameFor("com.google.api.gax.rpc.StatusCode");
            typeTable.saveNicknameFor("com.google.api.gax.grpc.GaxGrpcProperties");
            typeTable.saveNicknameFor("com.google.api.gax.grpc.GrpcStatusCode");
            typeTable.saveNicknameFor("com.google.api.gax.grpc.testing.LocalChannelProvider");
            typeTable.saveNicknameFor("com.google.api.gax.grpc.testing.MockGrpcService");
            typeTable.saveNicknameFor("com.google.api.gax.grpc.testing.MockServiceHelper");
            typeTable.saveNicknameFor("com.google.protobuf.AbstractMessage");
            typeTable.saveNicknameFor("io.grpc.Status");
            typeTable.saveNicknameFor("io.grpc.StatusRuntimeException");
            typeTable.saveNicknameFor("java.util.ArrayList");
            typeTable.saveNicknameFor("java.util.Objects");
            typeTable.saveNicknameFor("java.util.concurrent.ExecutionException");
            typeTable.saveNicknameFor("java.util.UUID");
            typeTable.saveNicknameFor("org.junit.Before");
            break;
        case HTTP:
            typeTable.saveNicknameFor("com.google.api.gax.httpjson.ApiMethodDescriptor");
            typeTable.saveNicknameFor("com.google.api.gax.httpjson.GaxHttpJsonProperties");
            typeTable.saveNicknameFor("com.google.api.gax.httpjson.testing.MockHttpService");
            typeTable.saveNicknameFor("com.google.api.gax.rpc.ApiClientHeaderProvider");
            typeTable.saveNicknameFor("com.google.api.gax.rpc.ApiException");
            typeTable.saveNicknameFor("com.google.api.gax.rpc.ApiExceptionFactory");
            typeTable.saveNicknameFor("com.google.api.gax.rpc.StatusCode.Code");
            typeTable.saveNicknameFor("com.google.api.gax.rpc.testing.FakeStatusCode");
            typeTable.saveNicknameFor("com.google.common.collect.ImmutableList");
            typeTable.saveNicknameFor("java.util.Map");
            typeTable.saveNicknameFor("java.util.HashMap");
            // Import stub settings class in unit test file.
            SurfaceNamer stubNamer = context.getNamer().cloneWithPackageName(context.getNamer().getStubPackageName());
            TypeName rpcStubClassName = stubNamer.getTypeNameConverter().getTypeNameInImplicitPackage(stubNamer.getApiStubSettingsClassName(context.getInterfaceConfig()));
            rpcStubClassName.getAndSaveNicknameIn(typeTable.getTypeTable());
            break;
    }
}
Also used : TypeName(com.google.api.codegen.util.TypeName) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 13 with ImportTypeTable

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

the class JavaSurfaceTestTransformer method addSmokeTestImports.

/**
 * package-private
 */
void addSmokeTestImports(InterfaceContext context) {
    ImportTypeTable typeTable = context.getImportTypeTable();
    typeTable.saveNicknameFor("java.util.logging.Level");
    typeTable.saveNicknameFor("java.util.logging.Logger");
    typeTable.saveNicknameFor("java.util.List");
    typeTable.saveNicknameFor("java.util.Arrays");
    typeTable.saveNicknameFor("com.google.common.base.Preconditions");
    typeTable.saveNicknameFor("com.google.common.collect.Lists");
    typeTable.saveNicknameFor("org.junit.Test");
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

Example 14 with ImportTypeTable

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

the class CSharpSampleImportTransformer method addInitCodeImports.

@Override
protected void addInitCodeImports(MethodContext context, ImportTypeTable initCodeTypeTable, Iterable<InitCodeNode> nodes) {
    ImportTypeTable typeTable = context.getTypeTable();
    typeTable.saveNicknameFor(context.getNamer().getFullyQualifiedApiWrapperClassName(context.getInterfaceConfig()));
    Streams.stream(nodes).map(InitCodeNode::getType).forEach(typeTable::getAndSaveNicknameFor);
    if (Streams.stream(nodes).anyMatch(n -> n.getLineType() == InitCodeLineType.ReadFileInitLine)) {
        typeTable.saveNicknameFor("System.IO.File");
    }
    if (Streams.stream(nodes).anyMatch(n -> n.getLineType() == InitCodeLineType.ListInitLine)) {
        typeTable.saveNicknameFor("System.Collections.Generic.IEnumerable");
    }
    if (Streams.stream(nodes).anyMatch(n -> n.getLineType() == InitCodeLineType.MapInitLine)) {
        typeTable.saveNicknameFor("System.Collections.Generic.IDictionary");
    }
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

Example 15 with ImportTypeTable

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

the class JavaSurfaceTestTransformer method addMockServiceImplImports.

private void addMockServiceImplImports(InterfaceContext context) {
    ImportTypeTable typeTable = context.getImportTypeTable();
    typeTable.saveNicknameFor("java.util.ArrayList");
    typeTable.saveNicknameFor("java.util.List");
    typeTable.saveNicknameFor("java.util.LinkedList");
    typeTable.saveNicknameFor("java.util.Queue");
    typeTable.saveNicknameFor("com.google.api.core.BetaApi");
    typeTable.saveNicknameFor("com.google.common.collect.Lists");
    if (context.getProductConfig().getTransportProtocol().equals(TransportProtocol.GRPC)) {
        typeTable.saveNicknameFor("com.google.protobuf.AbstractMessage");
        typeTable.saveNicknameFor("io.grpc.stub.StreamObserver");
    }
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

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