use of com.oracle.svm.hosted.json.JSONParser in project graal by oracle.
the class FieldDescriptor method loadFile.
private void loadFile(Reader reader) throws IOException {
Set<Class<?>> annotatedClasses = new HashSet<>(imageClassLoader.findAnnotatedClasses(TargetClass.class));
JSONParser parser = new JSONParser(reader);
@SuppressWarnings("unchecked") List<Object> allDescriptors = (List<Object>) parser.parse();
for (Object classDescriptorData : allDescriptors) {
if (classDescriptorData == null) {
/* Empty or trailing array elements are parsed to null. */
continue;
}
ClassDescriptor classDescriptor = new ClassDescriptor(classDescriptorData);
Class<?> annotatedClass = imageClassLoader.findClassByName(classDescriptor.annotatedClass());
if (annotatedClasses.contains(annotatedClass)) {
throw UserError.abort("target class already registered using explicit @TargetClass annotation: " + annotatedClass);
} else if (classDescriptors.containsKey(annotatedClass)) {
throw UserError.abort("target class already registered using substitution file: " + annotatedClass);
}
classDescriptors.put(annotatedClass, classDescriptor);
for (Object methodDescriptorData : classDescriptor.methods()) {
if (methodDescriptorData == null) {
/* Empty or trailing array elements are parsed to null. */
continue;
}
MethodDescriptor methodDescriptor = new MethodDescriptor(methodDescriptorData);
Executable annotatedMethod;
if (methodDescriptor.parameterTypes() != null) {
annotatedMethod = findMethod(annotatedClass, methodDescriptor.annotatedName(), methodDescriptor.parameterTypes());
} else {
annotatedMethod = findMethod(annotatedClass, methodDescriptor.annotatedName(), true);
}
methodDescriptors.put(annotatedMethod, methodDescriptor);
}
for (Object fieldDescriptorData : classDescriptor.fields()) {
FieldDescriptor fieldDescriptor = new FieldDescriptor(fieldDescriptorData);
Field annotatedField = findField(annotatedClass, fieldDescriptor.annotatedName());
fieldDescriptors.put(annotatedField, fieldDescriptor);
}
}
}
use of com.oracle.svm.hosted.json.JSONParser in project graal by oracle.
the class ReflectionConfigurationParser method parseAndRegister.
private void parseAndRegister(Reader reader, String featureName, Object location, HostedOptionKey<String> option) {
try {
JSONParser parser = new JSONParser(reader);
Object json = parser.parse();
parseClassArray(asList(json, "first level of document must be an array of class descriptors"));
} catch (IOException | JSONParserException e) {
String errorMessage = e.getMessage();
if (errorMessage == null || errorMessage.isEmpty()) {
errorMessage = e.toString();
}
throw UserError.abort("Error parsing " + featureName + " configuration in " + location + ":\n" + errorMessage + "\nVerify that the configuration matches the schema described in the " + SubstrateOptionsParser.commandArgument(PrintFlags, "+") + " output for option " + option.getName() + ".");
}
}
Aggregations