Search in sources :

Example 1 with Name

use of com.google.api.codegen.util.Name in project toolkit by googleapis.

the class DiscoGapicParser method getQualifiedResourceIdentifier.

/**
 * Return the name of the fully qualified resource from a given canonicalized path. Use {@link
 * #getCanonicalPath(Method)}} for canonicalization of the parameter.
 */
public static Name getQualifiedResourceIdentifier(String canonicalPath) {
    String[] pieces = canonicalPath.split(PATH_DELIMITER);
    Name name = null;
    for (String piece : pieces) {
        if (!piece.contains("{")) {
            if (name == null) {
                name = Name.from(Inflector.singularize(piece));
            } else {
                name = name.join(stringToName(Inflector.singularize(piece)));
            }
        }
    }
    return name;
}
Also used : Name(com.google.api.codegen.util.Name)

Example 2 with Name

use of com.google.api.codegen.util.Name in project toolkit by googleapis.

the class SurfaceNamer method getResourceNameFieldGetFunctionName.

/**
 * The function name to get a field that is a resource name class.
 */
public String getResourceNameFieldGetFunctionName(FieldConfig fieldConfig) {
    FieldModel type = fieldConfig.getField();
    Name identifier = fieldConfig.getField().getNameAsParameterName();
    Name resourceName = getResourceTypeNameObject(fieldConfig.getResourceNameConfig());
    if (type.isMap()) {
        return getNotImplementedString("SurfaceNamer.getResourceNameFieldGetFunctionName:map-type");
    } else if (type.isRepeated()) {
        return publicMethodName(Name.from("get").join(identifier).join("list_as").join(resourceName).join("list"));
    } else {
        return publicMethodName(Name.from("get").join(identifier).join("as").join(resourceName));
    }
}
Also used : FieldModel(com.google.api.codegen.config.FieldModel) Name(com.google.api.codegen.util.Name)

Example 3 with Name

use of com.google.api.codegen.util.Name in project toolkit by googleapis.

the class CSharpSurfaceNamer method getResourceNameFieldGetFunctionName.

@Override
public String getResourceNameFieldGetFunctionName(FieldConfig fieldConfig) {
    FieldModel type = fieldConfig.getField();
    String fieldName = fieldConfig.getField().getSimpleName();
    Name identifier = Name.from(fieldName);
    Name resourceName;
    if (type.isMap()) {
        return getNotImplementedString("SurfaceNamer.getResourceNameFieldGetFunctionName:map-type");
    }
    // Omit the identifier when the field is called name (or names for the repeated case)
    boolean requireIdentifier = !((type.isRepeated() && fieldName.toLowerCase().equals("names")) || (!type.isRepeated() && fieldName.toLowerCase().equals("name")));
    boolean requireAs = requireIdentifier || (fieldConfig.getResourceNameType() == ResourceNameType.ANY);
    boolean requirePlural = type.isRepeated();
    if (fieldConfig.getResourceNameType() == ResourceNameType.ANY) {
        resourceName = Name.from("resource_name");
    } else {
        resourceName = getResourceTypeNameObject(fieldConfig.getMessageResourceNameConfig());
    }
    Name name = Name.from();
    if (requireIdentifier) {
        name = name.join(identifier);
    }
    if (requireAs) {
        name = name.join("as");
    }
    String functionName = publicMethodName(name.join(resourceName));
    if (requirePlural) {
        functionName += "s";
    }
    return functionName;
}
Also used : FieldModel(com.google.api.codegen.config.FieldModel) TypeName(com.google.api.codegen.util.TypeName) Name(com.google.api.codegen.util.Name)

Example 4 with Name

use of com.google.api.codegen.util.Name in project toolkit by googleapis.

the class NodeJSGapicSurfaceTransformer method generateIndexViews.

private List<ViewModel> generateIndexViews(Iterable<? extends InterfaceModel> apiInterfaces, GapicProductConfig productConfig) {
    NodeJSPackageMetadataNamer packageMetadataNamer = new NodeJSPackageMetadataNamer(productConfig.getPackageName(), productConfig.getDomainLayerLocation());
    ArrayList<ViewModel> indexViews = new ArrayList<>();
    NodeJSSurfaceNamer namer = new NodeJSSurfaceNamer(productConfig.getPackageName(), NodeJSUtils.isGcloud(productConfig));
    String version = namer.getApiWrapperModuleVersion();
    boolean hasVersion = version != null && !version.isEmpty();
    ArrayList<VersionIndexRequireView> requireViews = new ArrayList<>();
    for (InterfaceModel apiInterface : apiInterfaces) {
        Name serviceName = namer.getReducedServiceName(apiInterface.getSimpleName());
        String localName = hasVersion ? serviceName.join(version).toLowerCamel() : serviceName.toLowerCamel();
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        ApiMethodView exampleMethod = generateApiMethods(context, apiInterface.getApiModel().hasMultipleServices()).get(0);
        VersionIndexRequireView require = VersionIndexRequireView.newBuilder().clientName(namer.getApiWrapperClassName(productConfig.getInterfaceConfig(apiInterface))).serviceName(namer.getPackageServiceName(context.getInterfaceConfig())).localName(localName).doc(serviceTransformer.generateServiceDoc(context, exampleMethod, productConfig)).fileName(namer.getClientFileName(context.getInterfaceConfig())).build();
        requireViews.add(require);
    }
    String indexOutputPath = hasVersion ? "src/" + version + "/index.js" : "src/index.js";
    VersionIndexView.Builder indexViewbuilder = VersionIndexView.newBuilder().templateFileName(INDEX_TEMPLATE_FILE).outputPath(indexOutputPath).requireViews(requireViews).primaryService(requireViews.get(0)).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.NODEJS).lower()).toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).packageName(packageMetadataNamer.getMetadataIdentifier());
    if (hasVersion) {
        indexViewbuilder.apiVersion(version);
    }
    indexViews.add(indexViewbuilder.build());
    if (hasVersion) {
        String versionIndexOutputPath = "src/index.js";
        VersionIndexView.Builder versionIndexViewBuilder = VersionIndexView.newBuilder().templateFileName(VERSION_INDEX_TEMPLATE_FILE).outputPath(versionIndexOutputPath).requireViews(requireViews).primaryService(requireViews.get(0)).apiVersion(version).stubs(versionIndexStubs(apiInterfaces, productConfig)).isGcloud(NodeJSUtils.isGcloud(productConfig)).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.NODEJS).lower()).toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).packageName(packageMetadataNamer.getMetadataIdentifier()).namespace(packageMetadataNamer.getServiceName());
        indexViews.add(versionIndexViewBuilder.build());
    }
    return indexViews;
}
Also used : ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) ArrayList(java.util.ArrayList) VersionIndexView(com.google.api.codegen.viewmodel.metadata.VersionIndexView) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView) Name(com.google.api.codegen.util.Name) InterfaceModel(com.google.api.codegen.config.InterfaceModel)

