Search in sources :

Example 1 with GenericInfoAttr

use of jadx.core.dex.attributes.nodes.GenericInfoAttr in project jadx by skylot.

the class GenericTypesVisitor method attachGenericTypesInfo.

private void attachGenericTypesInfo(MethodNode mth, ConstructorInsn insn) {
    try {
        RegisterArg resultArg = insn.getResult();
        if (resultArg == null) {
            return;
        }
        ArgType argType = resultArg.getSVar().getCodeVar().getType();
        if (argType == null || argType.getGenericTypes() == null) {
            return;
        }
        ClassNode cls = mth.root().resolveClass(insn.getClassType());
        if (cls != null && cls.getGenericTypeParameters().isEmpty()) {
            return;
        }
        insn.addAttr(new GenericInfoAttr(argType.getGenericTypes()));
    } catch (Exception e) {
        LOG.error("Failed to attach constructor generic info", e);
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ClassNode(jadx.core.dex.nodes.ClassNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) JadxException(jadx.core.utils.exceptions.JadxException) GenericInfoAttr(jadx.core.dex.attributes.nodes.GenericInfoAttr)

Example 2 with GenericInfoAttr

use of jadx.core.dex.attributes.nodes.GenericInfoAttr in project jadx by skylot.

the class InsnGen method makeConstructor.

private void makeConstructor(ConstructorInsn insn, ICodeWriter code) throws CodegenException {
    ClassNode cls = mth.root().resolveClass(insn.getClassType());
    if (cls != null && cls.isAnonymous() && !fallback) {
        cls.ensureProcessed();
        inlineAnonymousConstructor(code, cls, insn);
        mth.getParentClass().addInlinedClass(cls);
        return;
    }
    if (insn.isSelf()) {
        throw new JadxRuntimeException("Constructor 'self' invoke must be removed!");
    }
    MethodNode callMth = mth.root().resolveMethod(insn.getCallMth());
    if (insn.isSuper()) {
        code.attachAnnotation(callMth);
        code.add("super");
    } else if (insn.isThis()) {
        code.attachAnnotation(callMth);
        code.add("this");
    } else {
        code.add("new ");
        if (callMth == null || callMth.contains(AFlag.DONT_GENERATE)) {
            // use class reference if constructor method is missing (default constructor)
            code.attachAnnotation(mth.root().resolveClass(insn.getCallMth().getDeclClass()));
        } else {
            code.attachAnnotation(callMth);
        }
        mgen.getClassGen().addClsName(code, insn.getClassType());
        GenericInfoAttr genericInfoAttr = insn.get(AType.GENERIC_INFO);
        if (genericInfoAttr != null) {
            code.add('<');
            if (genericInfoAttr.isExplicit()) {
                boolean first = true;
                for (ArgType type : genericInfoAttr.getGenericTypes()) {
                    if (!first) {
                        code.add(',');
                    } else {
                        first = false;
                    }
                    mgen.getClassGen().useType(code, type);
                }
            }
            code.add('>');
        }
    }
    generateMethodArguments(code, insn, 0, callMth);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ClassNode(jadx.core.dex.nodes.ClassNode) ConstClassNode(jadx.core.dex.instructions.ConstClassNode) MethodNode(jadx.core.dex.nodes.MethodNode) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) GenericInfoAttr(jadx.core.dex.attributes.nodes.GenericInfoAttr)

Aggregations

GenericInfoAttr (jadx.core.dex.attributes.nodes.GenericInfoAttr)2 ArgType (jadx.core.dex.instructions.args.ArgType)2 ClassNode (jadx.core.dex.nodes.ClassNode)2 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)1 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)1 MethodNode (jadx.core.dex.nodes.MethodNode)1 JadxException (jadx.core.utils.exceptions.JadxException)1 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)1