Skip to content

Commit

Permalink
支持 Map<K,?>.put(K,?) 泛型写法 "K:key", { "type": "?", "value": val };对 me…
Browse files Browse the repository at this point in the history
…thodArgs 新增简写 args
  • Loading branch information
TommyLemon committed Nov 25, 2023
1 parent 8de9bbf commit 742c579
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/java/unitauto/MethodUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ default List<Class<?>> loadClassList(String packageOrFileName, String className,
public static String KEY_TIME_DETAIL = "time:start|duration|end";
public static String KEY_CLASS_ARGS = "classArgs";
public static String KEY_METHOD_ARGS = "methodArgs";
public static String KEY_ARGS = "args";
public static String KEY_CALLBACK = "callback";
public static String KEY_GLOBAL = "global";

Expand Down Expand Up @@ -533,6 +534,15 @@ public static void invokeMethod(JSONObject req, Object instance, Listener<JSONOb
Object this_ = req.get(KEY_THIS);
List<Argument> clsArgs = getArgList(req, KEY_CLASS_ARGS);
List<Argument> methodArgs = getArgList(req, KEY_METHOD_ARGS);
List<Argument> args_ = getArgList(req, KEY_ARGS);

if (methodArgs != null && args_ != null) {
throw new UnsupportedOperationException(KEY_METHOD_ARGS + " 和 " + KEY_ARGS + " 不能都传,最多传一个!");
}

if (methodArgs == null) {
methodArgs = args_;
}

Class<?> clazz = getInvokeClass(pkgName, clsName);
if (clazz == null) {
Expand Down Expand Up @@ -752,10 +762,13 @@ public static List<Argument> getArgList(JSONObject req, String arrKey) {
JSONArray arr = req == null ? null : JSON.parseArray(req.getString(arrKey));

List<Argument> list = null;
if (arr != null && arr.isEmpty() == false) {
if (arr != null) {
list = new ArrayList<>();
for (Object item : arr) {
if (item instanceof Boolean || item instanceof Number || item instanceof Collection) {
if (item instanceof Boolean || item instanceof Number || item instanceof Collection
|| (item instanceof Map && ((Map<?, ?>) item).containsKey(KEY_VALUE) == false
&& ((Map<?, ?>) item).get(KEY_TYPE) instanceof String == false)
) {
list.add(new Argument(null, item));
}
else if (item instanceof String) {
Expand Down Expand Up @@ -2116,7 +2129,10 @@ public static Class<?> findClass(String packageOrFileName, String className, boo
int index = className.indexOf("<");
if (index >= 0) {
className = className.substring(0, index);
} else if ("?".equals(className) || (className.length() == 1 && StringUtil.isBigName(className))) {
return Object.class;
}

//这个方法保证在 jar 包里能正常执行
Class<?> clazz = Class.forName(isEmpty(packageOrFileName, true) ? className : packageOrFileName.replaceAll("/", ".") + "." + className);
if (clazz != null) {
Expand Down

0 comments on commit 742c579

Please sign in to comment.