Exemplo n.º 1
0
  public static String isLocalType(Class<?> type) {
    /* As per [JACKSON-187], GAE seems to throw SecurityExceptions
     * here and there... and GAE itself has a bug, too
     * (see []). Bah.
     */
    try {
      // one more: method locals, anonymous, are not good:
      if (type.getEnclosingMethod() != null) {
        return "local/anonymous";
      }

      /* But how about non-static inner classes? Can't construct
       * easily (theoretically, we could try to check if parent
       * happens to be enclosing... but that gets convoluted)
       */
      if (type.getEnclosingClass() != null) {
        if (!Modifier.isStatic(type.getModifiers())) {
          return "non-static member class";
        }
      }
    } catch (SecurityException e) {
    } catch (NullPointerException e) {
    }
    return null;
  }
 @Test
 public void testEnclosingMethod() throws Exception {
   for (Class<?> type : standardTypes) {
     Matcher<MethodDescription> matcher;
     if (type.getEnclosingMethod() != null) {
       matcher =
           CoreMatchers.<MethodDescription>is(
               new MethodDescription.ForLoadedMethod(type.getEnclosingMethod()));
     } else if (type.getEnclosingConstructor() != null) {
       matcher =
           CoreMatchers.<MethodDescription>is(
               new MethodDescription.ForLoadedConstructor(type.getEnclosingConstructor()));
     } else {
       matcher = nullValue(MethodDescription.class);
     }
     assertThat(describe(type).getEnclosingMethod(), matcher);
   }
 }
Exemplo n.º 3
0
  /**
   * Runs the test using the specified harness.
   *
   * @param harness the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness) {
    // create instance of a class AbstractMethodError
    final Object o = new AbstractMethodError("AbstractMethodError");

    // get a runtime class of an object "o"
    final Class c = o.getClass();

    java.lang.reflect.Method m = c.getEnclosingMethod();
    harness.check(m == null);
  }