Class DuplicateBranches

All Implemented Interfaces:
Detector, Priorities, org.apache.bcel.classfile.Visitor

public class DuplicateBranches extends PreorderVisitor implements Detector
  • Field Details

  • Constructor Details

    • DuplicateBranches

      public DuplicateBranches(BugReporter bugReporter)
  • Method Details

    • visitClassContext

      public void visitClassContext(ClassContext classContext)
      Description copied from interface: Detector
      Visit the ClassContext for a class which should be analyzed for instances of bug patterns.
      Specified by:
      visitClassContext in interface Detector
      Parameters:
      classContext - the ClassContext
    • visitMethod

      public void visitMethod(org.apache.bcel.classfile.Method method)
      Specified by:
      visitMethod in interface org.apache.bcel.classfile.Visitor
      Overrides:
      visitMethod in class BetterVisitor
    • findIfElseDuplicates

      private void findIfElseDuplicates(CFG cfg, org.apache.bcel.classfile.Method method, BasicBlock bb)
    • getDeepFirstInstruction

      private static org.apache.bcel.generic.InstructionHandle getDeepFirstInstruction(CFG cfg, BasicBlock bb)
      Like bb.getFirstInstruction() except that if null is returned it will follow the FALL_THROUGH_EDGE (if any)
    • findSwitchDuplicates

      private void findSwitchDuplicates(CFG cfg, org.apache.bcel.classfile.Method method, BasicBlock bb)
    • updateMap

      private void updateMap(HashMap<BigInteger,Collection<Integer>> map, int i, BigInteger clauseAsInt)
    • getCodeBytesAsBigInt

      private BigInteger getCodeBytesAsBigInt(org.apache.bcel.classfile.Method method, int[] switchPos, int i, int endPos)
    • getFinalTarget

      private static int getFinalTarget(CFG cfg, int myPos, Collection<org.apache.bcel.generic.InstructionHandle> prevs)
      determine the end position (exclusive) of the final case by looking at the gotos at the ends of the other cases
    • getCodeBytes

      private byte[] getCodeBytes(org.apache.bcel.classfile.Method m, int start, int end)
    • findThenFinish

      private org.apache.bcel.generic.InstructionHandle findThenFinish(CFG cfg, BasicBlock thenBB, int elsePos)
    • report

      public void report()
      Description copied from interface: Detector
      This method is called after all classes to be visited. It should be used by any detectors which accumulate information over all visited classes to generate results.
      Specified by:
      report in interface Detector