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);
}
}
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;
}
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();
}
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;
}
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());
}
Aggregations