Search in sources :

Example 1 with NonInheritImplements

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);
    }
}
Also used : NonInheritImplements(com.laytonsmith.annotations.NonInheritImplements) Method(java.lang.reflect.Method) ClassMirror(com.laytonsmith.PureUtilities.ClassLoading.ClassMirror.ClassMirror) Parameter(java.lang.reflect.Parameter) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

ClassMirror (com.laytonsmith.PureUtilities.ClassLoading.ClassMirror.ClassMirror)1 NonInheritImplements (com.laytonsmith.annotations.NonInheritImplements)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1