Search in sources :

Example 1 with JsonClass

use of jadx.core.codegen.json.cls.JsonClass in project jadx by skylot.

the class JsonCodeGen method addInnerClasses.

private void addInnerClasses(ClassNode cls, JsonClass jsonCls, ClassGen classGen) {
    List<ClassNode> innerClasses = cls.getInnerClasses();
    if (innerClasses.isEmpty()) {
        return;
    }
    jsonCls.setInnerClasses(new ArrayList<>(innerClasses.size()));
    for (ClassNode innerCls : innerClasses) {
        if (innerCls.contains(AFlag.DONT_GENERATE)) {
            continue;
        }
        JsonClass innerJsonCls = processCls(innerCls, classGen);
        jsonCls.getInnerClasses().add(innerJsonCls);
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) JsonClass(jadx.core.codegen.json.cls.JsonClass)

Example 2 with JsonClass

use of jadx.core.codegen.json.cls.JsonClass in project jadx by skylot.

the class JsonCodeGen method processCls.

private JsonClass processCls(ClassNode cls, @Nullable ClassGen parentCodeGen) {
    ClassGen classGen;
    if (parentCodeGen == null) {
        classGen = new ClassGen(cls, args);
    } else {
        classGen = new ClassGen(cls, parentCodeGen);
    }
    ClassInfo classInfo = cls.getClassInfo();
    JsonClass jsonCls = new JsonClass();
    jsonCls.setPkg(classInfo.getAliasPkg());
    jsonCls.setDex(cls.getInputFileName());
    jsonCls.setName(classInfo.getFullName());
    if (classInfo.hasAlias()) {
        jsonCls.setAlias(classInfo.getAliasFullName());
    }
    jsonCls.setType(getClassTypeStr(cls));
    jsonCls.setAccessFlags(cls.getAccessFlags().rawValue());
    if (!Objects.equals(cls.getSuperClass(), ArgType.OBJECT)) {
        jsonCls.setSuperClass(getTypeAlias(cls.getSuperClass()));
    }
    if (!cls.getInterfaces().isEmpty()) {
        jsonCls.setInterfaces(Utils.collectionMap(cls.getInterfaces(), this::getTypeAlias));
    }
    ICodeWriter cw = new SimpleCodeWriter();
    CodeGenUtils.addErrorsAndComments(cw, cls);
    classGen.addClassDeclaration(cw);
    jsonCls.setDeclaration(cw.getCodeStr());
    addFields(cls, jsonCls, classGen);
    addMethods(cls, jsonCls, classGen);
    addInnerClasses(cls, jsonCls, classGen);
    if (!cls.getClassInfo().isInner()) {
        List<String> imports = Utils.collectionMap(classGen.getImports(), ClassInfo::getAliasFullName);
        Collections.sort(imports);
        jsonCls.setImports(imports);
    }
    return jsonCls;
}
Also used : SimpleCodeWriter(jadx.api.impl.SimpleCodeWriter) ClassGen(jadx.core.codegen.ClassGen) JsonClass(jadx.core.codegen.json.cls.JsonClass) ICodeWriter(jadx.api.ICodeWriter) ClassInfo(jadx.core.dex.info.ClassInfo)

Aggregations

JsonClass (jadx.core.codegen.json.cls.JsonClass)2 ICodeWriter (jadx.api.ICodeWriter)1 SimpleCodeWriter (jadx.api.impl.SimpleCodeWriter)1 ClassGen (jadx.core.codegen.ClassGen)1 ClassInfo (jadx.core.dex.info.ClassInfo)1 ClassNode (jadx.core.dex.nodes.ClassNode)1