-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ignore anonymous classes in enclosing node search (#1580)
- Loading branch information
Showing
15 changed files
with
180 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
jadx-core/src/main/java/jadx/api/metadata/annotations/NodeEnd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package jadx.api.metadata.annotations; | ||
|
||
import jadx.api.metadata.ICodeAnnotation; | ||
|
||
public class NodeEnd implements ICodeAnnotation { | ||
|
||
public static final NodeEnd VALUE = new NodeEnd(); | ||
|
||
private NodeEnd() { | ||
} | ||
|
||
@Override | ||
public AnnType getAnnType() { | ||
return AnnType.END; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "END"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
jadx-core/src/test/java/jadx/tests/integration/others/TestCodeMetadata2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package jadx.tests.integration.others; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.api.JavaClass; | ||
import jadx.api.JavaMethod; | ||
import jadx.api.metadata.ICodeMetadata; | ||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.core.dex.nodes.MethodNode; | ||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.api.JadxInternalAccess.convertClassNode; | ||
import static jadx.api.JadxInternalAccess.convertMethodNode; | ||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
public class TestCodeMetadata2 extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
@SuppressWarnings("Convert2Lambda") | ||
public Runnable test(boolean a) { | ||
if (a) { | ||
return new Runnable() { | ||
@Override | ||
public void run() { | ||
System.out.println("test"); | ||
} | ||
}; | ||
} | ||
System.out.println("another"); | ||
return empty(); | ||
} | ||
|
||
public static Runnable empty() { | ||
return new Runnable() { | ||
@Override | ||
public void run() { | ||
// empty | ||
} | ||
}; | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
ClassNode cls = getClassNode(TestCls.class); | ||
assertThat(cls).code().containsOne("return empty();"); | ||
|
||
MethodNode testMth = getMethod(cls, "test"); | ||
MethodNode emptyMth = getMethod(cls, "empty"); | ||
|
||
JavaClass javaClass = convertClassNode(jadxDecompiler, cls); | ||
JavaMethod emptyJavaMethod = convertMethodNode(jadxDecompiler, emptyMth); | ||
List<Integer> emptyUsePlaces = javaClass.getUsePlacesFor(javaClass.getCodeInfo(), emptyJavaMethod); | ||
assertThat(emptyUsePlaces).hasSize(1); | ||
int callUse = emptyUsePlaces.get(0); | ||
|
||
ICodeMetadata metadata = cls.getCode().getCodeMetadata(); | ||
assertThat(metadata.getNodeAt(callUse)).isSameAs(testMth); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.