java.lang.NoSuchMethodException Java Examples

The following examples show how to use java.lang.NoSuchMethodException. 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 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 #2
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 #3
Source File: RedefineAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void verifyMethodTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {
    Annotation anno;
    Executable typeAnnotatedMethod =
        c.getDeclaredMethod("typeAnnotatedMethod", TypeAnnotatedTestClass.class);

    anno = typeAnnotatedMethod.getAnnotatedReturnType().getAnnotations()[0];
    verifyTestAnn(returnTA, anno, "return");
    returnTA = anno;

    anno = typeAnnotatedMethod.getTypeParameters()[0].getAnnotations()[0];
    verifyTestAnn(methodTypeParameterTA, anno, "methodTypeParameter");
    methodTypeParameterTA = anno;

    anno = typeAnnotatedMethod.getAnnotatedParameterTypes()[0].getAnnotations()[0];
    verifyTestAnn(formalParameterTA, anno, "formalParameter");
    formalParameterTA = anno;

    anno = typeAnnotatedMethod.getAnnotatedExceptionTypes()[0].getAnnotations()[0];
    verifyTestAnn(throwsTA, anno, "throws");
    throwsTA = anno;
}
 
Example #4
Source File: RedefineAnnotations.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void verifyMethodTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {
    Annotation anno;
    Executable typeAnnotatedMethod =
        c.getDeclaredMethod("typeAnnotatedMethod", TypeAnnotatedTestClass.class);

    anno = typeAnnotatedMethod.getAnnotatedReturnType().getAnnotations()[0];
    verifyTestAnn(returnTA, anno, "return");
    returnTA = anno;

    anno = typeAnnotatedMethod.getTypeParameters()[0].getAnnotations()[0];
    verifyTestAnn(methodTypeParameterTA, anno, "methodTypeParameter");
    methodTypeParameterTA = anno;

    anno = typeAnnotatedMethod.getAnnotatedParameterTypes()[0].getAnnotations()[0];
    verifyTestAnn(formalParameterTA, anno, "formalParameter");
    formalParameterTA = anno;

    anno = typeAnnotatedMethod.getAnnotatedExceptionTypes()[0].getAnnotations()[0];
    verifyTestAnn(throwsTA, anno, "throws");
    throwsTA = anno;
}
 
Example #5
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 #6
Source File: RedefineAnnotations.java    From openjdk-jdk8u 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 #7
Source File: RedefineAnnotations.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void verifyMethodTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {
    Annotation anno;
    Executable typeAnnotatedMethod =
        c.getDeclaredMethod("typeAnnotatedMethod", TypeAnnotatedTestClass.class);

    anno = typeAnnotatedMethod.getAnnotatedReturnType().getAnnotations()[0];
    verifyTestAnn(returnTA, anno, "return");
    returnTA = anno;

    anno = typeAnnotatedMethod.getTypeParameters()[0].getAnnotations()[0];
    verifyTestAnn(methodTypeParameterTA, anno, "methodTypeParameter");
    methodTypeParameterTA = anno;

    anno = typeAnnotatedMethod.getAnnotatedParameterTypes()[0].getAnnotations()[0];
    verifyTestAnn(formalParameterTA, anno, "formalParameter");
    formalParameterTA = anno;

    anno = typeAnnotatedMethod.getAnnotatedExceptionTypes()[0].getAnnotations()[0];
    verifyTestAnn(throwsTA, anno, "throws");
    throwsTA = anno;
}
 
Example #8
Source File: RedefineAnnotations.java    From hottub 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 #9
Source File: RedefineAnnotations.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void verifyMethodTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {
    Annotation anno;
    Executable typeAnnotatedMethod =
        c.getDeclaredMethod("typeAnnotatedMethod", TypeAnnotatedTestClass.class);

    anno = typeAnnotatedMethod.getAnnotatedReturnType().getAnnotations()[0];
    verifyTestAnn(returnTA, anno, "return");
    returnTA = anno;

    anno = typeAnnotatedMethod.getTypeParameters()[0].getAnnotations()[0];
    verifyTestAnn(methodTypeParameterTA, anno, "methodTypeParameter");
    methodTypeParameterTA = anno;

    anno = typeAnnotatedMethod.getAnnotatedParameterTypes()[0].getAnnotations()[0];
    verifyTestAnn(formalParameterTA, anno, "formalParameter");
    formalParameterTA = anno;

    anno = typeAnnotatedMethod.getAnnotatedExceptionTypes()[0].getAnnotations()[0];
    verifyTestAnn(throwsTA, anno, "throws");
    throwsTA = anno;
}
 
