Search in sources :

Example 1 with CaseInfo

use of jadx.core.dex.regions.SwitchRegion.CaseInfo in project jadx by skylot.

the class RegionGen method makeSwitch.

public void makeSwitch(SwitchRegion sw, ICodeWriter code) throws CodegenException {
    SwitchInsn insn = (SwitchInsn) BlockUtils.getLastInsn(sw.getHeader());
    Objects.requireNonNull(insn, "Switch insn not found in header");
    InsnArg arg = insn.getArg(0);
    code.startLine("switch (");
    addArg(code, arg, false);
    code.add(") {");
    InsnCodeOffset.attach(code, insn);
    CodeGenUtils.addCodeComments(code, mth, insn);
    code.incIndent();
    for (CaseInfo caseInfo : sw.getCases()) {
        List<Object> keys = caseInfo.getKeys();
        IContainer c = caseInfo.getContainer();
        for (Object k : keys) {
            if (k == SwitchRegion.DEFAULT_CASE_KEY) {
                code.startLine("default:");
            } else {
                code.startLine("case ");
                addCaseKey(code, arg, k);
                code.add(':');
            }
        }
        makeRegionIndent(code, c);
    }
    code.decIndent();
    code.startLine('}');
}
Also used : CaseInfo(jadx.core.dex.regions.SwitchRegion.CaseInfo) InsnArg(jadx.core.dex.instructions.args.InsnArg) IContainer(jadx.core.dex.nodes.IContainer) SwitchInsn(jadx.core.dex.instructions.SwitchInsn)

Aggregations

SwitchInsn (jadx.core.dex.instructions.SwitchInsn)1 InsnArg (jadx.core.dex.instructions.args.InsnArg)1 IContainer (jadx.core.dex.nodes.IContainer)1 CaseInfo (jadx.core.dex.regions.SwitchRegion.CaseInfo)1