Search in sources :

Example 1 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<MethodModel> methods) {
    ImportTypeTable typeTable = context.getImportTypeTable();
    typeTable.saveNicknameFor("golang.org/x/net/context;;;");
    typeTable.saveNicknameFor(context.getProductConfig().getPackageName() + ";;;");
    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 2 with ImportTypeTable

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

the class JavaSurfaceTransformer method generateApiMethods.

private List<StaticLangApiMethodView> generateApiMethods(InterfaceContext context) {
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    for (MethodModel method : context.getSupportedMethods()) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        MethodContext requestMethodContext = context.asRequestMethodContext(method);
        if (methodConfig.isPageStreaming()) {
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                    apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext));
                    if (hasAnyResourceNameParameter(flatteningGroup)) {
                        apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
                    }
                }
            }
            apiMethods.add(apiMethodTransformer.generatePagedRequestObjectMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generatePagedCallableMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generateUnpagedListCallableMethod(requestMethodContext));
        } else if (methodConfig.isGrpcStreaming()) {
            ImportTypeTable typeTable = context.getImportTypeTable();
            switch(methodConfig.getGrpcStreamingType()) {
                case BidiStreaming:
                    typeTable.saveNicknameFor("com.google.api.gax.rpc.BidiStreamingCallable");
                    break;
                case ClientStreaming:
                    typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientStreamingCallable");
                    break;
                case ServerStreaming:
                    typeTable.saveNicknameFor("com.google.api.gax.rpc.ServerStreamingCallable");
                    break;
                default:
                    throw new IllegalArgumentException("Invalid streaming type: " + methodConfig.getGrpcStreamingType());
            }
            apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
        } else if (methodConfig.isLongRunningOperation()) {
            context.getImportTypeTable().saveNicknameFor("com.google.api.gax.rpc.OperationCallable");
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                    apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(flattenedMethodContext));
                    if (hasAnyResourceNameParameter(flatteningGroup)) {
                        apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
                    }
                }
            }
            apiMethods.add(apiMethodTransformer.generateAsyncOperationRequestObjectMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generateOperationCallableMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
        } else {
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                    apiMethods.add(apiMethodTransformer.generateFlattenedMethod(flattenedMethodContext));
                    if (hasAnyResourceNameParameter(flatteningGroup)) {
                        apiMethods.add(apiMethodTransformer.generateFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
                    }
                }
            }
            apiMethods.add(apiMethodTransformer.generateRequestObjectMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
        }
    }
    return apiMethods;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) ArrayList(java.util.ArrayList) MethodContext(com.google.api.codegen.transformer.MethodContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 3 with ImportTypeTable

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

the class JavaSurfaceNamer method getAndSavePagedResponseTypeName.

@Override
public String getAndSavePagedResponseTypeName(MethodContext methodContext, FieldConfig resourceFieldConfig) {
    // TODO(michaelbausor) make sure this uses the typeTable correctly
    ImportTypeTable typeTable = methodContext.getTypeTable();
    String fullPackageWrapperName = typeTable.getImplicitPackageFullNameFor(getApiWrapperClassName(methodContext.getInterfaceConfig()));
    String pagedResponseShortName = getPagedResponseTypeInnerName(methodContext.getMethodModel(), typeTable, resourceFieldConfig.getField());
    return typeTable.getAndSaveNicknameForInnerType(fullPackageWrapperName, pagedResponseShortName);
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

Example 4 with ImportTypeTable

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

the class JavaSurfaceNamer method getResourceTypeParentParseMethod.

/**
 * The name of the create method for the resource one-of for the given field config
 */
public String getResourceTypeParentParseMethod(MethodContext context, FieldConfig fieldConfig) {
    ImportTypeTable typeTable = context.getTypeTable();
    String resourceClass = context.getFeatureConfig().useStaticCreateMethodForOneofs() ? getAndSaveResourceTypeName(typeTable, fieldConfig.getMessageFieldConfig()) : getAndSaveResourceTypeFactoryName(typeTable, fieldConfig.getMessageFieldConfig());
    return resourceClass + "." + publicMethodName(Name.from("parse"));
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

Example 5 with ImportTypeTable

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

the class JavaSurfaceTransformer method getAndSaveNicknameForRootType.

private String getAndSaveNicknameForRootType(InterfaceContext context, String nickname) {
    SurfaceNamer namer = context.getNamer();
    ImportTypeTable typeTable = context.getImportTypeTable();
    String fullyQualifiedTypeName = namer.getRootPackageName() + "." + nickname;
    return typeTable.getAndSaveNicknameFor(fullyQualifiedTypeName);
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) 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