Search in sources :

Example 1 with ProtoTypeRef

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

the class RubyGapicSurfaceTransformer method generateVersionIndexView.

private ViewModel generateVersionIndexView(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    ImmutableList.Builder<VersionIndexRequireView> requireViews = ImmutableList.builder();
    Iterable<? extends InterfaceModel> interfaces = model.getInterfaces(productConfig);
    for (InterfaceModel apiInterface : interfaces) {
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        if (interfaceConfig == null) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        requireViews.add(VersionIndexRequireView.newBuilder().clientName(namer.getFullyQualifiedApiWrapperClassName(interfaceConfig)).fileName(namer.getServiceFileName(interfaceConfig)).serviceName(namer.getPackageServiceName(context.getInterfaceConfig())).doc(serviceTransformer.generateServiceDoc(context, generateApiMethods(context).get(0), productConfig)).build());
    }
    // append any additional types
    Set<String> requireTypes = new HashSet<>();
    for (TypeModel type : model.getAdditionalTypes()) {
        if (type instanceof ProtoTypeRef) {
            ProtoTypeRef t = (ProtoTypeRef) type;
            String name = namer.getProtoFileImportName(t.getProtoType().getMessageType().getFile().getSimpleName());
            requireTypes.add(name);
        }
    }
    return VersionIndexView.newBuilder().apiVersion(packageConfig.apiVersion()).requireViews(requireViews.build()).requireTypes(ImmutableList.copyOf(requireTypes)).templateFileName(VERSION_INDEX_TEMPLATE_FILE).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).outputPath("lib" + File.separator + versionPackagePath(namer) + ".rb").modules(generateModuleViews(model, productConfig, true)).type(VersionIndexType.VersionIndex).build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ProtoTypeRef(com.google.api.codegen.config.ProtoTypeRef) TypeModel(com.google.api.codegen.config.TypeModel) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) InterfaceModel(com.google.api.codegen.config.InterfaceModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) HashSet(java.util.HashSet)

Example 2 with ProtoTypeRef

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

the class NodeJSSurfaceNamer method returnTypeDoc.

private String returnTypeDoc(ImportTypeTable typeTable, GapicMethodConfig methodConfig) {
    String returnTypeDoc = "";
    if (methodConfig.isPageStreaming()) {
        returnTypeDoc = "Array of ";
        FieldModel resourcesType = methodConfig.getPageStreaming().getResourcesField();
        if (resourcesType.isMessage()) {
            returnTypeDoc += commentReformatter.getLinkedElementName(((ProtoTypeRef) resourcesType.getType()).getProtoType().getMessageType());
        } else if (resourcesType.isEnum()) {
            returnTypeDoc += commentReformatter.getLinkedElementName(((ProtoTypeRef) resourcesType.getType()).getProtoType().getEnumType());
        } else {
            // Converting to lowercase because "String" is capitalized in NodeJSModelTypeNameConverter.
            returnTypeDoc += getParamTypeNoCardinality(typeTable, resourcesType.getType()).toLowerCase();
        }
    } else if (methodConfig.isLongRunningOperation()) {
        returnTypeDoc = "a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object";
    } else {
        returnTypeDoc = getTypeNameDoc(typeTable, new ProtoTypeRef(methodConfig.getMethod().getOutputType()));
    }
    return returnTypeDoc;
}
Also used : ProtoTypeRef(com.google.api.codegen.config.ProtoTypeRef) FieldModel(com.google.api.codegen.config.FieldModel)

Example 3 with ProtoTypeRef

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

the class PythonSurfaceNamer method getFormattedPrintArgName.

@Override
public /**
 * If the argument is a protobuf enum, returns an expression that translates the enum to a
 * descriptive string, such as `enums.message_type.enum_type(var.foo.bar).name()`. Otherwise,
 * returns the argument as it is.
 */
String getFormattedPrintArgName(ImportTypeTable typeTable, TypeModel type, String variable, List<String> accessors) {
    String arg = variable + String.join("", accessors);
    // We print the argument as it is if it's not an enum type
    if (!(type instanceof ProtoTypeRef) || !((ProtoTypeRef) type).isEnum()) {
        return arg;
    }
    // Find all the parent elements of this enum type, stopping at the top-level message or enum
    TypeRef protoType = ((ProtoTypeRef) type).getProtoType();
    ProtoElement t = protoType.getEnumType();
    List<String> names = new ArrayList<>();
    while (!(t instanceof ProtoFile)) {
        names.add(t.getSimpleName());
        t = t.getParent();
    }
    // Wrap the enum value with the helper function that translates it to a descriptive string
    names.add("enums");
    StringBuilder builder = new StringBuilder();
    for (String name : Lists.reverse(names)) {
        builder.append(name).append(".");
    }
    builder.setLength(builder.length() - 1);
    return builder.append("(").append(arg).append(").name").toString();
}
Also used : ProtoTypeRef(com.google.api.codegen.config.ProtoTypeRef) TypeRef(com.google.api.tools.framework.model.TypeRef) ProtoTypeRef(com.google.api.codegen.config.ProtoTypeRef) ProtoElement(com.google.api.tools.framework.model.ProtoElement) ArrayList(java.util.ArrayList) ProtoFile(com.google.api.tools.framework.model.ProtoFile)

Example 4 with ProtoTypeRef

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

the class NodeJSSurfaceNamer method returnTypeDoc.

private String returnTypeDoc(ImportTypeTable typeTable, GapicMethodContext methodContext) {
    String returnTypeDoc = "";
    if (methodContext.getMethodConfig().isPageStreaming()) {
        returnTypeDoc = "Array of ";
        FieldModel resourcesType = methodContext.getMethodConfig().getPageStreaming().getResourcesField();
        if (resourcesType.isMessage()) {
            returnTypeDoc += commentReformatter.getLinkedElementName(((ProtoTypeRef) resourcesType.getType()).getProtoType().getMessageType());
        } else if (resourcesType.isEnum()) {
            returnTypeDoc += commentReformatter.getLinkedElementName(((ProtoTypeRef) resourcesType.getType()).getProtoType().getEnumType());
        } else {
            // Converting to lowercase because "String" is capitalized in NodeJSModelTypeNameConverter.
            returnTypeDoc += getParamTypeNoCardinality(typeTable, resourcesType.getType()).toLowerCase();
        }
    } else if (methodContext.isLongRunningMethodContext()) {
        returnTypeDoc = "a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/classes/Operation.html} object";
    } else {
        returnTypeDoc = getTypeNameDoc(typeTable, ProtoTypeRef.create(methodContext.getMethod().getOutputType()));
    }
    return returnTypeDoc;
}
Also used : ProtoTypeRef(com.google.api.codegen.config.ProtoTypeRef) FieldModel(com.google.api.codegen.config.FieldModel)

Aggregations

ProtoTypeRef (com.google.api.codegen.config.ProtoTypeRef)4 FieldModel (com.google.api.codegen.config.FieldModel)2 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)1 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)1 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 TypeModel (com.google.api.codegen.config.TypeModel)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1 VersionIndexRequireView (com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)1 ProtoElement (com.google.api.tools.framework.model.ProtoElement)1 ProtoFile (com.google.api.tools.framework.model.ProtoFile)1 TypeRef (com.google.api.tools.framework.model.TypeRef)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1