@SuppressWarnings("Duplicates") private boolean implementsSelfValidating(TypeElement type) { TypeMirror validatorFactoryType = elements.getTypeElement(SelfValidating.class.getCanonicalName()) .asType(); TypeMirror typeMirror = type.asType(); if (!type.getInterfaces() .isEmpty() || typeMirror.getKind() != TypeKind.NONE) { while (typeMirror.getKind() != TypeKind.NONE) { if (searchInterfacesAncestry(typeMirror, validatorFactoryType)) { return true; } type = (TypeElement) typeUtils.asElement(typeMirror); typeMirror = type.getSuperclass(); } } return false; }
@SuppressWarnings("Duplicates") private boolean implementsSelfValidating(TypeElement type) { TypeMirror validatorFactoryType = elements.getTypeElement(SelfValidating.class.getCanonicalName()) .asType(); TypeMirror typeMirror = type.asType(); if (!type.getInterfaces() .isEmpty() || typeMirror.getKind() != TypeKind.NONE) { while (typeMirror.getKind() != TypeKind.NONE) { if (searchInterfacesAncestry(typeMirror, validatorFactoryType)) { return true; } type = (TypeElement) typeUtils.asElement(typeMirror); typeMirror = type.getSuperclass(); } } return false; }
@SuppressWarnings("Duplicates") private boolean searchInterfacesAncestry(TypeMirror rootIface, TypeMirror target) { TypeElement rootIfaceElement = (TypeElement) typeUtils.asElement(rootIface); // check if it implements valid interfaces for (TypeMirror iface : rootIfaceElement.getInterfaces()) { TypeElement ifaceElement = (TypeElement) typeUtils.asElement(rootIface); while (iface.getKind() != TypeKind.NONE) { if (typeUtils.isSameType(iface, target)) { return true; } // go up if (searchInterfacesAncestry(iface, target)) { return true; } // then move on iface = ifaceElement.getSuperclass(); } } return false; }
@SuppressWarnings("Duplicates") private boolean searchInterfacesAncestry(TypeMirror rootIface, TypeMirror target) { TypeElement rootIfaceElement = (TypeElement) typeUtils.asElement(rootIface); // check if it implements valid interfaces for (TypeMirror iface : rootIfaceElement.getInterfaces()) { TypeElement ifaceElement = (TypeElement) typeUtils.asElement(rootIface); while (iface.getKind() != TypeKind.NONE) { if (typeUtils.isSameType(iface, target)) { return true; } // go up if (searchInterfacesAncestry(iface, target)) { return true; } // then move on iface = ifaceElement.getSuperclass(); } } return false; }