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);
}
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();
}
Aggregations