use of com.laytonsmith.annotations.NonInheritImplements in project CommandHelper by EngineHub.
the class AnnotationChecks method verifyNonInheritImplements.
public static void verifyNonInheritImplements() throws ClassNotFoundException {
Set<ClassMirror<?>> toVerify;
toVerify = ClassDiscovery.getDefaultInstance().getClassesWithAnnotation(NonInheritImplements.class);
Set<String> uhohs = new HashSet<>();
for (ClassMirror<?> c : toVerify) {
Class<?> iface = Class.forName(c.getAnnotation(NonInheritImplements.class).getValue("value").toString());
if (!iface.isInterface()) {
uhohs.add("The class given to @NonInheritImplements, tagged on " + c.getClassName() + " is not an interface, and must be.");
continue;
}
// methods.
for (Method im : iface.getDeclaredMethods()) {
try {
c.getMethod(im.getName(), im.getParameterTypes());
} catch (NoSuchMethodException ex) {
String msg = "The class " + c.getClassName() + " implements " + iface.getSimpleName() + " but does not" + " implement the method public " + im.getReturnType().getSimpleName() + " " + im.getName() + "(";
List<String> params = new ArrayList<>();
msg += StringUtils.Join(im.getParameters(), ", ", ", ", ", ", "", (Object item) -> {
Parameter ci = (Parameter) item;
return ci.getType().getSimpleName() + " " + ci.getName();
});
msg += ") {}";
uhohs.add(msg);
}
}
}
if (!uhohs.isEmpty()) {
String error = StringUtils.Join(uhohs, "\n");
throw new Error(error);
}
}
Aggregations