use of com.linkedin.avroutil1.model.CodeLocation in project avro-util by linkedin.
the class AvscParser method parseUnionSchema.
private SchemaOrRef parseUnionSchema(JsonArrayExt arrayNode, AvscFileParseContext context, boolean topLevel) {
CodeLocation codeLocation = locationOf(context.getUri(), arrayNode);
List<SchemaOrRef> unionTypes = new ArrayList<>(arrayNode.size());
for (JsonValue jsonValue : arrayNode) {
JsonValueExt unionNode = (JsonValueExt) jsonValue;
SchemaOrRef type = parseSchemaDeclOrRef(unionNode, context, false);
unionTypes.add(type);
}
AvroUnionSchema unionSchema = new AvroUnionSchema(codeLocation);
unionSchema.setTypes(unionTypes);
context.defineSchema(unionSchema, topLevel);
return new SchemaOrRef(codeLocation, unionSchema);
}
use of com.linkedin.avroutil1.model.CodeLocation in project avro-util by linkedin.
the class AvscParser method parseAliases.
private List<AvroName> parseAliases(JsonObjectExt objectNode, AvscFileParseContext context, AvroType avroType, AvroName name) {
JsonArrayExt aliasesArray = getOptionalArray(objectNode, "aliases");
if (aliasesArray == null || aliasesArray.isEmpty()) {
return null;
}
List<AvroName> aliases = new ArrayList<>(aliasesArray.size());
for (int i = 0; i < aliasesArray.size(); i++) {
// !=null
JsonValueExt aliasNode = (JsonValueExt) aliasesArray.get(i);
JsonValue.ValueType fieldNodeType = aliasNode.getValueType();
if (fieldNodeType != JsonValue.ValueType.STRING) {
throw new AvroSyntaxException("alias " + i + " for " + name.getSimpleName() + " at " + aliasNode.getStartLocation() + " expected to be a STRING, not a " + JsonPUtil.describe(fieldNodeType) + " (" + aliasNode + ")");
}
String aliasStr = ((JsonStringExt) aliasNode).getString();
AvroName alias;
if (aliasStr.contains(".")) {
int lastDot = aliasStr.lastIndexOf('.');
alias = new AvroName(aliasStr.substring(lastDot + 1), aliasStr.substring(0, lastDot));
} else {
alias = new AvroName(aliasStr, name.getNamespace());
}
if (aliases.contains(alias)) {
TextLocation fieldStartLocation = Util.convertLocation(aliasNode.getStartLocation());
TextLocation fieldEndLocation = Util.convertLocation(aliasNode.getEndLocation());
CodeLocation aliasCodeLocation = new CodeLocation(context.getUri(), fieldStartLocation, fieldEndLocation);
context.addIssue(AvscIssues.duplicateAlias(alias.getFullname(), aliasCodeLocation));
} else {
aliases.add(alias);
}
}
return aliases;
}
Aggregations