private boolean validDestinationMethod(Method method) {
    Class<?>[] argTypes = method.getParameterTypes();

    switch (argTypes.length) {
      case 2:
        if (!ClassUtils.isImplement(argTypes[1], Callback.class)) return false;
      case 1:
        if (!ClassUtils.isImplement(argTypes[0], Params.class)
            && !ClassUtils.isImplement(argTypes[0], Callback.class)) return false;
      case 0:
        break;
      default:
        Log.w(TAG, "dest:" + method.getName() + " has illegal arguments");
        return false;
    }

    return true;
  }
Esempio n. 2
0
  public void testGetMethodsByName() throws Exception {
    Method[] ms = ClassUtils.getMethodsByName(BbbImpl.class, "func");

    assertEquals(2, ms.length);
    assertNotNull(ms[0]);
    assertNotNull(ms[1]);
    assertFalse("Both objects are equals", ms[0].equals(ms[1]));
    // find which method is which, as order of the methods in the list isn't
    // guaranteed by the Java reflection API
    final int bridgeMethodIndex = ms[0].isBridge() ? 0 : 1;
    final int nonBridgeMethodIndex = (bridgeMethodIndex + 1) % 2;
    assertTrue(ms[bridgeMethodIndex].isBridge());
    assertFalse(ms[nonBridgeMethodIndex].isBridge());

    assertEquals(AaaImplExt.class, ms[nonBridgeMethodIndex].getGenericParameterTypes()[0]);
    assertEquals(Aaa.class, ms[bridgeMethodIndex].getGenericParameterTypes()[0]);
  }
Esempio n. 3
0
 public void testGetConstructor() throws Exception {
   Constructor<Cons> c =
       ClassUtils.getConstructor(Cons.class, new Class[] {String.class, String.class});
   assertNotNull(c);
 }
Esempio n. 4
0
 public void testNewInstanceWithArgs() throws Exception {
   Cons c = ClassUtils.newInstance(Cons.class, "aaa", "bbb");
   assertEquals("aaa", c.mAaa);
   assertEquals("bbb", c.mBbb);
 }
Esempio n. 5
0
 public void testToClasses() throws Exception {
   Class<?>[] classes = ClassUtils.toClasses("a", new Integer(1), "b");
   assertEquals(String.class, classes[0]);
   assertEquals(Integer.class, classes[1]);
   assertEquals(String.class, classes[2]);
 }
Esempio n. 6
0
 public void testGetGenericType() {
   Type[] types = ClassUtils.getGenericType(BbbImpl.class, Bbb.class);
   assertEquals(1, types.length);
   assertEquals(AaaImplExt.class, types[0]);
 }
Esempio n. 7
0
 public void testIsImplement() {
   assertTrue(ClassUtils.isImplement(AaaImpl.class, Aaa.class));
   assertTrue(ClassUtils.isImplement(AaaImplExt.class, Aaa.class));
   assertFalse(ClassUtils.isImplement(Object.class, Aaa.class));
 }