Search in sources :

Example 1 with ResourceNameType

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

the class JavaSurfaceNamer method getResourceTypeNameObject.

@Override
protected Name getResourceTypeNameObject(ResourceNameConfig resourceNameConfig) {
    Name entityName = resourceNameConfig.getEntityName();
    ResourceNameType resourceNameType = resourceNameConfig.getResourceNameType();
    switch(resourceNameType) {
        case ANY:
            return getAnyResourceTypeName();
        case FIXED:
            return entityName.join("name_fixed");
        case ONEOF:
            // Remove suffix "_oneof". This allows the collection oneof config to "share" an entity name
            // with a collection config.
            entityName = Name.from(StringUtil.removeSuffix(entityName.toLowerUnderscore(), "_oneof"));
            return entityName.join("name");
        case SINGLE:
            return entityName.join("name");
        case NONE:
        default:
            throw new UnsupportedOperationException("unexpected entity name type");
    }
}
Also used : ResourceNameType(com.google.api.codegen.config.ResourceNameType) Name(com.google.api.codegen.util.Name)

Example 2 with ResourceNameType

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

the class SurfaceNamer method getResourceTypeNameObject.

protected Name getResourceTypeNameObject(ResourceNameConfig resourceNameConfig) {
    Name entityName = resourceNameConfig.getEntityName();
    ResourceNameType resourceNameType = resourceNameConfig.getResourceNameType();
    switch(resourceNameType) {
        case ANY:
            return getAnyResourceTypeName();
        case FIXED:
            return entityName.join("name_fixed");
        case ONEOF:
            // Remove suffix "_oneof". This allows the collection oneof config to "share" an entity name
            // with a collection config.
            entityName = Name.from(StringUtil.removeSuffix(entityName.toLowerUnderscore(), "_oneof"));
            return entityName.join("name_oneof");
        case SINGLE:
            return entityName.join("name");
        case NONE:
        default:
            throw new UnsupportedOperationException("unexpected entity name type");
    }
}
Also used : ResourceNameType(com.google.api.codegen.config.ResourceNameType) Name(com.google.api.codegen.util.Name)

Example 3 with ResourceNameType

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

the class JavaModelTypeNameConverter method getResourceNamePackage.

private static String getResourceNamePackage(FieldConfig fieldConfig) {
    String commonResourceName = fieldConfig.getResourceNameConfig().getCommonResourceName();
    if (commonResourceName != null) {
        // Common resource name is fully-qualified.
        int p = commonResourceName.lastIndexOf(".");
        if (p >= 0) {
            commonResourceName = commonResourceName.substring(0, p);
        }
        return commonResourceName;
    }
    ResourceNameType resourceNameType = fieldConfig.getResourceNameConfig().getResourceNameType();
    switch(resourceNameType) {
        case ANY:
            return "com.google.api.resourcenames";
        case FIXED:
        case SINGLE:
        case ONEOF:
            ProtoFile assignedProtoFile = fieldConfig.getResourceNameConfig().getAssignedProtoFile();
            if (assignedProtoFile == null) {
                FieldModel fm = fieldConfig.getField();
                assignedProtoFile = ((ProtoField) fm).getProtoField().getFile();
            }
            return getJavaPackage(assignedProtoFile);
        case NONE:
        default:
            throw new IllegalArgumentException("Unexpected ResourceNameType: " + resourceNameType);
    }
}
Also used : ProtoField(com.google.api.codegen.config.ProtoField) ProtoFile(com.google.api.tools.framework.model.ProtoFile) ResourceNameType(com.google.api.codegen.config.ResourceNameType) FieldModel(com.google.api.codegen.config.FieldModel)

Aggregations

ResourceNameType (com.google.api.codegen.config.ResourceNameType)3 Name (com.google.api.codegen.util.Name)2 FieldModel (com.google.api.codegen.config.FieldModel)1 ProtoField (com.google.api.codegen.config.ProtoField)1 ProtoFile (com.google.api.tools.framework.model.ProtoFile)1