40 lines
1.3 KiB
Java
40 lines
1.3 KiB
Java
package net.tomatentum.cutin;
|
|
|
|
import java.lang.reflect.Method;
|
|
import java.util.HashMap;
|
|
import java.util.Optional;
|
|
import java.util.Set;
|
|
|
|
import net.tomatentum.cutin.method.ReflectedMethod;
|
|
|
|
|
|
public interface ReflectedMethodFactory<I extends Object, C extends Object> {
|
|
Optional<ReflectedMethod<I, C>> produce(Method method, Object containingClass);
|
|
ReflectedMethodFactory<I, C> addFactory(Factory<I, C> factory);
|
|
|
|
public interface Factory<I extends Object, C extends Object> {
|
|
|
|
Optional<ReflectedMethod<I, C>> produce(Method method, Object containingObject, ParserResults parserResults);
|
|
void addParser(Set<MethodParser> parser);
|
|
|
|
}
|
|
|
|
public static class ParserResults extends HashMap<Class<? extends MethodParser>, Object> {
|
|
|
|
public static ParserResults create(Set<MethodParser> parser, Method method, Object containingObject) {
|
|
ParserResults results = new ParserResults();
|
|
for (MethodParser p : parser) {
|
|
results.put(p.getClass(), p.parse(method, containingObject));
|
|
}
|
|
return results;
|
|
}
|
|
|
|
private ParserResults() {}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
public <T extends Object> T get(Class<? extends MethodParser> key) {
|
|
return (T) super.get(key);
|
|
}
|
|
|
|
}
|
|
} |