Java Code Examples for java.lang.reflect.AnnotatedType#getAnnotations()

The following examples show how to use java.lang.reflect.AnnotatedType#getAnnotations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedefineAnnotations.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void verifyArrayFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    Annotation anno;
    AnnotatedType at;

    at = c.getDeclaredField("typeAnnotatedArray").getAnnotatedType();
    anno = at.getAnnotations()[0];
    verifyTestAnn(arrayTA[0], anno, "array1");
    arrayTA[0] = anno;

    for (int i = 1; i <= 3; i++) {
        at = ((AnnotatedArrayType) at).getAnnotatedGenericComponentType();
        anno = at.getAnnotations()[0];
        verifyTestAnn(arrayTA[i], anno, "array" + (i + 1));
        arrayTA[i] = anno;
    }
}
 
Example 2
Source File: RedefineAnnotations.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void verifyArrayFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    Annotation anno;
    AnnotatedType at;

    at = c.getDeclaredField("typeAnnotatedArray").getAnnotatedType();
    anno = at.getAnnotations()[0];
    verifyTestAnn(arrayTA[0], anno, "array1");
    arrayTA[0] = anno;

    for (int i = 1; i <= 3; i++) {
        at = ((AnnotatedArrayType) at).getAnnotatedGenericComponentType();
        anno = at.getAnnotations()[0];
        verifyTestAnn(arrayTA[i], anno, "array" + (i + 1));
        arrayTA[i] = anno;
    }
}
 
Example 3
Source File: RedefineAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void verifyArrayFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    Annotation anno;
    AnnotatedType at;

    at = c.getDeclaredField("typeAnnotatedArray").getAnnotatedType();
    anno = at.getAnnotations()[0];
    verifyTestAnn(arrayTA[0], anno, "array1");
    arrayTA[0] = anno;

    for (int i = 1; i <= 3; i++) {
        at = ((AnnotatedArrayType) at).getAnnotatedGenericComponentType();
        anno = at.getAnnotations()[0];
        verifyTestAnn(arrayTA[i], anno, "array" + (i + 1));
        arrayTA[i] = anno;
    }
}
 
Example 4
Source File: GetAnnotatedSuperclass.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static void testReturnsEmptyAT() {
    for (Class<?> toTest : nonNullTestData) {
        tests++;

        AnnotatedType res = toTest.getAnnotatedSuperclass();

        if (res == null) {
            failed++;
            System.out.println(toTest + ".getAnnotatedSuperclass() returns 'null' should  be non-null");
        } else if (res.getAnnotations().length != 0) {
            failed++;
            System.out.println(toTest + ".getAnnotatedSuperclass() returns: "
                    + Arrays.asList(res.getAnnotations()) + ", should be an empty AnnotatedType");
        }
    }
}
 
Example 5
Source File: RedefineAnnotations.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void verifyArrayFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    Annotation anno;
    AnnotatedType at;

    at = c.getDeclaredField("typeAnnotatedArray").getAnnotatedType();
    anno = at.getAnnotations()[0];
    verifyTestAnn(arrayTA[0], anno, "array1");
    arrayTA[0] = anno;

    for (int i = 1; i <= 3; i++) {
        at = ((AnnotatedArrayType) at).getAnnotatedGenericComponentType();
        anno = at.getAnnotations()[0];
        verifyTestAnn(arrayTA[i], anno, "array" + (i + 1));
        arrayTA[i] = anno;
    }
}
 
Example 6
Source File: RedefineAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void verifyMapFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    Annotation anno;
    AnnotatedType atBase;
    AnnotatedType atParameter;
    atBase = c.getDeclaredField("typeAnnotatedMap").getAnnotatedType();

    anno = atBase.getAnnotations()[0];
    verifyTestAnn(mapTA[0], anno, "map1");
    mapTA[0] = anno;

    atParameter =
        ((AnnotatedParameterizedType) atBase).
        getAnnotatedActualTypeArguments()[0];
    anno = ((AnnotatedWildcardType) atParameter).getAnnotations()[0];
    verifyTestAnn(mapTA[1], anno, "map2");
    mapTA[1] = anno;

    anno =
        ((AnnotatedWildcardType) atParameter).
        getAnnotatedUpperBounds()[0].getAnnotations()[0];
    verifyTestAnn(mapTA[2], anno, "map3");
    mapTA[2] = anno;

    atParameter =
        ((AnnotatedParameterizedType) atBase).
        getAnnotatedActualTypeArguments()[1];
    anno = ((AnnotatedParameterizedType) atParameter).getAnnotations()[0];
    verifyTestAnn(mapTA[3], anno, "map4");
    mapTA[3] = anno;

    anno =
        ((AnnotatedParameterizedType) atParameter).
        getAnnotatedActualTypeArguments()[0].getAnnotations()[0];
    verifyTestAnn(mapTA[4], anno, "map5");
    mapTA[4] = anno;
}
 
Example 7
Source File: GetAnnotatedReceiverType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkEmptyAT(AnnotatedType a, String msg) {
    if (a.getAnnotations().length != 0) {
        failures++;
        System.err.print(msg);
    }
    tests++;
}
 
Example 8
Source File: GetAnnotatedReceiverType.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void checkEmptyAT(AnnotatedType a, String msg) {
    if (a.getAnnotations().length != 0) {
        failures++;
        System.err.print(msg);
    }
    tests++;
}
 
Example 9
Source File: GetAnnotatedReceiverType.java    From native-obfuscator with GNU General Public License v3.0 5 votes vote down vote up
private static void checkEmptyAT(AnnotatedType a, String msg) {
    if (a.getAnnotations().length != 0) {
        failures++;
        System.err.print(msg);
    }
    tests++;
}
 
Example 10
Source File: GetAnnotatedReceiverType.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkEmptyAT(Executable e, String msg) {
    AnnotatedType a = e.getAnnotatedReceiverType();
    if (a.getAnnotations().length != 0) {
        failures++;
        System.err.print(msg + ": " + e);
    }
    tests++;
}
 
Example 11
Source File: RedefineAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void verifyInnerFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    AnnotatedType at = c.getDeclaredField("typeAnnotatedInner").getAnnotatedType();
    Annotation anno = at.getAnnotations()[0];
    verifyTestAnn(innerTA, anno, "inner");
    innerTA = anno;
}
 
Example 12
Source File: GetAnnotatedReceiverType.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkEmptyAT(AnnotatedType a, String msg) {
    if (a.getAnnotations().length != 0) {
        failures++;
        System.err.print(msg);
    }
    tests++;
}
 
Example 13
Source File: RedefineAnnotations.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void verifyMapFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    Annotation anno;
    AnnotatedType atBase;
    AnnotatedType atParameter;
    atBase = c.getDeclaredField("typeAnnotatedMap").getAnnotatedType();

    anno = atBase.getAnnotations()[0];
    verifyTestAnn(mapTA[0], anno, "map1");
    mapTA[0] = anno;

    atParameter =
        ((AnnotatedParameterizedType) atBase).
        getAnnotatedActualTypeArguments()[0];
    anno = ((AnnotatedWildcardType) atParameter).getAnnotations()[0];
    verifyTestAnn(mapTA[1], anno, "map2");
    mapTA[1] = anno;

    anno =
        ((AnnotatedWildcardType) atParameter).
        getAnnotatedUpperBounds()[0].getAnnotations()[0];
    verifyTestAnn(mapTA[2], anno, "map3");
    mapTA[2] = anno;

    atParameter =
        ((AnnotatedParameterizedType) atBase).
        getAnnotatedActualTypeArguments()[1];
    anno = ((AnnotatedParameterizedType) atParameter).getAnnotations()[0];
    verifyTestAnn(mapTA[3], anno, "map4");
    mapTA[3] = anno;

    anno =
        ((AnnotatedParameterizedType) atParameter).
        getAnnotatedActualTypeArguments()[0].getAnnotations()[0];
    verifyTestAnn(mapTA[4], anno, "map5");
    mapTA[4] = anno;
}
 
Example 14
Source File: GetAnnotatedReceiverType.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkEmptyAT(AnnotatedType a, String msg) {
    if (a.getAnnotations().length != 0) {
        failures++;
        System.err.print(msg);
    }
    tests++;
}
 
Example 15
Source File: RedefineAnnotations.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void verifyInnerFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    AnnotatedType at = c.getDeclaredField("typeAnnotatedInner").getAnnotatedType();
    Annotation anno = at.getAnnotations()[0];
    verifyTestAnn(innerTA, anno, "inner");
    innerTA = anno;
}
 
