提交 6428f293 编写于 作者: S Skylot

fix: don't add @Override for static methods (#976)

上级 cfaa6ab6
......@@ -9,6 +9,7 @@ import java.util.Objects;
import jadx.core.clsp.ClspClass;
import jadx.core.clsp.ClspMethod;
import jadx.core.dex.attributes.nodes.MethodOverrideAttr;
import jadx.core.dex.info.AccessInfo;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.IMethodDetails;
......@@ -33,7 +34,7 @@ public class OverrideMethodVisitor extends AbstractVisitor {
RootNode root = cls.root();
List<ArgType> superTypes = collectSuperTypes(cls);
for (MethodNode mth : cls.getMethods()) {
if (mth.isConstructor()) {
if (mth.isConstructor() || mth.getAccessFlags().isStatic()) {
continue;
}
String signature = mth.getMethodInfo().makeSignature(false);
......@@ -53,7 +54,9 @@ public class OverrideMethodVisitor extends AbstractVisitor {
ClassNode classNode = root.resolveClass(superType);
if (classNode != null) {
for (MethodNode mth : classNode.getMethods()) {
if (!mth.getAccessFlags().isPrivate()) {
AccessInfo accessFlags = mth.getAccessFlags();
if (!accessFlags.isPrivate()
&& !accessFlags.isStatic()) {
String mthShortId = mth.getMethodInfo().getShortId();
if (mthShortId.startsWith(signature)) {
overrideList.add(mth);
......
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 TestOverrideStaticMethod extends IntegrationTest {
public static class TestCls {
public static class BaseClass {
public static int a() {
return 1;
}
}
public static class MyClass extends BaseClass {
public static int a() {
return 2;
}
}
public void check() {
assertThat(BaseClass.a()).isEqualTo(1);
assertThat(MyClass.a()).isEqualTo(2);
}
}
@Test
public void test() {
assertThat(getClassNode(TestCls.class))
.code()
.doesNotContain("@Override");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册