Search in sources :

Example 6 with ICodeComment

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

the class CommentDialog method updateCommentsData.

private static void updateCommentsData(CodeArea codeArea, Consumer<List<ICodeComment>> updater) {
    try {
        JadxProject project = codeArea.getProject();
        JadxCodeData codeData = project.getCodeData();
        if (codeData == null) {
            codeData = new JadxCodeData();
        }
        List<ICodeComment> list = new ArrayList<>(codeData.getComments());
        updater.accept(list);
        Collections.sort(list);
        codeData.setComments(list);
        project.setCodeData(codeData);
        codeArea.getMainWindow().getWrapper().getDecompiler().reloadCodeData();
    } catch (Exception e) {
        LOG.error("Comment action failed", e);
    }
    try {
        // refresh code
        codeArea.refreshClass();
    } catch (Exception e) {
        LOG.error("Failed to reload code", e);
    }
}
Also used : ICodeComment(jadx.api.data.ICodeComment) ArrayList(java.util.ArrayList) JadxProject(jadx.gui.settings.JadxProject) JadxCodeData(jadx.api.data.impl.JadxCodeData)

Example 7 with ICodeComment

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

the class CommentDialog method searchForExistComment.

private static ICodeComment searchForExistComment(CodeArea codeArea, ICodeComment blankComment) {
    try {
        JadxProject project = codeArea.getProject();
        JadxCodeData codeData = project.getCodeData();
        if (codeData == null || codeData.getComments().isEmpty()) {
            return null;
        }
        for (ICodeComment comment : codeData.getComments()) {
            if (Objects.equals(comment.getNodeRef(), blankComment.getNodeRef()) && Objects.equals(comment.getCodeRef(), blankComment.getCodeRef())) {
                return comment;
            }
        }
    } catch (Exception e) {
        LOG.error("Error searching for exists comment", e);
    }
    return null;
}
Also used : ICodeComment(jadx.api.data.ICodeComment) JadxProject(jadx.gui.settings.JadxProject) JadxCodeData(jadx.api.data.impl.JadxCodeData)

Example 8 with ICodeComment

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

the class CommentDialog method apply.

private void apply() {
    String newCommentStr = commentArea.getText().trim();
    if (newCommentStr.isEmpty()) {
        if (updateComment) {
            remove();
        } else {
            cancel();
        }
        return;
    }
    ICodeComment newComment = new JadxCodeComment(comment.getNodeRef(), comment.getCodeRef(), newCommentStr);
    if (updateComment) {
        updateCommentsData(codeArea, list -> {
            list.remove(comment);
            list.add(newComment);
        });
    } else {
        updateCommentsData(codeArea, list -> list.add(newComment));
    }
    dispose();
}
Also used : ICodeComment(jadx.api.data.ICodeComment) JadxCodeComment(jadx.api.data.impl.JadxCodeComment)

Example 9 with ICodeComment

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

the class CommentAction method popupMenuWillBecomeVisible.

@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    ICodeComment codeComment = getCommentRef(getMouseLine());
    setEnabled(codeComment != null);
    this.actionComment = codeComment;
}
Also used : ICodeComment(jadx.api.data.ICodeComment)

Example 10 with ICodeComment

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

the class TestCodeComments2a 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() ? 22 : 18);
    ICodeComment insnComment = new JadxCodeComment(mthRef, insnRef, "return comment");
    IJavaCodeRef insnRef2 = JadxCodeRef.forInsn(isJavaInput() ? 27 : 19);
    ICodeComment insnComment2 = new JadxCodeComment(mthRef, insnRef2, "another return comment");
    JadxCodeData codeData = new JadxCodeData();
    codeData.setComments(Arrays.asList(insnComment, insnComment2));
    getArgs().setCodeData(codeData);
    assertThat(getClassNode(TestCls.class)).decompile().checkCodeOffsets().code().containsOne("// " + insnComment.getComment()).containsOne("// " + insnComment2.getComment());
}
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)

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