public void parse(File file, String content, Diagnostic chain) throws JsonParseException, IOException {
JElement root = parse(file, content);
if(!(root instanceof JObject))
throw new JsonParseException("Excpected Json Object", JsonLocation.NA);
ModuleName fullName = null;
boolean nameSeen = false;
boolean versionSeen = false;
for(JEntry entry : ((JObject) root).getEntries()) {
try {
CallSymbol symbol = CallSymbol.valueOf(entry.getKey());
if(symbol == CallSymbol.dependency)
// Not recognized in metadata.json
throw new IllegalArgumentException();
JElement args = entry.getElement();
if(symbol == CallSymbol.name) {
fullName = createModuleName(args, false, chain);
nameSeen = true;
}
else if(symbol == CallSymbol.version) {
createVersion(args, chain);
versionSeen = true;
}
else
switch(symbol) {
case dependencies:
validateDependencies(args, symbol.name(), chain);
break;
case types:
validateTypes(args, symbol.name(), chain);
break;
case checksums:
validateChecksums(args, symbol.name(), chain);
break;
default:
validateString(args, symbol.name(), chain);
}
if(args instanceof JArray)
call(symbol, entry.getLine(), entry.getOffset(), entry.getLength(), ((JArray) args).getValues());
else
call(
symbol, entry.getLine(), entry.getOffset(), entry.getLength(),
Collections.singletonList(entry.getElement()));
}
catch(IllegalArgumentException e) {
chain.addChild(createDiagnostic(entry, ERROR, "Unrecognized call: " + entry.getKey()));
}
}
if(!nameSeen || fullName != null && (fullName.getOwner() == null || fullName.getName() == null)) {
chain.addChild(new FileDiagnostic(ERROR, PACKAGE, "A full name (user-module) must be specified", file));
}
if(!versionSeen) {
chain.addChild(new FileDiagnostic(ERROR, PACKAGE, "A version must be specified", file));