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