提交 63c003a0 编写于 作者: S Skylot

core: fix generic types for local variables

上级 5557fd81
......@@ -7,6 +7,7 @@ import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.LiteralArg;
import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.instructions.args.TypedVar;
import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.MethodNode;
......@@ -88,8 +89,13 @@ public class PostTypeResolver {
case CHECK_CAST: {
ArgType castType = (ArgType) ((IndexInsnNode) insn).getIndex();
// workaround for compiler bug (see TestDuplicateCast)
insn.getResult().getTypedVar().forceSetType(castType);
TypedVar typedVar = insn.getResult().getTypedVar();
// don't override generic types of same base class
boolean skip = castType.isObject() && castType.getObject().equals(typedVar.getType().getObject());
if (!skip) {
// workaround for compiler bug (see TestDuplicateCast)
typedVar.forceSetType(castType);
}
return true;
}
......
package jadx.tests.internal.generics;
import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.Map;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
public class TestGenerics2 extends InternalJadxTest {
public static class TestCls {
private static class ItemReference<V> extends WeakReference<V> {
private Object id;
public ItemReference(V item, Object id, ReferenceQueue<? super V> queue) {
super(item, queue);
this.id = id;
}
}
public static class ItemReferences<V> {
private Map<Object, ItemReference<V>> items;
public V get(Object id) {
WeakReference<V> ref = this.items.get(id);
return (ref != null) ? ref.get() : null;
}
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
assertThat(code, containsString("public ItemReference(V item, Object id, ReferenceQueue<? super V> queue) {"));
assertThat(code, containsString("public V get(Object id) {"));
assertThat(code, containsString("WeakReference<V> ref = "));
assertThat(code, containsString("return (ref != null) ? ref.get() : null;"));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册