@Test public void testIsAssignableFrom_interface() { Type baseType = Type.getObjectType("C"); Type interfaceType = Type.getObjectType("I"); SimpleVerifier simpleVerifier = new SimpleVerifier(Opcodes.ASM7, interfaceType, null, null, true) { @Override protected Type getSuperClass(final Type type) { return Type.getObjectType("java/lang/Object"); } }; assertTrue(simpleVerifier.isAssignableFrom(interfaceType, baseType)); assertTrue(simpleVerifier.isAssignableFrom(interfaceType, Type.getObjectType("[I"))); assertFalse(simpleVerifier.isAssignableFrom(interfaceType, Type.INT_TYPE)); }
protected boolean isAssignableFrom(final Type type1, final Type type2) { if (type1.equals(type2)) { return true; } if (currentClass != null && currentClass.equals(type1)) { if (getSuperClass(type2) == null) { return false; } else { if (isInterface) { return type2.getSort() == Type.OBJECT || type2.getSort() == Type.ARRAY; } return isAssignableFrom(type1, getSuperClass(type2)); } } if (currentClass != null && currentClass.equals(type2)) { if (isAssignableFrom(type1, currentSuperClass)) { return true; } if (currentClassInterfaces != null) { for (Type currentClassInterface : currentClassInterfaces) { if (isAssignableFrom(type1, currentClassInterface)) { return true; } } } return false; } return getClass(type1).isAssignableFrom(getClass(type2)); }
SimpleVerifier extends BasicVerifier { protected boolean isAssignableFrom(final Type type1, final Type type2) { if (type1.equals(type2)) { return true; } if (currentClass != null && currentClass.equals(type1)) { if (getSuperClass(type2) == null) { return false; } else { if (isInterface) { return type2.getSort() == Type.OBJECT || type2.getSort() == Type.ARRAY; } return isAssignableFrom(type1, getSuperClass(type2)); } } if (currentClass != null && currentClass.equals(type2)) { if (isAssignableFrom(type1, currentSuperClass)) { return true; } if (currentClassInterfaces != null) { for (Type currentClassInterface : currentClassInterfaces) { if (isAssignableFrom(type1, currentClassInterface)) { return true; } } } return false; } return getClass(type1).isAssignableFrom(getClass(type2)); } }
SimpleVerifier extends BasicVerifier { protected boolean isAssignableFrom(final Type type1, final Type type2) { if (type1.equals(type2)) { return true; } if (currentClass != null && currentClass.equals(type1)) { if (getSuperClass(type2) == null) { return false; } else { if (isInterface) { return type2.getSort() == Type.OBJECT || type2.getSort() == Type.ARRAY; } return isAssignableFrom(type1, getSuperClass(type2)); } } if (currentClass != null && currentClass.equals(type2)) { if (isAssignableFrom(type1, currentSuperClass)) { return true; } if (currentClassInterfaces != null) { for (Type currentClassInterface : currentClassInterfaces) { if (isAssignableFrom(type1, currentClassInterface)) { return true; } } } return false; } return getClass(type1).isAssignableFrom(getClass(type2)); } SimpleVerifier();  SimpleVerifier(
      final Type currentClass, final Type currentSuperClass, final boolean isInterface);  SimpleVerifier(
      final Type currentClass,
      final Type currentSuperClass,
      final List<Type> currentClassInterfaces,
      final boolean isInterface); protected  SimpleVerifier(
      final int api,
      final Type currentClass,
      final Type currentSuperClass,
      final List<Type> currentClassInterfaces,
      final boolean isInterface); }
SimpleVerifier extends BasicVerifier { protected boolean isAssignableFrom(final Type type1, final Type type2) { if (type1.equals(type2)) { return true; } if (currentClass != null && currentClass.equals(type1)) { if (getSuperClass(type2) == null) { return false; } else { if (isInterface) { return type2.getSort() == Type.OBJECT || type2.getSort() == Type.ARRAY; } return isAssignableFrom(type1, getSuperClass(type2)); } } if (currentClass != null && currentClass.equals(type2)) { if (isAssignableFrom(type1, currentSuperClass)) { return true; } if (currentClassInterfaces != null) { for (Type currentClassInterface : currentClassInterfaces) { if (isAssignableFrom(type1, currentClassInterface)) { return true; } } } return false; } return getClass(type1).isAssignableFrom(getClass(type2)); } SimpleVerifier();  SimpleVerifier(
      final Type currentClass, final Type currentSuperClass, final boolean isInterface);  SimpleVerifier(
      final Type currentClass,
      final Type currentSuperClass,
      final List<Type> currentClassInterfaces,
      final boolean isInterface); protected  SimpleVerifier(
      final int api,
      final Type currentClass,
      final Type currentSuperClass,
      final List<Type> currentClassInterfaces,
      final boolean isInterface); void setClassLoader(final ClassLoader loader); @Override BasicValue newValue(final Type type); @Override BasicValue merge(final BasicValue value1, final BasicValue value2); }
SimpleVerifier extends BasicVerifier { protected boolean isAssignableFrom(final Type type1, final Type type2) { if (type1.equals(type2)) { return true; } if (currentClass != null && currentClass.equals(type1)) { if (getSuperClass(type2) == null) { return false; } else { if (isInterface) { return type2.getSort() == Type.OBJECT || type2.getSort() == Type.ARRAY; } return isAssignableFrom(type1, getSuperClass(type2)); } } if (currentClass != null && currentClass.equals(type2)) { if (isAssignableFrom(type1, currentSuperClass)) { return true; } if (currentClassInterfaces != null) { for (Type currentClassInterface : currentClassInterfaces) { if (isAssignableFrom(type1, currentClassInterface)) { return true; } } } return false; } return getClass(type1).isAssignableFrom(getClass(type2)); } SimpleVerifier();  SimpleVerifier(
      final Type currentClass, final Type currentSuperClass, final boolean isInterface);  SimpleVerifier(
      final Type currentClass,
      final Type currentSuperClass,
      final List<Type> currentClassInterfaces,
      final boolean isInterface); protected  SimpleVerifier(
      final int api,
      final Type currentClass,
      final Type currentSuperClass,
      final List<Type> currentClassInterfaces,
      final boolean isInterface); void setClassLoader(final ClassLoader loader); @Override BasicValue newValue(final Type type); @Override BasicValue merge(final BasicValue value1, final BasicValue value2);  }