Search in sources :

Example 6 with Delete

use of com.oracle.svm.core.annotate.Delete in project graal by oracle.

the class AnnotationSubstitutionProcessor method handleClass.

private void handleClass(Class<?> annotatedClass) {
    guarantee(Modifier.isFinal(annotatedClass.getModifiers()) || annotatedClass.isInterface(), "Annotated class must be final: %s", annotatedClass);
    guarantee(annotatedClass.getSuperclass() == Object.class || annotatedClass.isInterface(), "Annotated class must inherit directly from Object: %s", annotatedClass);
    if (!NativeImageGenerator.includedIn(ImageSingletons.lookup(Platform.class), lookupAnnotation(annotatedClass, Platforms.class))) {
        return;
    }
    TargetClass targetClassAnnotation = lookupAnnotation(annotatedClass, TargetClass.class);
    Class<?> originalClass = findTargetClass(annotatedClass, targetClassAnnotation);
    if (originalClass == null) {
        return;
    }
    Delete deleteAnnotation = lookupAnnotation(annotatedClass, Delete.class);
    Substitute substituteAnnotation = lookupAnnotation(annotatedClass, Substitute.class);
    int numAnnotations = (deleteAnnotation != null ? 1 : 0) + (substituteAnnotation != null ? 1 : 0);
    guarantee(numAnnotations <= 1, "Only one of @Delete or @Substitute can be used: %s", annotatedClass);
    if (deleteAnnotation != null) {
        handleDeletedClass(originalClass, deleteAnnotation);
    } else if (substituteAnnotation != null) {
        handleSubstitutionClass(annotatedClass, originalClass);
    } else {
        handleAliasClass(annotatedClass, originalClass);
    }
}
Also used : Delete(com.oracle.svm.core.annotate.Delete) TargetClass(com.oracle.svm.core.annotate.TargetClass) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 7 with Delete

use of com.oracle.svm.core.annotate.Delete in project graal by oracle.

the class AnnotationSubstitutionProcessor method handleMethodInAliasClass.

private void handleMethodInAliasClass(Executable annotatedMethod, Class<?> originalClass) {
    if (!NativeImageGenerator.includedIn(ImageSingletons.lookup(Platform.class), lookupAnnotation(annotatedMethod, Platforms.class))) {
        return;
    }
    Delete deleteAnnotation = lookupAnnotation(annotatedMethod, Delete.class);
    Substitute substituteAnnotation = lookupAnnotation(annotatedMethod, Substitute.class);
    AnnotateOriginal annotateOriginalAnnotation = lookupAnnotation(annotatedMethod, AnnotateOriginal.class);
    Alias aliasAnnotation = lookupAnnotation(annotatedMethod, Alias.class);
    int numAnnotations = (deleteAnnotation != null ? 1 : 0) + (substituteAnnotation != null ? 1 : 0) + (annotateOriginalAnnotation != null ? 1 : 0) + (aliasAnnotation != null ? 1 : 0);
    if (numAnnotations == 0) {
        guarantee(annotatedMethod instanceof Constructor, "One of @Delete, @Substitute, @AnnotateOriginal, or @Alias must be used: %s", annotatedMethod);
        return;
    }
    guarantee(numAnnotations == 1, "Only one of @Delete, @Substitute, @AnnotateOriginal, or @Alias can be used: %s", annotatedMethod);
    ResolvedJavaMethod annotated = metaAccess.lookupJavaMethod(annotatedMethod);
    ResolvedJavaMethod original = findOriginalMethod(annotatedMethod, originalClass);
    if (original == null) {
    /* Optional target that is not present, so nothing to do. */
    } else if (deleteAnnotation != null) {
        registerAsDeleted(annotated, original, deleteAnnotation);
    } else if (substituteAnnotation != null) {
        SubstitutionMethod substitution = new SubstitutionMethod(original, annotated);
        register(methodSubstitutions, annotated, original, substitution);
    } else if (annotateOriginalAnnotation != null) {
        AnnotatedMethod substitution = new AnnotatedMethod(original, annotated);
        register(methodSubstitutions, annotated, original, substitution);
    } else if (aliasAnnotation != null) {
        register(methodSubstitutions, annotated, original, original);
    }
}
Also used : Delete(com.oracle.svm.core.annotate.Delete) AnnotateOriginal(com.oracle.svm.core.annotate.AnnotateOriginal) CustomSubstitutionMethod(com.oracle.svm.hosted.annotation.CustomSubstitutionMethod) Alias(com.oracle.svm.core.annotate.Alias) Constructor(java.lang.reflect.Constructor) Substitute(com.oracle.svm.core.annotate.Substitute) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

Delete (com.oracle.svm.core.annotate.Delete)7 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)3 Alias (com.oracle.svm.core.annotate.Alias)2 Substitute (com.oracle.svm.core.annotate.Substitute)2 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 AnnotateOriginal (com.oracle.svm.core.annotate.AnnotateOriginal)1 Inject (com.oracle.svm.core.annotate.Inject)1 TargetClass (com.oracle.svm.core.annotate.TargetClass)1 CustomSubstitutionMethod (com.oracle.svm.hosted.annotation.CustomSubstitutionMethod)1 Constructor (java.lang.reflect.Constructor)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1