Cutin/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactory.java
tueem 8d24604707
All checks were successful
Build / Gradle-Build (push) Successful in 1m36s
Publish / Gradle-Publish (push) Successful in 10s
Test / Gradle-Test (push) Successful in 12s
feat(factory): add utility method which does the "unchecked" cast
2025-04-15 11:06:00 +02:00

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);
}
}
}