Example 16
Source File: RedefineAnnotations.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void verifyInnerFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    AnnotatedType at = c.getDeclaredField("typeAnnotatedInner").getAnnotatedType();
    Annotation anno = at.getAnnotations()[0];
    verifyTestAnn(innerTA, anno, "inner");
    innerTA = anno;
}
 
Example 17
Source File: RedefineAnnotations.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void verifyMapFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    Annotation anno;
    AnnotatedType atBase;
    AnnotatedType atParameter;
    atBase = c.getDeclaredField("typeAnnotatedMap").getAnnotatedType();

    anno = atBase.getAnnotations()[0];
    verifyTestAnn(mapTA[0], anno, "map1");
    mapTA[0] = anno;

    atParameter =
        ((AnnotatedParameterizedType) atBase).
        getAnnotatedActualTypeArguments()[0];
    anno = ((AnnotatedWildcardType) atParameter).getAnnotations()[0];
    verifyTestAnn(mapTA[1], anno, "map2");
    mapTA[1] = anno;

    anno =
        ((AnnotatedWildcardType) atParameter).
        getAnnotatedUpperBounds()[0].getAnnotations()[0];
    verifyTestAnn(mapTA[2], anno, "map3");
    mapTA[2] = anno;

    atParameter =
        ((AnnotatedParameterizedType) atBase).
        getAnnotatedActualTypeArguments()[1];
    anno = ((AnnotatedParameterizedType) atParameter).getAnnotations()[0];
    verifyTestAnn(mapTA[3], anno, "map4");
    mapTA[3] = anno;

    anno =
        ((AnnotatedParameterizedType) atParameter).
        getAnnotatedActualTypeArguments()[0].getAnnotations()[0];
    verifyTestAnn(mapTA[4], anno, "map5");
    mapTA[4] = anno;
}
 
Example 18
Source File: GetAnnotatedReceiverType.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void checkEmptyAT(AnnotatedType a, String msg) {
    if (a.getAnnotations().length != 0) {
        failures++;
        System.err.print(msg);
    }
    tests++;
}
 
Example 19
Source File: GetAnnotatedReceiverType.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void checkEmptyAT(AnnotatedType a, String msg) {
    if (a.getAnnotations().length != 0) {
        failures++;
        System.err.print(msg);
    }
    tests++;
}
 
Example 20
Source File: OutputDefinition.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
static OutputDefinition instanceOf(Method method, Class<?> outputClass, MessageCodec socketCodec) {
    if (!CommandDefinition.checkType(method.getGenericReturnType())) {
        throw new CommunicationDefinitionException("指令的参数与返回不能有擦拭类型与通配符类型");
    }
    int modifier = outputClass.getModifiers();
    if (!outputClass.isPrimitive() && Modifier.isAbstract(modifier)) {
        throw new CommunicationDefinitionException("指令的参数与返回不能为抽象");
    }
    if (Modifier.isInterface(modifier)) {
        throw new CommunicationDefinitionException("指令的参数与返回不能为接口");
    }

    OutputDefinition instance = new OutputDefinition();
    instance.contentFormat = MessageFormat.toByte(socketCodec.outputFormat(), socketCodec.outputZip());
    instance.contentType = outputClass;
    AnnotatedType annotatedType = method.getAnnotatedReturnType();
    Annotation[] annotations = annotatedType.getAnnotations();
    boolean hasBodyVariable = false;
    CommandVariable variable = null;
    for (Annotation annotation : annotations) {
        if (annotation instanceof CommandVariable) {
            if (variable != null) {
                throw new CommunicationDefinitionException();
            }
            variable = (CommandVariable) annotation;

            if (VariableType.MESSAGE_BODY.equals(variable.type())) {
                hasBodyVariable = true;
            }
        }
    }
    if (variable != null) {
        instance.outputVariable = VariableDefinition.instanceOf(annotatedType.getType(), variable, null);
    }

    if (instance.outputVariable == null && !(outputClass.equals(void.class) || outputClass.equals(Void.class))) {
        throw new CommunicationDefinitionException();
    }
    if (instance.outputVariable != null) {
        if (!hasBodyVariable && !(outputClass.equals(void.class) || outputClass.equals(Void.class))) {
            throw new CommunicationDefinitionException();
        }

        if (hasBodyVariable && !StringUtility.isBlank(instance.outputVariable.getVariable().property()) && outputClass.equals(void.class)) {
            throw new CommunicationDefinitionException();
        }
    }

    return instance;
}