Search in sources :

Example 1 with ResourceDescriptorConfig

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

the class ProtoParser method collectResourceDescriptor.

private void collectResourceDescriptor(DiagCollector diagCollector, Map<String, ResourceDescriptor> definitions, ImmutableMap.Builder<String, ResourceDescriptorConfig> configs, ResourceDescriptor definition, ProtoFile protoFile, boolean isDefinedAtMessageLevel) {
    if (definitions.put(definition.getType(), definition) != null) {
        diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Multiple ResourceDescriptor defintions with the type" + " %s are defined in proto file %s. Values for type must be unique.", definition.getType(), protoFile.getFullName()));
        return;
    }
    ResourceDescriptorConfig config = ResourceDescriptorConfig.from(definition, protoFile, isDefinedAtMessageLevel);
    configs.put(config.getUnifiedResourceType(), config);
}
Also used : ResourceDescriptorConfig(com.google.api.codegen.config.ResourceDescriptorConfig)

Example 2 with ResourceDescriptorConfig

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

the class ProtoParser method getResourceDescriptorConfigMap.

/**
 * Return a Map of Unified Resource Types to a ResourceDescriptorConfig object.
 */
public Map<String, ResourceDescriptorConfig> getResourceDescriptorConfigMap(List<ProtoFile> protoFiles, DiagCollector diagCollector) {
    ImmutableMap.Builder<String, ResourceDescriptorConfig> mapBuilder = ImmutableMap.builder();
    // Maps base names to ResourceDescriptors. Used to check redeclarations.
    Map<String, ResourceDescriptor> localDefs = new LinkedHashMap<>();
    // Skip unnecessary file parsing.
    if (!enableProtoAnnotations)
        return mapBuilder.build();
    for (ProtoFile protoFile : protoFiles) {
        List<ResourceDescriptor> resourceDescriptors = new ArrayList<>();
        // Get Resource[Set] definitions from file-level annotations.
        for (ResourceDescriptor definition : getFileLevelResourceDescriptors(protoFile)) {
            collectResourceDescriptor(diagCollector, localDefs, mapBuilder, definition, protoFile, false);
        }
        // Get Resource[Set] definitions from fields in message types.
        for (MessageType message : protoFile.getMessages()) {
            ResourceDescriptor definition = getResourceDescriptor(message);
            if (definition != null) {
                collectResourceDescriptor(diagCollector, localDefs, mapBuilder, definition, protoFile, true);
            }
        }
    }
    return mapBuilder.build();
}
Also used : ProtoFile(com.google.api.tools.framework.model.ProtoFile) ArrayList(java.util.ArrayList) ResourceDescriptorConfig(com.google.api.codegen.config.ResourceDescriptorConfig) ImmutableMap(com.google.common.collect.ImmutableMap) MessageType(com.google.api.tools.framework.model.MessageType) ResourceDescriptor(com.google.api.ResourceDescriptor) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ResourceDescriptorConfig (com.google.api.codegen.config.ResourceDescriptorConfig)2 ResourceDescriptor (com.google.api.ResourceDescriptor)1 MessageType (com.google.api.tools.framework.model.MessageType)1 ProtoFile (com.google.api.tools.framework.model.ProtoFile)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1