diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/JavaUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/JavaUtils.java index 8ed4945f0053346cc8c867cb3b996695652c08d2..650f89aca54803c462dd4cc2a50487e3610dabf4 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/JavaUtils.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/JavaUtils.java @@ -28,7 +28,7 @@ import org.apache.commons.lang.WordUtils; * @author doebber * @author $Author$ * @version $Rev$ - * @ConQAT.Rating GREEN Hash: 0BCFE18A0C3A2F20A258EEB72B7AD343 + * @ConQAT.Rating YELLOW Hash: 15E009EC41779E81E68F52D2958BC419 */ public class JavaUtils { @@ -87,4 +87,28 @@ public class JavaUtils { return buffer.toString(); } + + /** + * Predicate whether a given {@code type} is directly derived from a given {@code superType}, or + * whether the {@code type} implements the {@code superType} interface. + * + * @param type + * Type to for which to check if it is directly derived from the given + * {@code superType}. + * @param superType + * Super-type which should be tested for the given {@code type}. + * + * @return {@code true} iff a given {@code type} is directly derived from a given + * {@code superType}, or if the {@code type} implements the {@code superType} interface. + */ + public static boolean isDirectlyDerived(Class<?> type, Class<?> superType) { + for(Class<?> iFace : type.getInterfaces()) { + if(iFace.equals(superType)) { + return true; + } + } + + Class<?> typeSuperClass = type.getSuperclass(); + return typeSuperClass != null && typeSuperClass.equals(superType); + } }