From e4259891069369a167b3a4914fe22709f6f14510 Mon Sep 17 00:00:00 2001 From: Tueem Date: Mon, 14 Apr 2025 19:01:01 +0200 Subject: [PATCH] feat(parser): MethodParser rework --- .../net/tomatentum/cutin/MethodParser.java | 4 +++- .../cutin/ReflectedMethodFactory.java | 21 ++++++++++++++++--- .../cutin/ReflectedMethodFactoryImpl.java | 13 ++++++------ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/src/main/java/net/tomatentum/cutin/MethodParser.java b/lib/src/main/java/net/tomatentum/cutin/MethodParser.java index fc18a8d..ac4aa7a 100644 --- a/lib/src/main/java/net/tomatentum/cutin/MethodParser.java +++ b/lib/src/main/java/net/tomatentum/cutin/MethodParser.java @@ -1,5 +1,7 @@ package net.tomatentum.cutin; +import java.lang.reflect.Method; + public interface MethodParser { - void parse(); + Object parse(Method method, Object containingObject); } diff --git a/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactory.java b/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactory.java index 28ca15a..8432b54 100644 --- a/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactory.java +++ b/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactory.java @@ -1,8 +1,9 @@ package net.tomatentum.cutin; import java.lang.reflect.Method; -import java.util.List; +import java.util.HashMap; import java.util.Optional; +import java.util.Set; import net.tomatentum.cutin.method.ReflectedMethod; @@ -13,8 +14,22 @@ public interface ReflectedMethodFactory { public interface Factory { - Optional> produce(Method method, Object containingObject); - void addParser(ReflectedMethod method, List parser); + Optional> produce(Method method, Object containingObject, ParserResults parserResults); + void addParser(Set parser); + + } + + public static class ParserResults extends HashMap, Object> { + + public static ParserResults create(Set 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() {} } } \ No newline at end of file diff --git a/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactoryImpl.java b/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactoryImpl.java index fab8f54..f2f6d7f 100644 --- a/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactoryImpl.java +++ b/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactoryImpl.java @@ -2,8 +2,10 @@ package net.tomatentum.cutin; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Optional; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,13 +52,10 @@ public class ReflectedMethodFactoryImpl impl } private Optional> factoryProduce(Factory factory, Method method, Object containingClass) { - List parser = new ArrayList<>(); - Optional> m = factory.produce(method, containingClass); - m.ifPresent(x -> { - factory.addParser(x, parser); - parser.forEach(MethodParser::parse); - }); - return m; + Set parser = new HashSet<>(); + factory.addParser(parser); + ParserResults results = ParserResults.create(parser, method, containingClass); + return factory.produce(method, containingClass, results); } }