未验证 提交 b56fd4d2 编写于 作者: J Jan S 提交者: GitHub

chore: add inlined class name as comment (PR #865)

* chore: add inlined class name as comment
* chore: adapt unit test for inlined class name as comment
上级 45207471
......@@ -223,10 +223,25 @@ public class ClassGen {
}
public void addClassBody(CodeWriter clsCode) throws CodegenException {
addClassBody(clsCode, false);
}
/**
*
* @param clsCode
* @param printClassName allows to print the original class name as comment (e.g. for inlined
* classes)
* @throws CodegenException
*/
public void addClassBody(CodeWriter clsCode, boolean printClassName) throws CodegenException {
clsCode.add('{');
setBodyGenStarted(true);
clsDeclLine = clsCode.getLine();
clsCode.incIndent();
if (printClassName) {
clsCode.startLine();
clsCode.add("/* class " + cls.getFullName() + " */");
}
addFields(clsCode);
addInnerClsAndMethods(clsCode);
clsCode.decIndent();
......
......@@ -675,7 +675,7 @@ public class InsnGen {
MethodNode callMth = mth.dex().resolveMethod(insn.getCallMth());
generateMethodArguments(code, insn, 0, callMth);
code.add(' ');
new ClassGen(cls, mgen.getClassGen().getParentGen()).addClassBody(code);
new ClassGen(cls, mgen.getClassGen().getParentGen()).addClassBody(code, true);
}
private void makeInvoke(InvokeNode insn, CodeWriter code) throws CodegenException {
......
......@@ -22,6 +22,8 @@ public class TestAnonymousClass14 extends SmaliTest {
public void makeAnonymousCls() {
use(new Thread(this) {
/ * class inner.OuterCls.AnonymousClass1 * /
public void someMethod() {
}
});
......@@ -44,6 +46,7 @@ public class TestAnonymousClass14 extends SmaliTest {
public void test() {
ClassNode clsNode = getClassNodeFromSmaliFiles("inner", "TestAnonymousClass14", "OuterCls");
String code = clsNode.getCode().toString();
code = code.replaceAll("/\\*.*?\\*/", ""); // remove block comments
assertThat(code, not(containsString("AnonymousClass1")));
assertThat(code, not(containsString("synthetic")));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册