Class PrepareForCodeGen

java.lang.Object
jadx.core.dex.visitors.AbstractVisitor
jadx.core.dex.visitors.PrepareForCodeGen
All Implemented Interfaces:
IDexTreeVisitor

public class PrepareForCodeGen extends AbstractVisitor
Prepare instructions for code generation pass, most of this modification breaks register dependencies, so this pass must be just before CodeGen.
  • Constructor Details

    • PrepareForCodeGen

      public PrepareForCodeGen()
  • Method Details

    • getName

      public String getName()
      Description copied from interface: IDexTreeVisitor
      Visitor short id
      Specified by:
      getName in interface IDexTreeVisitor
      Overrides:
      getName in class AbstractVisitor
    • visit

      public boolean visit(ClassNode cls) throws JadxException
      Description copied from interface: IDexTreeVisitor
      Visit class
      Specified by:
      visit in interface IDexTreeVisitor
      Overrides:
      visit in class AbstractVisitor
      Returns:
      false for disable child methods and inner classes traversal
      Throws:
      JadxException
    • visit

      public void visit(MethodNode mth) throws JadxException
      Description copied from interface: IDexTreeVisitor
      Visit method
      Specified by:
      visit in interface IDexTreeVisitor
      Overrides:
      visit in class AbstractVisitor
      Throws:
      JadxException
    • removeInstructions

      private static void removeInstructions(BlockNode block)
    • checkInline

      private static void checkInline(BlockNode block)
    • checkConstUsage

      private static void checkConstUsage(BlockNode block)
      Add explicit type for non int constants
    • forbidExplicitType

      private static boolean forbidExplicitType(InsnType type)
    • removeParenthesis

      private static void removeParenthesis(BlockNode block)
    • removeParenthesis

      private static void removeParenthesis(InsnNode insn)
      Remove parenthesis for wrapped insn in arith '+' or '-' ('(a + b) +c' => 'a + b + c')
    • removeParenthesis

      private static void removeParenthesis(IfCondition cond)
    • modifyArith

      private static void modifyArith(BlockNode block)
      Replace arithmetic operation with short form ('a = a + 2' => 'a += 2')
    • moveConstructorInConstructor

      private void moveConstructorInConstructor(MethodNode mth)
      Check that 'super' or 'this' call in constructor is a first instruction. Otherwise, move to the top and add a warning.
    • searchConstructorCall

      @Nullable private @Nullable ConstructorInsn searchConstructorCall(MethodNode mth)
    • setClassSourceLine

      private void setClassSourceLine(ClassNode cls)
      Use source line from top method
    • collectFieldsUsageInAnnotations

      private void collectFieldsUsageInAnnotations(ClassNode cls)
    • collectFieldsUsageInAnnotations

      private void collectFieldsUsageInAnnotations(MethodNode mth, AttrNode attrNode)
    • checkEncodedValue

      private void checkEncodedValue(MethodNode mth, EncodedValue encodedValue)
    • addNullCasts

      private void addNullCasts(MethodNode mth, BlockNode block)
    • verifyNullCast

      private void verifyNullCast(MethodNode mth, InsnArg arg)