use of jadx.api.ICodeWriter in project jadx by skylot.
the class CheckRegions method getBlockInsnStr.
private static String getBlockInsnStr(MethodNode mth, IBlock block) {
ICodeWriter code = new SimpleCodeWriter();
code.incIndent();
code.newLine();
MethodGen mg = MethodGen.getFallbackMethodGen(mth);
InsnGen ig = new InsnGen(mg, true);
for (InsnNode insn : block.getInstructions()) {
try {
ig.makeInsn(insn, code);
} catch (CodegenException e) {
// ignore
}
}
code.newLine();
return code.getCodeStr();
}
use of jadx.api.ICodeWriter in project jadx by skylot.
the class MethodGen method addOverrideAnnotation.
private void addOverrideAnnotation(ICodeWriter code, MethodNode mth) {
MethodOverrideAttr overrideAttr = mth.get(AType.METHOD_OVERRIDE);
if (overrideAttr == null) {
return;
}
if (!overrideAttr.getBaseMethods().contains(mth)) {
code.startLine("@Override");
if (mth.checkCommentsLevel(CommentsLevel.INFO)) {
code.add(" // ");
code.add(Utils.listToString(overrideAttr.getOverrideList(), ", ", md -> md.getMethodInfo().getDeclClass().getAliasFullName()));
}
}
if (Consts.DEBUG) {
code.startLine("// related by override: ");
code.add(Utils.listToString(overrideAttr.getRelatedMthNodes(), ", ", m -> m.getParentClass().getFullName()));
}
}
use of jadx.api.ICodeWriter in project jadx by skylot.
the class JsonCodeGen method addMethods.
private void addMethods(ClassNode cls, JsonClass jsonCls, ClassGen classGen) {
jsonCls.setMethods(new ArrayList<>());
for (MethodNode mth : cls.getMethods()) {
if (mth.contains(AFlag.DONT_GENERATE)) {
continue;
}
JsonMethod jsonMth = new JsonMethod();
jsonMth.setName(mth.getName());
if (mth.getMethodInfo().hasAlias()) {
jsonMth.setAlias(mth.getAlias());
}
jsonMth.setSignature(mth.getMethodInfo().getShortId());
jsonMth.setReturnType(getTypeAlias(mth.getReturnType()));
jsonMth.setArguments(Utils.collectionMap(mth.getMethodInfo().getArgumentsTypes(), this::getTypeAlias));
MethodGen mthGen = new MethodGen(classGen, mth);
ICodeWriter cw = new AnnotatedCodeWriter();
mthGen.addDefinition(cw);
jsonMth.setDeclaration(cw.getCodeStr());
jsonMth.setAccessFlags(mth.getAccessFlags().rawValue());
jsonMth.setLines(fillMthCode(mth, mthGen));
jsonMth.setOffset("0x" + Long.toHexString(mth.getMethodCodeOffset()));
jsonCls.getMethods().add(jsonMth);
}
}
use of jadx.api.ICodeWriter in project jadx by skylot.
the class JsonCodeGen method addFields.
private void addFields(ClassNode cls, JsonClass jsonCls, ClassGen classGen) {
jsonCls.setFields(new ArrayList<>());
for (FieldNode field : cls.getFields()) {
if (field.contains(AFlag.DONT_GENERATE)) {
continue;
}
JsonField jsonField = new JsonField();
jsonField.setName(field.getName());
if (field.getFieldInfo().hasAlias()) {
jsonField.setAlias(field.getAlias());
}
ICodeWriter cw = new SimpleCodeWriter();
classGen.addField(cw, field);
jsonField.setDeclaration(cw.getCodeStr());
jsonField.setAccessFlags(field.getAccessFlags().rawValue());
jsonCls.getFields().add(jsonField);
}
}
use of jadx.api.ICodeWriter in project jadx by skylot.
the class ResXmlGen method makeResourcesXml.
public List<ResContainer> makeResourcesXml() {
Map<String, ICodeWriter> contMap = new HashMap<>();
for (ResourceEntry ri : resStorage.getResources()) {
if (SKIP_RES_TYPES.contains(ri.getTypeName())) {
continue;
}
String fn = getFileName(ri);
ICodeWriter cw = contMap.get(fn);
if (cw == null) {
cw = new SimpleCodeWriter();
cw.add("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
cw.startLine("<resources>");
cw.incIndent();
contMap.put(fn, cw);
}
addValue(cw, ri);
}
List<ResContainer> files = new ArrayList<>(contMap.size());
for (Map.Entry<String, ICodeWriter> entry : contMap.entrySet()) {
String fileName = entry.getKey();
ICodeWriter content = entry.getValue();
content.decIndent();
content.startLine("</resources>");
ICodeInfo codeInfo = content.finish();
files.add(ResContainer.textResource(fileName, codeInfo));
}
Collections.sort(files);
return files;
}
Aggregations