/** * Returns true if the resource passed in either an instance of the type filter class, or if * there is no type filter class defined in plugin.xml. */ public boolean isApplicableType(IResource resource) { // If type filter is null, means filter out no types. // Otherwise, return true only if the given type is an instance of // the type filter. if (_typeFilterClass == null) return true; // If the resource is an instance of the type filter class. return isInstance(resource.getClass(), _typeFilterClass); }
/** * Checks if filterClass is a parent (interface or superclass) of objectClass. */ boolean isInstance(Class objectClass, Class filterClass) { // The java.lang.Class.isInstance call doesn't check interfaces fully. // i.e., if I have two interfaces, A and B, and B extends A but // doesn't implement A, then the isInstance call will return false. // // So, instead of using Class.isInstance, do the checking myself. for (Class cl = objectClass; cl != null; cl = cl.getSuperclass()) { if (cl.getName().equals(filterClass.getName())) { return true; } Class[] clInterfaces = cl.getInterfaces(); for (int i = 0; i < clInterfaces.length; i++) { if (clInterfaces[i].getName().equals(filterClass.getName())) { return true; } return isInstance(clInterfaces[i], filterClass); } } return false; }
if (!isInstance(filterClass, mustImplementClass)) { _typeFilterClass = null; Logger logger = ValidationPlugin.getPlugin().getMsgLogger();