feat(parser): MethodParser rework
This commit is contained in:
parent
eccad71837
commit
e425989106
@ -1,5 +1,7 @@
|
|||||||
package net.tomatentum.cutin;
|
package net.tomatentum.cutin;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public interface MethodParser {
|
public interface MethodParser {
|
||||||
void parse();
|
Object parse(Method method, Object containingObject);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package net.tomatentum.cutin;
|
package net.tomatentum.cutin;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.List;
|
import java.util.HashMap;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import net.tomatentum.cutin.method.ReflectedMethod;
|
import net.tomatentum.cutin.method.ReflectedMethod;
|
||||||
|
|
||||||
@ -13,8 +14,22 @@ public interface ReflectedMethodFactory<I extends Object, C extends Object> {
|
|||||||
|
|
||||||
public interface Factory<I extends Object, C extends Object> {
|
public interface Factory<I extends Object, C extends Object> {
|
||||||
|
|
||||||
Optional<ReflectedMethod<I, C>> produce(Method method, Object containingObject);
|
Optional<ReflectedMethod<I, C>> produce(Method method, Object containingObject, ParserResults parserResults);
|
||||||
void addParser(ReflectedMethod<I, C> method, List<MethodParser> parser);
|
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() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,8 +2,10 @@ package net.tomatentum.cutin;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -50,13 +52,10 @@ public class ReflectedMethodFactoryImpl<I extends Object, C extends Object> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Optional<ReflectedMethod<I, C>> factoryProduce(Factory<I, C> factory, Method method, Object containingClass) {
|
private Optional<ReflectedMethod<I, C>> factoryProduce(Factory<I, C> factory, Method method, Object containingClass) {
|
||||||
List<MethodParser> parser = new ArrayList<>();
|
Set<MethodParser> parser = new HashSet<>();
|
||||||
Optional<ReflectedMethod<I, C>> m = factory.produce(method, containingClass);
|
factory.addParser(parser);
|
||||||
m.ifPresent(x -> {
|
ParserResults results = ParserResults.create(parser, method, containingClass);
|
||||||
factory.addParser(x, parser);
|
return factory.produce(method, containingClass, results);
|
||||||
parser.forEach(MethodParser::parse);
|
|
||||||
});
|
|
||||||
return m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user