Example #10
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 #11
Source File: RedefineAnnotations.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void verifyMethodTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {
    Annotation anno;
    Executable typeAnnotatedMethod =
        c.getDeclaredMethod("typeAnnotatedMethod", TypeAnnotatedTestClass.class);

    anno = typeAnnotatedMethod.getAnnotatedReturnType().getAnnotations()[0];
    verifyTestAnn(returnTA, anno, "return");
    returnTA = anno;

    anno = typeAnnotatedMethod.getTypeParameters()[0].getAnnotations()[0];
    verifyTestAnn(methodTypeParameterTA, anno, "methodTypeParameter");
    methodTypeParameterTA = anno;

    anno = typeAnnotatedMethod.getAnnotatedParameterTypes()[0].getAnnotations()[0];
    verifyTestAnn(formalParameterTA, anno, "formalParameter");
    formalParameterTA = anno;

    anno = typeAnnotatedMethod.getAnnotatedExceptionTypes()[0].getAnnotations()[0];
    verifyTestAnn(throwsTA, anno, "throws");
    throwsTA = anno;
}
 
Example #12
Source File: RedefineAnnotations.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void verifyMethodTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {
    Annotation anno;
    Executable typeAnnotatedMethod =
        c.getDeclaredMethod("typeAnnotatedMethod", TypeAnnotatedTestClass.class);

    anno = typeAnnotatedMethod.getAnnotatedReturnType().getAnnotations()[0];
    verifyTestAnn(returnTA, anno, "return");
    returnTA = anno;

    anno = typeAnnotatedMethod.getTypeParameters()[0].getAnnotations()[0];
    verifyTestAnn(methodTypeParameterTA, anno, "methodTypeParameter");
    methodTypeParameterTA = anno;

    anno = typeAnnotatedMethod.getAnnotatedParameterTypes()[0].getAnnotations()[0];
    verifyTestAnn(formalParameterTA, anno, "formalParameter");
    formalParameterTA = anno;

    anno = typeAnnotatedMethod.getAnnotatedExceptionTypes()[0].getAnnotations()[0];
    verifyTestAnn(throwsTA, anno, "throws");
    throwsTA = anno;
}
 
Example #13
Source File: RedefineAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void testTransformAndVerify()
    throws NoSuchFieldException, NoSuchMethodException {

    Class<TypeAnnotatedTestClass> c = TypeAnnotatedTestClass.class;
    Class<?> myClass = c;

    /*
     * Verify that the expected annotations are where they should be before transform.
     */
    verifyClassTypeAnnotations(c);
    verifyFieldTypeAnnotations(c);
    verifyMethodTypeAnnotations(c);

    try {
        inst.addTransformer(new Transformer(), true);
        inst.retransformClasses(myClass);
    } catch (UnmodifiableClassException e) {
        throw new RuntimeException(e);
    }

    /*
     * Verify that the expected annotations are where they should be after transform.
     * Also verify that before and after are equal.
     */
    verifyClassTypeAnnotations(c);
    verifyFieldTypeAnnotations(c);
    verifyMethodTypeAnnotations(c);
}
 
Example #14
Source File: RedefineAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String argv[]) throws NoSuchFieldException, NoSuchMethodException {
    if (argv.length == 1 && argv[0].equals("buildagent")) {
        buildAgent();
        return;
    }

    if (inst == null) {
        throw new RuntimeException("Instrumentation object was null");
    }

    RedefineAnnotations test = new RedefineAnnotations();
    test.testTransformAndVerify();
}
 
Example #15
Source File: RedefineAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void verifyFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    verifyBasicFieldTypeAnnotations(c);
    verifyInnerFieldTypeAnnotations(c);
    verifyArrayFieldTypeAnnotations(c);
    verifyMapFieldTypeAnnotations(c);
}
 
Example #16
Source File: RedefineAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void verifyBasicFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    Annotation anno = c.getDeclaredField("typeAnnotatedBoolean").getAnnotatedType().getAnnotations()[0];
    verifyTestAnn(fieldTA, anno, "field");
    fieldTA = anno;
}
 
