Fix maven plugin not recognizing transitive interfaces 59/15459/1
authorRobert Varga <rovarga@cisco.com>
Wed, 18 Feb 2015 10:46:51 +0000 (11:46 +0100)
committerRobert Varga <rovarga@cisco.com>
Wed, 18 Feb 2015 10:47:56 +0000 (11:47 +0100)
An implenter does not need to directly implement the interface, but can
rely on it being captured somewhere else. Instead of custom magic, use
Class.isAssignableFrom() to check for compatibility.

Change-Id: I1e21b9880eb0a48bbe6027518cea39fef13b6ec6
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/Util.java

index b9287185b3ba47d9d27adb1d9201f13eadc3d1c0..ee9a6897423788f38eeff1bbce37a10103f44411 100644 (file)
@@ -126,21 +126,12 @@ final class Util {
     private static Class<?> resolveClass(String codeGeneratorClass, Class<?> baseType) throws ClassNotFoundException {
         Class<?> clazz = Class.forName(codeGeneratorClass);
 
-        if (!isImplemented(baseType, clazz)) {
+        if (!baseType.isAssignableFrom(clazz)) {
             throw new IllegalArgumentException("Code generator " + clazz + " has to implement " + baseType);
         }
         return clazz;
     }
 
-    private static boolean isImplemented(Class<?> expectedIface, Class<?> byClazz) {
-        for (Class<?> iface : byClazz.getInterfaces()) {
-            if (iface.equals(expectedIface)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     static String message(String message, String logPrefix, Object... args) {
         String innerMessage = String.format(message, args);
         return String.format("%s %s", logPrefix, innerMessage);