Search in sources :

Example 1 with CollectionLanguageOverridesProto

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

the class SingleResourceNameConfig method createSingleResourceName.

/**
 * Creates an instance of SingleResourceNameConfig based on CollectionConfigProto. On errors, null
 * will be returned, and diagnostics are reported to the diag collector.
 */
@Nullable
public static SingleResourceNameConfig createSingleResourceName(DiagCollector diagCollector, ConfigProto configProto, CollectionConfigProto collectionConfigProto, ProtoFile file) {
    String namePattern = collectionConfigProto.getNamePattern();
    PathTemplate nameTemplate;
    try {
        nameTemplate = PathTemplate.create(namePattern);
    } catch (ValidationException e) {
        diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, e.getMessage()));
        return null;
    }
    String entityId = collectionConfigProto.getEntityName();
    String entityName = entityId;
    String language = configProto.getLanguage();
    if (language != null) {
        for (CollectionLanguageOverridesProto override : collectionConfigProto.getLanguageOverridesList()) {
            if (language.equals(override.getLanguage())) {
                entityName = override.getEntityName();
            }
        }
    }
    return new AutoValue_SingleResourceNameConfig(namePattern, nameTemplate, entityId, entityName, file);
}
Also used : ValidationException(com.google.api.pathtemplate.ValidationException) CollectionLanguageOverridesProto(com.google.api.codegen.CollectionLanguageOverridesProto) PathTemplate(com.google.api.pathtemplate.PathTemplate) Nullable(javax.annotation.Nullable)

Aggregations

CollectionLanguageOverridesProto (com.google.api.codegen.CollectionLanguageOverridesProto)1 PathTemplate (com.google.api.pathtemplate.PathTemplate)1 ValidationException (com.google.api.pathtemplate.ValidationException)1 Nullable (javax.annotation.Nullable)1