Search in sources :

Example 31 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class MethodGen method addMethodArguments.

private void addMethodArguments(CodeWriter argsCode, List<RegisterArg> args) {
    MethodParameters paramsAnnotation = mth.get(AType.ANNOTATION_MTH_PARAMETERS);
    int i = 0;
    for (Iterator<RegisterArg> it = args.iterator(); it.hasNext(); ) {
        RegisterArg arg = it.next();
        // add argument annotation
        if (paramsAnnotation != null) {
            annotationGen.addForParameter(argsCode, paramsAnnotation, i);
        }
        SSAVar argSVar = arg.getSVar();
        if (argSVar != null && argSVar.contains(AFlag.FINAL)) {
            argsCode.add("final ");
        }
        if (!it.hasNext() && mth.getAccessFlags().isVarArgs()) {
            // change last array argument to varargs
            ArgType type = arg.getType();
            if (type.isArray()) {
                ArgType elType = type.getArrayElement();
                classGen.useType(argsCode, elType);
                argsCode.add("...");
            } else {
                LOG.warn(ErrorsCounter.formatErrorMsg(mth, "Last argument in varargs method not array"));
                classGen.useType(argsCode, arg.getType());
            }
        } else {
            classGen.useType(argsCode, arg.getType());
        }
        argsCode.add(' ');
        argsCode.add(nameGen.assignArg(arg));
        i++;
        if (it.hasNext()) {
            argsCode.add(", ");
        }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SSAVar(jadx.core.dex.instructions.args.SSAVar) MethodParameters(jadx.core.dex.attributes.annotations.MethodParameters)

Example 32 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class ClassGen method useClass.

public void useClass(CodeWriter code, ArgType type) {
    useClass(code, ClassInfo.extCls(cls.dex(), type));
    ArgType[] generics = type.getGenericTypes();
    if (generics != null) {
        code.add('<');
        int len = generics.length;
        for (int i = 0; i < len; i++) {
            if (i != 0) {
                code.add(", ");
            }
            ArgType gt = generics[i];
            ArgType wt = gt.getWildcardType();
            if (wt != null) {
                code.add('?');
                int bounds = gt.getWildcardBounds();
                if (bounds != 0) {
                    code.add(bounds == -1 ? " super " : " extends ");
                    useType(code, wt);
                }
            } else {
                useType(code, gt);
            }
        }
        code.add('>');
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType)

Example 33 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class ClassGen method addClassDeclaration.

public void addClassDeclaration(CodeWriter clsCode) {
    AccessInfo af = cls.getAccessFlags();
    if (af.isInterface()) {
        af = af.remove(AccessFlags.ACC_ABSTRACT).remove(AccessFlags.ACC_STATIC);
    } else if (af.isEnum()) {
        af = af.remove(AccessFlags.ACC_FINAL).remove(AccessFlags.ACC_ABSTRACT).remove(AccessFlags.ACC_STATIC);
    }
    // 'static' and 'private' modifier not allowed for top classes (not inner)
    if (!cls.getAlias().isInner()) {
        af = af.remove(AccessFlags.ACC_STATIC).remove(AccessFlags.ACC_PRIVATE);
    }
    annotationGen.addForClass(clsCode);
    insertSourceFileInfo(clsCode, cls);
    insertRenameInfo(clsCode, cls);
    clsCode.startLine(af.makeString());
    if (af.isInterface()) {
        if (af.isAnnotation()) {
            clsCode.add('@');
        }
        clsCode.add("interface ");
    } else if (af.isEnum()) {
        clsCode.add("enum ");
    } else {
        clsCode.add("class ");
    }
    clsCode.attachDefinition(cls);
    clsCode.add(cls.getShortName());
    addGenericMap(clsCode, cls.getGenericMap());
    clsCode.add(' ');
    ArgType sup = cls.getSuperClass();
    if (sup != null && !sup.equals(ArgType.OBJECT) && !sup.getObject().equals(ArgType.ENUM.getObject())) {
        clsCode.add("extends ");
        useClass(clsCode, sup);
        clsCode.add(' ');
    }
    if (!cls.getInterfaces().isEmpty() && !af.isAnnotation()) {
        if (cls.getAccessFlags().isInterface()) {
            clsCode.add("extends ");
        } else {
            clsCode.add("implements ");
        }
        for (Iterator<ArgType> it = cls.getInterfaces().iterator(); it.hasNext(); ) {
            ArgType interf = it.next();
            useClass(clsCode, interf);
            if (it.hasNext()) {
                clsCode.add(", ");
            }
        }
        if (!cls.getInterfaces().isEmpty()) {
            clsCode.add(' ');
        }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) AccessInfo(jadx.core.dex.info.AccessInfo)

Example 34 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class ClassGen method addGenericMap.

public boolean addGenericMap(CodeWriter code, Map<ArgType, List<ArgType>> gmap) {
    if (gmap == null || gmap.isEmpty()) {
        return false;
    }
    code.add('<');
    int i = 0;
    for (Entry<ArgType, List<ArgType>> e : gmap.entrySet()) {
        ArgType type = e.getKey();
        List<ArgType> list = e.getValue();
        if (i != 0) {
            code.add(", ");
        }
        if (type.isGenericType()) {
            code.add(type.getObject());
        } else {
            useClass(code, type);
        }
        if (list != null && !list.isEmpty()) {
            code.add(" extends ");
            for (Iterator<ArgType> it = list.iterator(); it.hasNext(); ) {
                ArgType g = it.next();
                if (g.isGenericType()) {
                    code.add(g.getObject());
                } else {
                    useClass(code, g);
                }
                if (it.hasNext()) {
                    code.add(" & ");
                }
            }
        }
        i++;
    }
    code.add('>');
    return true;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ArrayList(java.util.ArrayList) List(java.util.List)

Example 35 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class ClsSet method makeParentsArray.

public static NClass[] makeParentsArray(ClassNode cls, Map<String, NClass> names) {
    List<NClass> parents = new ArrayList<NClass>(1 + cls.getInterfaces().size());
    ArgType superClass = cls.getSuperClass();
    if (superClass != null) {
        NClass c = getCls(superClass.getObject(), names);
        if (c != null) {
            parents.add(c);
        }
    }
    for (ArgType iface : cls.getInterfaces()) {
        NClass c = getCls(iface.getObject(), names);
        if (c != null) {
            parents.add(c);
        }
    }
    return parents.toArray(new NClass[parents.size()]);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ArrayList(java.util.ArrayList)

Aggregations

ArgType (jadx.core.dex.instructions.args.ArgType)48 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)12 InsnNode (jadx.core.dex.nodes.InsnNode)11 InsnArg (jadx.core.dex.instructions.args.InsnArg)9 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)8 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)6 SSAVar (jadx.core.dex.instructions.args.SSAVar)6 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)5 ArrayList (java.util.ArrayList)5 FieldNode (jadx.core.dex.nodes.FieldNode)4 MethodNode (jadx.core.dex.nodes.MethodNode)4 Annotation (jadx.core.dex.attributes.annotations.Annotation)3 FieldInfo (jadx.core.dex.info.FieldInfo)3 FilledNewArrayNode (jadx.core.dex.instructions.FilledNewArrayNode)3 InvokeNode (jadx.core.dex.instructions.InvokeNode)3 BlockNode (jadx.core.dex.nodes.BlockNode)3 ClassNode (jadx.core.dex.nodes.ClassNode)3 DexNode (jadx.core.dex.nodes.DexNode)3 List (java.util.List)3 MethodInfo (jadx.core.dex.info.MethodInfo)2