Skip to content

Commit

Permalink
fix: don't add @OverRide for static methods (#976)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Sep 17, 2020
1 parent cfaa6ab commit 6428f29
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand All @@ -33,7 +34,7 @@ public boolean visit(ClassNode cls) throws JadxException {
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);
Expand All @@ -53,7 +54,9 @@ private List<IMethodDetails> collectOverrideMethods(RootNode root, List<ArgType>
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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");
}
}

0 comments on commit 6428f29

Please sign in to comment.