fix: don't add 'default' for static methods in interfaces

This commit is contained in:
Skylot
2020-11-21 15:31:50 +00:00
parent 6f9619126a
commit eada4b0fc3
2 changed files with 38 additions and 1 deletions
@@ -110,7 +110,7 @@ public class MethodGen {
if (Consts.DEBUG) {
code.add(mth.isVirtual() ? "/* virtual */ " : "/* direct */ ");
}
if (clsAccFlags.isInterface() && !mth.isNoCode()) {
if (clsAccFlags.isInterface() && !mth.isNoCode() && !mth.getAccessFlags().isStatic()) {
// add 'default' for method with code in interface
code.add("default ");
}
@@ -0,0 +1,37 @@
package jadx.tests.integration.others;
import org.junit.jupiter.api.Test;
import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
public class TestInterfaceDefaultMethod extends IntegrationTest {
public static class TestCls {
@SuppressWarnings("UnnecessaryInterfaceModifier")
public interface ITest {
void test1();
default void test2() {
}
static void test3() {
}
abstract void test4();
}
}
@Test
public void test() {
assertThat(getClassNode(TestCls.class))
.code()
.doesNotContain("static default")
.doesNotContain("abstract")
.containsOne("void test1();")
.containsOne("default void test2() {")
.containsOne("static void test3() {");
}
}