Example 5 with Name

use of com.google.api.codegen.util.Name in project toolkit by googleapis.

the class PhpApiMethodParamTransformer method getCallSettingsParamDocList.

private List<ParamDocView> getCallSettingsParamDocList(GapicMethodContext context) {
    ImmutableList.Builder<ParamDocView> arrayKeyDocs = ImmutableList.builder();
    Name retrySettingsName = Name.from("retry", "settings");
    Name timeoutMillisName = Name.from("timeout", "millis");
    if (context.getNamer().methodHasRetrySettings(context.getMethodConfig())) {
        SimpleParamDocView.Builder retrySettingsDoc = SimpleParamDocView.newBuilder();
        retrySettingsDoc.paramName(context.getNamer().localVarName(retrySettingsName));
        String retryDocType = Joiner.on("|").join("RetrySettings", "array");
        retrySettingsDoc.typeName(retryDocType);
        // TODO figure out a reliable way to line-wrap comments across all languages
        // instead of encoding it in the transformer
        StringBuilder retrySettingsDocTextBuilder = new StringBuilder("Retry settings to use for this call. Can be a\n" + "{@see Google\\ApiCore\\RetrySettings} object, or an associative array\n" + "of retry settings parameters. See the documentation on\n" + "{@see Google\\ApiCore\\RetrySettings} for example usage.");
        if (context.getNamer().methodHasTimeoutSettings(context.getMethodConfig())) {
            retrySettingsDocTextBuilder.append(String.format("\nIf specified, then %s is ignored.", context.getNamer().localVarReference(timeoutMillisName)));
        }
        List<String> retrySettingsDocLines = context.getNamer().getDocLines(retrySettingsDocTextBuilder.toString());
        retrySettingsDoc.lines(retrySettingsDocLines);
        arrayKeyDocs.add(retrySettingsDoc.build());
    }
    if (context.getNamer().methodHasTimeoutSettings(context.getMethodConfig())) {
        SimpleParamDocView.Builder timeoutDoc = SimpleParamDocView.newBuilder();
        timeoutDoc.typeName(context.getTypeTable().getAndSaveNicknameFor(TypeRef.of(Type.TYPE_INT32)));
        timeoutDoc.paramName(context.getNamer().localVarName(timeoutMillisName));
        // TODO figure out a reliable way to line-wrap comments across all languages
        // instead of encoding it in the transformer
        StringBuilder timeoutMillisDocTextBuilder = new StringBuilder("Timeout to use for this call.");
        if (context.getNamer().methodHasRetrySettings(context.getMethodConfig())) {
            timeoutMillisDocTextBuilder.append(String.format(" Only used if %s\nis not set.", context.getNamer().localVarReference(retrySettingsName)));
        }
        List<String> timeoutMillisDocLines = context.getNamer().getDocLines(timeoutMillisDocTextBuilder.toString());
        timeoutDoc.lines(timeoutMillisDocLines);
        arrayKeyDocs.add(timeoutDoc.build());
    }
    return arrayKeyDocs.build();
}
Also used : SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ImmutableList(com.google.common.collect.ImmutableList) MapParamDocView(com.google.api.codegen.viewmodel.MapParamDocView) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) Name(com.google.api.codegen.util.Name)

Aggregations

Name (com.google.api.codegen.util.Name)10 FieldModel (com.google.api.codegen.config.FieldModel)3 MapParamDocView (com.google.api.codegen.viewmodel.MapParamDocView)2 ParamDocView (com.google.api.codegen.viewmodel.ParamDocView)2 SimpleParamDocView (com.google.api.codegen.viewmodel.SimpleParamDocView)2 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 Method (com.google.api.codegen.discovery.Method)1 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)1 TypeName (com.google.api.codegen.util.TypeName)1 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)1 ViewModel (com.google.api.codegen.viewmodel.ViewModel)1 VersionIndexRequireView (com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)1 VersionIndexView (com.google.api.codegen.viewmodel.metadata.VersionIndexView)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1