use of jadx.api.data.impl.JadxCodeData 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.impl.JadxCodeData 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.impl.JadxCodeData 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.impl.JadxCodeData 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.impl.JadxCodeData 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;
}
Aggregations