Example #17
Source File: RedefineAnnotations.java    From openjdk-jdk8u-backup 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: 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 #19
Source File: RedefineAnnotations.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String argv[]) throws NoSuchFieldException, NoSuchMethodException {
    if (argv.length == 1 && argv[0].equals("buildagent")) {
        buildAgent();
        return;
    }

    if (inst == null) {
        throw new RuntimeException("Instrumentation object was null");
    }

    RedefineAnnotations test = new RedefineAnnotations();
    test.testTransformAndVerify();
}
 
Example #20
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 #21
Source File: RedefineAnnotations.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void verifyFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    verifyBasicFieldTypeAnnotations(c);
    verifyInnerFieldTypeAnnotations(c);
    verifyArrayFieldTypeAnnotations(c);
    verifyMapFieldTypeAnnotations(c);
}
 
Example #22
Source File: RedefineAnnotations.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void testTransformAndVerify()
    throws NoSuchFieldException, NoSuchMethodException {

    Class<TypeAnnotatedTestClass> c = TypeAnnotatedTestClass.class;
    Class<?> myClass = c;

    /*
     * Verify that the expected annotations are where they should be before transform.
     */
    verifyClassTypeAnnotations(c);
    verifyFieldTypeAnnotations(c);
    verifyMethodTypeAnnotations(c);

    try {
        inst.addTransformer(new Transformer(), true);
        inst.retransformClasses(myClass);
    } catch (UnmodifiableClassException e) {
        throw new RuntimeException(e);
    }

    /*
     * Verify that the expected annotations are where they should be after transform.
     * Also verify that before and after are equal.
     */
    verifyClassTypeAnnotations(c);
    verifyFieldTypeAnnotations(c);
    verifyMethodTypeAnnotations(c);
}
 
Example #23
Source File: RedefineAnnotations.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void verifyFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    verifyBasicFieldTypeAnnotations(c);
    verifyInnerFieldTypeAnnotations(c);
    verifyArrayFieldTypeAnnotations(c);
    verifyMapFieldTypeAnnotations(c);
}
 
Example #24
Source File: RedefineAnnotations.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void verifyBasicFieldTypeAnnotations(Class c)
    throws NoSuchFieldException, NoSuchMethodException {

    Annotation anno = c.getDeclaredField("typeAnnotatedBoolean").getAnnotatedType().getAnnotations()[0];
    verifyTestAnn(fieldTA, anno, "field");
    fieldTA = anno;
}
 
Example #25
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 #26
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 #27
Source File: TestUtils.java    From Spyglass with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static Object invokePrivateMethod(Object target, String methodName, Object... parameters)
    throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Method method = getDeclaredMethodIgnoreCase(target.getClass(), methodName, parameters);
    method.setAccessible(true);

    if (parameters != null && parameters.length > 0) {
        return method.invoke(target, (Object[]) parameters);
    }
    return method.invoke(target);
}
 
Example #28
Source File: TEnumHelper.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
/**
 * Given a TEnum class and integer value, this method will return
 * the associated constant from the given TEnum class.
 * This method MUST be modified should the name of the 'findByValue' method
 * change.
 *
 * @param enumClass TEnum from which to return a matching constant.
 * @param value Value for which to return the constant.
 *
 * @return The constant in 'enumClass' whose value is 'value' or null if
 *         something went wrong.
 */
public static TEnum getByValue(Class<? extends TEnum> enumClass, int value) {
  try {
    Method method = enumClass.getMethod("findByValue", int.class);
    return (TEnum) method.invoke(null, value);
  } catch (NoSuchMethodException nsme) {
    return null;
  } catch (IllegalAccessException iae) {
    return null;
  } catch (InvocationTargetException ite) {
    return null;
  }
}
 
Example #29
Source File: TEnumHelper.java    From galaxy-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * Given a TEnum class and integer value, this method will return
 * the associated constant from the given TEnum class.
 * This method MUST be modified should the name of the 'findByValue' method
 * change.
 *
 * @param enumClass TEnum from which to return a matching constant.
 * @param value Value for which to return the constant.
 *
 * @return The constant in 'enumClass' whose value is 'value' or null if
 *         something went wrong.
 */
public static TEnum getByValue(Class<? extends TEnum> enumClass, int value) {
  try {
    Method method = enumClass.getMethod("findByValue", int.class);
    return (TEnum) method.invoke(null, value);
  } catch (NoSuchMethodException nsme) {
    return null;
  } catch (IllegalAccessException iae) {
    return null;
  } catch (InvocationTargetException ite) {
    return null;
  }
}
 
Example #30
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;
}