org.xblackcat.sjpu.skel.FunctionalClassBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sjpu-dbah Show documentation
Show all versions of sjpu-dbah Show documentation
Service for generating DB access logic in simple way via interfaces and annotations
package org.xblackcat.sjpu.skel;
import org.xblackcat.sjpu.storage.IFunctionalAH;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
/**
* Functional builder allows only one abstract method per class/interface.
*
* @author xBlackCat
*/
public class FunctionalClassBuilder extends ClassBuilder {
public FunctionalClassBuilder(IDefiner definerF, IMethodBuilder>... builders) {
super(definerF, builders);
}
@Override
public Class extends T> build(
Class target
) throws GeneratorException {
int abstractCount = 0;
for (Method m : target.getMethods()) {
if (Modifier.isAbstract(m.getModifiers())) {
abstractCount++;
}
}
for (Method m : target.getDeclaredMethods()) {
if (!Modifier.isPublic(m.getModifiers()) && Modifier.isAbstract(m.getModifiers())) {
abstractCount++;
}
}
if (abstractCount != 1) {
throw new GeneratorException(
"Only single abstract method is allowed for implementation of " +
BuilderUtils.getName(IFunctionalAH.class) + ". " + BuilderUtils.getName(target) + " has " +
abstractCount
);
}
return super.build(target);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy