use of com.oracle.svm.hosted.json.JSONParserException in project graal by oracle.
the class ReflectionConfigurationParser method parseMethod.
private void parseMethod(Map<String, Object> data, Class<?> clazz) {
String methodName = null;
Class<?>[] methodParameterTypes = null;
for (Map.Entry<String, Object> entry : data.entrySet()) {
String propertyName = entry.getKey();
if (propertyName.equals("name")) {
methodName = asString(entry.getValue(), "name");
} else if (propertyName.equals("parameterTypes")) {
methodParameterTypes = parseTypes(asList(entry.getValue(), "Attribute 'parameterTypes' must be a list of type names"));
} else {
throw new JSONParserException("Unknown attribute '" + propertyName + "' (supported attributes: 'name', 'parameterTypes') in definition of method for class '" + clazz.getTypeName() + "'");
}
}
if (methodName == null) {
throw new JSONParserException("Missing attribute 'name' in definition of method for class '" + clazz.getTypeName() + "'");
}
if (methodParameterTypes != null) {
try {
Executable method;
if (CONSTRUCTOR_NAME.equals(methodName)) {
method = clazz.getDeclaredConstructor(methodParameterTypes);
} else {
method = clazz.getDeclaredMethod(methodName, methodParameterTypes);
}
registry.register(method);
} catch (NoSuchMethodException e) {
String parameterTypeNames = Stream.of(methodParameterTypes).map(Class::getSimpleName).collect(Collectors.joining(", "));
throw new JSONParserException("Method " + clazz.getTypeName() + "." + methodName + "(" + parameterTypeNames + ") not found");
}
} else {
boolean found = false;
boolean isConstructor = CONSTRUCTOR_NAME.equals(methodName);
Executable[] methods = isConstructor ? clazz.getDeclaredConstructors() : clazz.getDeclaredMethods();
for (Executable method : methods) {
if (isConstructor || method.getName().equals(methodName)) {
registry.register(method);
found = true;
}
}
if (!found) {
throw new JSONParserException("Method " + clazz.getTypeName() + "." + methodName + " not found");
}
}
}
use of com.oracle.svm.hosted.json.JSONParserException 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