All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xblackcat.sjpu.skel.Definer Maven / Gradle / Ivy

Go to download

Service for generating DB access logic in simple way via interfaces and annotations

There is a newer version: 2.0
Show newest version
package org.xblackcat.sjpu.skel;

import javassist.*;

import java.lang.reflect.Method;

/**
 * 15.11.13 15:37
 *
 * @author xBlackCat
 */
public class Definer implements IDefiner {
    private final Class baseClass;
    private final Class[] paramClasses;
    private final ClassPool pool;

    public Definer(ClassPool pool, Class baseClass, Class... paramClasses) {
        this.baseClass = baseClass;
        this.pool = pool;
        this.paramClasses = paramClasses;
    }

    @Override
    public CtClass getBaseCtClass() throws NotFoundException {
        return pool.get(baseClass.getName());
    }

    @Override
    public boolean isAssignable(Class clazz) {
        return baseClass.isAssignableFrom(clazz);
    }


    @Override
    public boolean isImplemented(Method m) {
        try {
            final Method method = baseClass.getDeclaredMethod(m.getName(), m.getParameterTypes());
            return !Modifier.isAbstract(method.getModifiers());
        } catch (NoSuchMethodException e) {
            return false;
        }
    }

    @Override
    public String getNestedClassName() {
        return baseClass.getSimpleName() + "Impl";
    }

    @Override
    public CtConstructor buildCtConstructor(CtClass accessHelper) throws NotFoundException, CannotCompileException {
        return CtNewConstructor.make(
                BuilderUtils.toCtClasses(pool, paramClasses),
                BuilderUtils.EMPTY_LIST,
                "{ super($$); }",
                accessHelper
        );
    }

    @Override
    public ClassPool getPool() {
        return pool;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy