Search in sources :

Example 1 with ICodeComment

use of jadx.api.data.ICodeComment in project jadx by skylot.

the class TestCodeCommentsMultiline method test.

@Test
public void test() {
    printOffsets();
    String baseClsId = TestCls.class.getName();
    JadxNodeRef mthRef = new JadxNodeRef(RefType.METHOD, baseClsId, "test(Z)I");
    IJavaCodeRef insnRef = JadxCodeRef.forInsn(isJavaInput() ? 15 : 11);
    ICodeComment insnComment = new JadxCodeComment(mthRef, insnRef, "multi\nline\ncomment");
    JadxCodeData codeData = new JadxCodeData();
    codeData.setComments(Collections.singletonList(insnComment));
    getArgs().setCodeData(codeData);
    assertThat(getClassNode(TestCls.class)).code().containsOne("// multi").containsOne("// line").containsOne("// comment");
}
Also used : ICodeComment(jadx.api.data.ICodeComment) JadxCodeComment(jadx.api.data.impl.JadxCodeComment) IJavaCodeRef(jadx.api.data.IJavaCodeRef) JadxNodeRef(jadx.api.data.impl.JadxNodeRef) JadxCodeData(jadx.api.data.impl.JadxCodeData) Test(org.junit.jupiter.api.Test) IntegrationTest(jadx.tests.api.IntegrationTest)

Example 2 with ICodeComment

use of jadx.api.data.ICodeComment in project jadx by skylot.

the class CommentsIndex method search.

public Flowable<JNode> search(SearchSettings searchSettings) {
    List<ICodeComment> comments = project.getCodeData().getComments();
    if (comments == null || comments.isEmpty()) {
        return Flowable.empty();
    }
    LOG.debug("Total comments count: {}", comments.size());
    return Flowable.create(emitter -> {
        for (ICodeComment comment : comments) {
            JNode foundNode = isMatch(searchSettings, comment);
            if (foundNode != null) {
                emitter.onNext(foundNode);
            }
            if (emitter.isCancelled()) {
                return;
            }
        }
        emitter.onComplete();
    }, BackpressureStrategy.BUFFER);
}
Also used : ICodeComment(jadx.api.data.ICodeComment) JNode(jadx.gui.treemodel.JNode)

Example 3 with ICodeComment

use of jadx.api.data.ICodeComment in project jadx by skylot.

the class TestCodeComments method test.

@Test
public void test() {
    String baseClsId = TestCls.class.getName();
    ICodeComment clsComment = new JadxCodeComment(JadxNodeRef.forCls(baseClsId), "class comment");
    ICodeComment innerClsComment = new JadxCodeComment(JadxNodeRef.forCls(baseClsId + "$A"), "inner class comment");
    ICodeComment fldComment = new JadxCodeComment(new JadxNodeRef(RefType.FIELD, baseClsId, "intField:I"), "field comment");
    JadxNodeRef mthRef = new JadxNodeRef(RefType.METHOD, baseClsId, "test()I");
    ICodeComment mthComment = new JadxCodeComment(mthRef, "method comment");
    IJavaCodeRef insnRef = JadxCodeRef.forInsn(isJavaInput() ? 13 : 11);
    ICodeComment insnComment = new JadxCodeComment(mthRef, insnRef, "insn comment");
    JadxCodeData codeData = new JadxCodeData();
    getArgs().setCodeData(codeData);
    codeData.setComments(Arrays.asList(clsComment, innerClsComment, fldComment, mthComment, insnComment));
    ClassNode cls = getClassNode(TestCls.class);
    assertThat(cls).decompile().checkCodeOffsets().code().containsOne("// class comment").containsOne("// inner class comment").containsOne("// field comment").containsOne("// method comment").containsOne("System.out.println(\"comment\"); // insn comment");
    String code = cls.getCode().getCodeStr();
    assertThat(cls).reloadCode(this).isEqualTo(code);
    ICodeComment updInsnComment = new JadxCodeComment(mthRef, insnRef, "updated insn comment");
    codeData.setComments(Collections.singletonList(updInsnComment));
    jadxDecompiler.reloadCodeData();
    assertThat(cls).reloadCode(this).containsOne("System.out.println(\"comment\"); // updated insn comment").doesNotContain("class comment").containsOne(" comment");
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) ICodeComment(jadx.api.data.ICodeComment) JadxCodeComment(jadx.api.data.impl.JadxCodeComment) IJavaCodeRef(jadx.api.data.IJavaCodeRef) JadxNodeRef(jadx.api.data.impl.JadxNodeRef) JadxCodeData(jadx.api.data.impl.JadxCodeData) Test(org.junit.jupiter.api.Test) IntegrationTest(jadx.tests.api.IntegrationTest)

