Class CastScanner

All Implemented Interfaces:
TreeVisitor<Void,Void>

public class CastScanner extends CommonScanner
CastScanner stores information about the names and offsets of casts inside a method, and can also be used to scan the source tree and determine the index of a given cast, where the i^th index corresponds to the i^th cast, using 0-based indexing.
  • Method Details

    • indexOfCastTree

      public static int indexOfCastTree(TreePath origpath, Tree tree)
      Computes the index of the given cast tree amongst all cast trees inside its method, using 0-based indexing.
      Parameters:
      origpath - the path ending in the given cast tree
      tree - the cast tree to search for
      Returns:
      the index of the given cast tree
    • visitTypeCast

      public Void visitTypeCast(TypeCastTree node, Void p)
      Specified by:
      visitTypeCast in interface TreeVisitor<Void,Void>
      Overrides:
      visitTypeCast in class TreeScanner<Void,Void>
    • addCastToMethod

      public static void addCastToMethod(String methodName, Integer offset)
      Adds a cast bytecode offset to the current list of offsets for methodName. This method must be called with monotonically increasing offsets for any one method.
      Parameters:
      methodName - the name of the method
      offset - the offset to add
    • getMethodCastIndex

      public static Integer getMethodCastIndex(String methodName, Integer offset)
      Returns the index of the given offset within the list of offsets for the given method, using 0-based indexing, or returns a negative number if the offset is not one of the offsets in the method.
      Parameters:
      methodName - the name of the method
      offset - the offset of the instanceof check
      Returns:
      the index of the given offset, or a negative number if the given offset does not exists inside the method