fix(gui): use correct type for generic params in Xposed snippet (PR #2057)

* Fix: Resolved an issue with incorrectly generated xposedMethodSnippet when the parameter type is generic.
Add: Introduced xposedGenerateFieldSnippet.

* fix code format

* Fixed: Resolved the issue where Xposed code generation was incorrect when dealing with generic parameters and alias fields.

---------

Co-authored-by: skylot <118523+skylot@users.noreply.github.com>
This commit is contained in:
LanBaiCode
2023-12-12 01:14:10 +08:00
committed by GitHub
parent d5bf9f20a6
commit b6155afd32
@@ -101,11 +101,20 @@ public class XposedAction extends JNodeAction {
return String.format(xposedFormatStr, xposedMethod, rawClassName, methodName);
}
String params = mthArgs.stream()
.map(type -> (type.isGeneric() ? type.getObject() : type) + ".class, ")
.map(type -> fixTypeContent(type) + ".class, ")
.collect(Collectors.joining());
return String.format(xposedFormatStr, xposedMethod, rawClassName, methodName + params);
}
private String fixTypeContent(ArgType type) {
if (type.isGeneric()) {
return type.getObject();
} else if (type.isGenericType() && type.isObject() && type.isTypeKnown()) {
return "Object";
}
return type.toString();
}
private String generateClassSnippet(JClass jc) {
JavaClass javaClass = jc.getCls();
String rawClassName = javaClass.getRawName();
@@ -120,6 +129,6 @@ public class XposedAction extends JNodeAction {
String isStatic = javaField.getAccessFlags().isStatic() ? "Static" : "";
String type = PRIMITIVE_TYPE_MAPPING.getOrDefault(javaField.getFieldNode().getType().toString(), "Object");
String xposedMethod = "XposedHelpers.get" + isStatic + type + "Field";
return String.format("%s(/*runtimeObject*/, \"%s\");", xposedMethod, javaField.getName());
return String.format("%s(/*runtimeObject*/, \"%s\");", xposedMethod, javaField.getFieldNode().getFieldInfo().getName());
}
}