Search in sources :

Example 56 with MethodModel

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

the class BatchingTransformer method generateDescriptorClasses.

public List<BatchingDescriptorClassView> generateDescriptorClasses(InterfaceContext context) {
    List<BatchingDescriptorClassView> descriptors = new ArrayList<>();
    for (MethodModel method : context.getInterfaceConfigMethods()) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        if (methodConfig == null) {
            continue;
        }
        if (!methodConfig.isBatching()) {
            continue;
        }
        descriptors.add(generateDescriptorClass(context.asRequestMethodContext(method)));
    }
    return descriptors;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) BatchingDescriptorClassView(com.google.api.codegen.viewmodel.BatchingDescriptorClassView) ArrayList(java.util.ArrayList)

Example 57 with MethodModel

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

the class DiscoGapicInterfaceContext method getInterfaceConfigMethods.

/**
 * Returns a list of methods for this interface. Memoize the result.
 */
@Override
public List<MethodModel> getInterfaceConfigMethods() {
    if (interfaceMethods != null) {
        return interfaceMethods;
    }
    ImmutableList.Builder<MethodModel> methodBuilder = ImmutableList.builder();
    for (MethodConfig methodConfig : getInterfaceConfig().getMethodConfigs()) {
        MethodModel method = methodConfig.getMethodModel();
        if (isSupported(method)) {
            methodBuilder.add(method);
        }
    }
    interfaceMethods = methodBuilder.build();
    return interfaceMethods;
}
Also used : DiscoGapicMethodConfig(com.google.api.codegen.config.DiscoGapicMethodConfig) MethodConfig(com.google.api.codegen.config.MethodConfig) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) MethodModel(com.google.api.codegen.config.MethodModel) ImmutableList(com.google.common.collect.ImmutableList)

Example 58 with MethodModel

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

the class GapicInterfaceContext method getInterfaceConfigMethods.

/**
 * Returns a list of methods for this interface that have method configs. Memoize the result.
 */
@Override
public List<MethodModel> getInterfaceConfigMethods() {
    if (interfaceMethods != null) {
        return interfaceMethods;
    }
    ImmutableList.Builder<MethodModel> methodBuilder = ImmutableList.builder();
    for (MethodConfig methodConfig : getInterfaceConfig().getMethodConfigs()) {
        methodBuilder.add(new ProtoMethodModel(((GapicMethodConfig) methodConfig).getMethod()));
    }
    interfaceMethods = methodBuilder.build();
    return interfaceMethods;
}
Also used : GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) MethodConfig(com.google.api.codegen.config.MethodConfig) ProtoMethodModel(com.google.api.codegen.config.ProtoMethodModel) MethodModel(com.google.api.codegen.config.MethodModel) ProtoMethodModel(com.google.api.codegen.config.ProtoMethodModel) GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) ImmutableList(com.google.common.collect.ImmutableList)

Example 59 with MethodModel

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

the class MockServiceTransformer method createMockGrpcMethodViews.

public List<MockGrpcMethodView> createMockGrpcMethodViews(InterfaceContext context) {
    if (!context.getProductConfig().getTransportProtocol().equals(TransportProtocol.GRPC)) {
        return ImmutableList.of();
    }
    List<MethodModel> methods = context.getInterfaceMethods();
    ArrayList<MockGrpcMethodView> mocks = new ArrayList<>(methods.size());
    for (MethodModel method : methods) {
        if (context.getMethodConfig(method) == null) {
            continue;
        }
        MethodContext methodContext = context.asRequestMethodContext(method);
        String requestTypeName = method.getAndSaveRequestTypeName(methodContext.getTypeTable(), methodContext.getNamer());
        String responseTypeName = method.getAndSaveResponseTypeName(methodContext.getTypeTable(), methodContext.getNamer());
        MethodConfig methodConfig = methodContext.getMethodConfig();
        mocks.add(MockGrpcMethodView.newBuilder().name(methodContext.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).requestTypeName(requestTypeName).responseTypeName(responseTypeName).grpcStreamingType(methodConfig.getGrpcStreamingType()).streamHandleTypeName(methodContext.getNamer().getStreamingServerName(method)).build());
    }
    return mocks;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) MockGrpcMethodView(com.google.api.codegen.viewmodel.testing.MockGrpcMethodView) ArrayList(java.util.ArrayList)

Example 60 with MethodModel

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

the class PageStreamingTransformer method generateFactoryClass.

private PagedListResponseFactoryClassView generateFactoryClass(MethodContext context) {
    SurfaceNamer namer = context.getNamer();
    MethodModel method = context.getMethodModel();
    ImportTypeTable typeTable = context.getTypeTable();
    PageStreamingConfig pageStreaming = context.getMethodConfig().getPageStreaming();
    FieldModel resourceField = pageStreaming.getResourcesField();
    FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
    PagedListResponseFactoryClassView.Builder factory = PagedListResponseFactoryClassView.newBuilder();
    factory.name(namer.getPagedListResponseFactoryConstName(method));
    factory.requestTypeName(method.getAndSaveRequestTypeName(typeTable, namer));
    factory.responseTypeName(method.getAndSaveResponseTypeName(typeTable, namer));
    factory.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceField));
    factory.pagedListResponseTypeName(namer.getAndSavePagedResponseTypeName(context, resourceFieldConfig));
    factory.pageStreamingDescriptorName(namer.getPageStreamingDescriptorConstName(method));
    return factory.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) FieldConfig(com.google.api.codegen.config.FieldConfig) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) PagedListResponseFactoryClassView(com.google.api.codegen.viewmodel.PagedListResponseFactoryClassView) FieldModel(com.google.api.codegen.config.FieldModel)

Aggregations

MethodModel (com.google.api.codegen.config.MethodModel)95 ArrayList (java.util.ArrayList)30 MethodConfig (com.google.api.codegen.config.MethodConfig)29 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)23 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)20 ImmutableList (com.google.common.collect.ImmutableList)16 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)14 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)14 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)12 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)11 FieldConfig (com.google.api.codegen.config.FieldConfig)11 ProtoMethodModel (com.google.api.codegen.config.ProtoMethodModel)9 Test (org.junit.Test)9 FieldModel (com.google.api.codegen.config.FieldModel)8 MethodContext (com.google.api.codegen.transformer.MethodContext)8 SymbolTable (com.google.api.codegen.util.SymbolTable)8 TypeModel (com.google.api.codegen.config.TypeModel)7 TestCaseView (com.google.api.codegen.viewmodel.testing.TestCaseView)7 InterfaceModel (com.google.api.codegen.config.InterfaceModel)6 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)6