Commit 2063fd07 authored by skylot's avatar skylot

Merge pull request #17 from NeoSpb/fix2

Fix2 by NeoSpb
parents 5a68d3be 128fe8a8
...@@ -129,8 +129,16 @@ public class InsnGen { ...@@ -129,8 +129,16 @@ public class InsnGen {
} }
private void instanceField(CodeWriter code, FieldInfo field, InsnArg arg) throws CodegenException { private void instanceField(CodeWriter code, FieldInfo field, InsnArg arg) throws CodegenException {
FieldNode fieldNode = mth.getParentClass().searchField(field); ClassNode pCls = mth.getParentClass();
if (fieldNode != null) { FieldNode fieldNode = pCls.searchField(field);
while ((fieldNode == null)
&& (pCls.getParentClass() != pCls) && (pCls.getParentClass() != null))
{
pCls = pCls.getParentClass();
fieldNode = pCls.searchField(field);
}
if (fieldNode != null) {
FieldReplaceAttr replace = fieldNode.get(AType.FIELD_REPLACE); FieldReplaceAttr replace = fieldNode.get(AType.FIELD_REPLACE);
if (replace != null) { if (replace != null) {
FieldInfo info = replace.getFieldInfo(); FieldInfo info = replace.getFieldInfo();
......
...@@ -377,10 +377,7 @@ public class ClassNode extends LineAttrNode implements ILoadable { ...@@ -377,10 +377,7 @@ public class ClassNode extends LineAttrNode implements ILoadable {
public MethodNode getDefaultConstructor() { public MethodNode getDefaultConstructor() {
for (MethodNode mth : methods) { for (MethodNode mth : methods) {
if (mth.getAccessFlags().isConstructor() if (mth.isDefaultConstructor()) {
&& mth.getMethodInfo().isConstructor()
&& (mth.getMethodInfo().getArgsCount() == 0
|| (mth.getArguments(false) != null && mth.getArguments(false).isEmpty()))) {
return mth; return mth;
} }
} }
......
...@@ -461,6 +461,31 @@ public class MethodNode extends LineAttrNode implements ILoadable { ...@@ -461,6 +461,31 @@ public class MethodNode extends LineAttrNode implements ILoadable {
} }
return false; return false;
} }
public boolean isDefaultConstructor() {
boolean result = false;
if (accFlags.isConstructor() && mthInfo.isConstructor()) {
int defaultArgCount = 0;
/** workaround for non-static inner class constructor, that has
* synthetic argument */
if ((parentClass != null) && parentClass.getClassInfo().isInner()) {
if (!parentClass.getAccessFlags().isStatic()) {
ClassNode outerCls = parentClass.getParentClass();
if ((argsList != null) && (argsList.size() >= 1)) {
if (argsList.get(0).getType().equals(outerCls.getClassInfo().getType())) {
defaultArgCount = 1;
}
}
}
}
result = (argsList == null) || (argsList.size() == defaultArgCount);
}
return result;
}
public int getRegsCount() { public int getRegsCount() {
return regsCount; return regsCount;
......
...@@ -76,6 +76,12 @@ public class ModVisitor extends AbstractVisitor { ...@@ -76,6 +76,12 @@ public class ModVisitor extends AbstractVisitor {
remove = true; remove = true;
} }
} }
// remove super() call in instance initializer
if (parentClass.isAnonymous() && mth.isDefaultConstructor() && co.isSuper()) {
remove = true;
}
if (remove) { if (remove) {
remover.add(insn); remover.add(insn);
} else { } else {
......
package jadx.samples;
public class TestInitializers extends AbstractTest {
private static String a;
private static int counter;
private A c_a;
public static class A {
public static String a;
static {
a = "a1";
}
public boolean z() {
return true;
}
}
public class B {
private int b;
private int bbb;
public B() {
if (c_a.z()) {
b = -1;
} else {
b = 1;
}
}
public B(int _b) {
b = _b;
}
public void setB(int _b) {
b = _b;
}
public int getB() {
return b;
}
public int getBBB() {
return bbb;
}
{
bbb = 123;
}
}
static {
a = "a0";
counter = 0;
}
{
c_a = new A();
}
@Override
public boolean testRun() throws Exception {
assertTrue(counter == 0);
assertTrue(a.equals("a0"));
assertTrue(A.a.equals("a1"));
B b1 = new B() {
{
TestInitializers.counter++;
setB(TestInitializers.counter);
}
};
assertTrue(b1.getB() == 1);
B b2 = new B() {
@SuppressWarnings("unused")
private int bb;
public int getB() {
return super.getB();
}
{
bb = 100;
}
};
assertTrue(b2.getB() == -1);
assertTrue((new B()).getB() == -1);
assertTrue(counter == 1);
B b3 = new B(3);
assertTrue((b3.getB() == 3) && (b3.getBBB() == 123));
return true;
}
public static void main(String[] args) throws Exception {
new TestInitializers().testRun();
}
}
package jadx.samples;
public class TestInner3 extends AbstractTest {
private String i0;
public class A {
protected String a;
public A() {
a="";
}
public String a() {
return "";
}
}
public class I0 {
private String i0;
private String i1;
public class I1 {
private String i0;
private String i1;
private String i2;
public I1() {
TestInner3.this.i0 = "i0";
I0.this.i0 = "i1";
I0.this.i1 = "i2";
i0 = "i0";
i1 = "i1";
i2 = "i2";
}
public String i() {
String result = TestInner3.this.i0 + I0.this.i0 + I0.this.i1 + i0 + i1 + i2;
A a = new A() {
public String a() {
TestInner3.this.i0 = "i1";
I0.this.i0 = "i2";
I0.this.i1 = "i3";
I1.this.i0 = "i1";
I1.this.i1 = "i2";
I1.this.i2 = "i3";
a = "a";
return TestInner3.this.i0 + I0.this.i0 + I0.this.i1 + I1.this.i0 + I1.this.i1 + I1.this.i2 + a;
}
};
return result + a.a();
}
}
public I0() {
TestInner3.this.i0 = "i-";
i0 = "i0";
i1 = "i1";
}
public String i() {
String result = TestInner3.this.i0 + i0 + i1;
return result + (new I1()).i();
}
}
@Override
public boolean testRun() throws Exception {
assertTrue((new I0()).i().equals("i-i0i1i0i1i2i0i1i2i1i2i3i1i2i3a"));
assertTrue(i0.equals("i1"));
return true;
}
public static void main(String[] args) throws Exception {
new TestInner2().testRun();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment