Search in sources :

Example 1 with AnnotationMethodParamsAttr

use of jadx.api.plugins.input.data.attributes.types.AnnotationMethodParamsAttr in project jadx by skylot.

the class MethodGen method addMethodArguments.

private void addMethodArguments(ICodeWriter code, List<RegisterArg> args) {
    AnnotationMethodParamsAttr paramsAnnotation = mth.get(JadxAttrType.ANNOTATION_MTH_PARAMETERS);
    int i = 0;
    Iterator<RegisterArg> it = args.iterator();
    while (it.hasNext()) {
        RegisterArg mthArg = it.next();
        SSAVar ssaVar = mthArg.getSVar();
        CodeVar var;
        if (ssaVar == null) {
            // abstract or interface methods
            var = CodeVar.fromMthArg(mthArg, classGen.isFallbackMode());
        } else {
            var = ssaVar.getCodeVar();
        }
        // add argument annotation
        if (paramsAnnotation != null) {
            annotationGen.addForParameter(code, paramsAnnotation, i);
        }
        if (var.isFinal()) {
            code.add("final ");
        }
        ArgType argType;
        ArgType varType = var.getType();
        if (varType == null || varType == ArgType.UNKNOWN) {
            // occur on decompilation errors
            argType = mthArg.getInitType();
        } else {
            argType = varType;
        }
        if (!it.hasNext() && mth.getAccessFlags().isVarArgs()) {
            // change last array argument to varargs
            if (argType.isArray()) {
                ArgType elType = argType.getArrayElement();
                classGen.useType(code, elType);
                code.add("...");
            } else {
                mth.addWarnComment("Last argument in varargs method is not array: " + var);
                classGen.useType(code, argType);
            }
        } else {
            classGen.useType(code, argType);
        }
        code.add(' ');
        String varName = nameGen.assignArg(var);
        if (code.isMetadataSupported() && ssaVar != null) /* for fallback mode */
        {
            code.attachDefinition(VarDeclareRef.get(mth, var));
        }
        code.add(varName);
        i++;
        if (it.hasNext()) {
            code.add(", ");
        }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) CodeVar(jadx.core.dex.instructions.args.CodeVar) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SSAVar(jadx.core.dex.instructions.args.SSAVar) AnnotationMethodParamsAttr(jadx.api.plugins.input.data.attributes.types.AnnotationMethodParamsAttr)

Aggregations

AnnotationMethodParamsAttr (jadx.api.plugins.input.data.attributes.types.AnnotationMethodParamsAttr)1 ArgType (jadx.core.dex.instructions.args.ArgType)1 CodeVar (jadx.core.dex.instructions.args.CodeVar)1 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)1 SSAVar (jadx.core.dex.instructions.args.SSAVar)1