Search in sources :

Example 1 with SmaliCatchStatement

use of org.jf.smalidea.psi.impl.SmaliCatchStatement in project smali by JesusFreke.

the class SmalideaMethod method getImplementation.

@Nullable
@Override
public MethodImplementation getImplementation() {
    if (psiMethod instanceof SmaliMethod) {
        final SmaliMethod smaliMethod = (SmaliMethod) this.psiMethod;
        List<SmaliInstruction> instructions = smaliMethod.getInstructions();
        if (instructions.size() == 0) {
            return null;
        }
        // TODO: cache this?
        return new MethodImplementation() {

            @Override
            public int getRegisterCount() {
                return smaliMethod.getRegisterCount();
            }

            @Nonnull
            @Override
            public Iterable<? extends Instruction> getInstructions() {
                return Lists.transform(smaliMethod.getInstructions(), new Function<SmaliInstruction, Instruction>() {

                    @Override
                    public Instruction apply(SmaliInstruction smaliInstruction) {
                        return SmalideaInstruction.of(smaliInstruction);
                    }
                });
            }

            @Nonnull
            @Override
            public List<? extends TryBlock<? extends ExceptionHandler>> getTryBlocks() {
                return Lists.transform(smaliMethod.getCatchStatements(), new Function<SmaliCatchStatement, TryBlock<? extends ExceptionHandler>>() {

                    @Override
                    public TryBlock<? extends ExceptionHandler> apply(SmaliCatchStatement smaliCatchStatement) {
                        assert smaliCatchStatement != null;
                        return new SmalideaTryBlock(smaliCatchStatement);
                    }
                });
            }

            @Nonnull
            @Override
            public Iterable<? extends DebugItem> getDebugItems() {
                // TODO: implement this
                return ImmutableList.of();
            }
        };
    }
    return null;
}
Also used : SmaliMethod(org.jf.smalidea.psi.impl.SmaliMethod) SmaliCatchStatement(org.jf.smalidea.psi.impl.SmaliCatchStatement) SmaliInstruction(org.jf.smalidea.psi.impl.SmaliInstruction) Instruction(org.jf.dexlib2.iface.instruction.Instruction) SmaliInstruction(org.jf.smalidea.psi.impl.SmaliInstruction) SmalideaInstruction(org.jf.smalidea.dexlib.instruction.SmalideaInstruction) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Nullable (org.jetbrains.annotations.Nullable)1 Instruction (org.jf.dexlib2.iface.instruction.Instruction)1 SmalideaInstruction (org.jf.smalidea.dexlib.instruction.SmalideaInstruction)1 SmaliCatchStatement (org.jf.smalidea.psi.impl.SmaliCatchStatement)1 SmaliInstruction (org.jf.smalidea.psi.impl.SmaliInstruction)1 SmaliMethod (org.jf.smalidea.psi.impl.SmaliMethod)1