Search in sources :

Example 1 with MethodParameters

use of jadx.core.dex.attributes.annotations.MethodParameters 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 2 with MethodParameters

use of jadx.core.dex.attributes.annotations.MethodParameters in project jadx by skylot.

the class AnnotationsParser method parse.

public void parse(int offset) throws DecodeException {
    Section section = dex.openSection(offset);
    // TODO read as unsigned int
    int classAnnotationsOffset = section.readInt();
    int fieldsCount = section.readInt();
    int annotatedMethodsCount = section.readInt();
    int annotatedParametersCount = section.readInt();
    if (classAnnotationsOffset != 0) {
        cls.addAttr(readAnnotationSet(classAnnotationsOffset));
    }
    for (int i = 0; i < fieldsCount; i++) {
        FieldNode f = cls.searchFieldById(section.readInt());
        f.addAttr(readAnnotationSet(section.readInt()));
    }
    for (int i = 0; i < annotatedMethodsCount; i++) {
        MethodNode m = cls.searchMethodById(section.readInt());
        m.addAttr(readAnnotationSet(section.readInt()));
    }
    for (int i = 0; i < annotatedParametersCount; i++) {
        MethodNode mth = cls.searchMethodById(section.readInt());
        // read annotation ref list
        Section ss = dex.openSection(section.readInt());
        int size = ss.readInt();
        MethodParameters params = new MethodParameters(size);
        for (int j = 0; j < size; j++) {
            params.getParamList().add(readAnnotationSet(ss.readInt()));
        }
        mth.addAttr(params);
    }
}
Also used : FieldNode(jadx.core.dex.nodes.FieldNode) MethodNode(jadx.core.dex.nodes.MethodNode) MethodParameters(jadx.core.dex.attributes.annotations.MethodParameters) Section(com.android.dex.Dex.Section)

Aggregations

MethodParameters (jadx.core.dex.attributes.annotations.MethodParameters)2 Section (com.android.dex.Dex.Section)1 ArgType (jadx.core.dex.instructions.args.ArgType)1 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)1 SSAVar (jadx.core.dex.instructions.args.SSAVar)1 FieldNode (jadx.core.dex.nodes.FieldNode)1 MethodNode (jadx.core.dex.nodes.MethodNode)1