
framework.annotation.Factory Maven / Gradle / Ivy
package framework.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import framework.AbstractBuilder;
import framework.AbstractBuilder.PropertyBuilder;
import framework.Reflector;
/**
* Factory info
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Factory {
/**
* @return apply group
*/
Class extends AbstractBuilder, ?, ?>> value();
/**
* Factory constructor
*/
public class Constructor {
/**
* @param Target class type
* @param targetClass Target class
* @return Target factory instance
*/
@SuppressWarnings("unchecked")
public static AbstractBuilder instance(Class targetClass) {
Factory factory = targetClass.getAnnotation(Factory.class);
Class> builder = factory != null ? factory.value() : Reflector.clazz(targetClass.getName() + "$Builder").orElse(null);
return builder != null ? (AbstractBuilder) Reflector.instance(builder) : new PropertyBuilder<>(() -> Reflector.instance(targetClass));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy