Skip to content

Commit

Permalink
fix: don't inline anonymous in self inner class (#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Aug 18, 2022
1 parent 894e0e6 commit ce5d8ee
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ private static MethodNode checkUsage(ClassNode cls) {
// exclude self usage
return null;
}
if (ctrUseCls.getTopParentClass().equals(cls)) {
// exclude usage inside inner classes
return null;
}
for (MethodNode mth : cls.getMethods()) {
if (mth == ctr) {
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package jadx.tests.integration.inner;

import org.junit.jupiter.api.Test;

import jadx.api.JadxInternalAccess;
import jadx.api.JavaClass;
import jadx.core.dex.attributes.AType;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;

import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;

public class TestAnonymousClass20 extends IntegrationTest {

@SuppressWarnings({ "unused", "checkstyle:TypeName", "Convert2Lambda", "Anonymous2MethodRef" })
public static class Test$Cls {
public Runnable test() {
return new Runnable() {
@Override
public void run() {
new Test$Cls();
}
};
}
}

@Test
public void test() {
ClassNode cls = getClassNode(Test$Cls.class);
assertThat(cls.get(AType.ANONYMOUS_CLASS)).isNull();

JavaClass javaClass = JadxInternalAccess.convertClassNode(jadxDecompiler, cls);
assertThat(javaClass.getTopParentClass()).isEqualTo(javaClass);

assertThat(cls)
.code()
.containsOne("new TestAnonymousClass20$Test$Cls();");
}
}

0 comments on commit ce5d8ee

Please sign in to comment.