Search in sources :

Example 1 with JSONParser

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);
        }
    }
}
Also used : Field(java.lang.reflect.Field) TargetClass(com.oracle.svm.core.annotate.TargetClass) JSONParser(com.oracle.svm.hosted.json.JSONParser) List(java.util.List) TargetClass(com.oracle.svm.core.annotate.TargetClass) Executable(java.lang.reflect.Executable) HashSet(java.util.HashSet)

Example 2 with JSONParser

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() + ".");
    }
}
Also used : JSONParserException(com.oracle.svm.hosted.json.JSONParserException) JSONParser(com.oracle.svm.hosted.json.JSONParser) IOException(java.io.IOException)

Aggregations

JSONParser (com.oracle.svm.hosted.json.JSONParser)2 TargetClass (com.oracle.svm.core.annotate.TargetClass)1 JSONParserException (com.oracle.svm.hosted.json.JSONParserException)1 IOException (java.io.IOException)1 Executable (java.lang.reflect.Executable)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 List (java.util.List)1