Example 4 with ICodeComment

use of jadx.api.data.ICodeComment in project jadx by skylot.

the class TestCodeCommentsOverride method test.

@Test
public void test() {
    String baseClsId = TestCls.class.getName();
    JadxNodeRef iMthRef = new JadxNodeRef(RefType.METHOD, baseClsId + "$I", "mth()V");
    ICodeComment iMthComment = new JadxCodeComment(iMthRef, "interface mth comment");
    JadxNodeRef mthRef = new JadxNodeRef(RefType.METHOD, baseClsId + "$A", "mth()V");
    ICodeComment mthComment = new JadxCodeComment(mthRef, "mth comment");
    JadxCodeData codeData = new JadxCodeData();
    codeData.setComments(Arrays.asList(iMthComment, mthComment));
    getArgs().setCodeData(codeData);
    ClassNode cls = getClassNode(TestCls.class);
    assertThat(cls).decompile().checkCodeOffsets().code().containsOne("@Override").containsOne("// " + iMthComment.getComment()).containsOne("// " + mthComment.getComment());
    assertThat(cls).reloadCode(this).containsOne("@Override").containsOne("// " + iMthComment.getComment()).containsOne("// " + mthComment.getComment());
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) ICodeComment(jadx.api.data.ICodeComment) JadxCodeComment(jadx.api.data.impl.JadxCodeComment) JadxNodeRef(jadx.api.data.impl.JadxNodeRef) JadxCodeData(jadx.api.data.impl.JadxCodeData) Test(org.junit.jupiter.api.Test) IntegrationTest(jadx.tests.api.IntegrationTest)

Example 5 with ICodeComment

use of jadx.api.data.ICodeComment in project jadx by skylot.

the class CommentDialog method show.

public static void show(CodeArea codeArea, ICodeComment blankComment) {
    ICodeComment existComment = searchForExistComment(codeArea, blankComment);
    Dialog dialog;
    if (existComment != null) {
        dialog = new CommentDialog(codeArea, existComment, true);
    } else {
        dialog = new CommentDialog(codeArea, blankComment, false);
    }
    dialog.setVisible(true);
}
Also used : ICodeComment(jadx.api.data.ICodeComment) JDialog(javax.swing.JDialog) Dialog(java.awt.Dialog)

Aggregations

ICodeComment (jadx.api.data.ICodeComment)11 JadxCodeData (jadx.api.data.impl.JadxCodeData)7 JadxCodeComment (jadx.api.data.impl.JadxCodeComment)6 JadxNodeRef (jadx.api.data.impl.JadxNodeRef)5 IntegrationTest (jadx.tests.api.IntegrationTest)5 Test (org.junit.jupiter.api.Test)5 IJavaCodeRef (jadx.api.data.IJavaCodeRef)4 ClassNode (jadx.core.dex.nodes.ClassNode)2 JadxProject (jadx.gui.settings.JadxProject)2 JNode (jadx.gui.treemodel.JNode)1 Dialog (java.awt.Dialog)1 ArrayList (java.util.ArrayList)1 JDialog (javax.swing.JDialog)1