java.lang.Object
org.matwoess.jsourceprofiler.tool.model.Block
All Implemented Interfaces:
Serializable, Component

public class Block extends Object implements Serializable, Component
This class is used to store information about a code block. It is the most important class of the model package and used for correct instrumentation and report generation.
See Also:
  • Field Details

    • id

      public int id
    • clazz

      public JClass clazz
    • method

      public Method method
    • parentBlock

      public Block parentBlock
    • beg

      public CodePosition beg
    • end

      public CodePosition end
    • blockType

      public BlockType blockType
    • isSingleStatement

      public boolean isSingleStatement
    • innerBlocks

      public final List<Block> innerBlocks
      The list of nested blocks for this block. Empty by default.
    • controlBreak

      public ControlBreak controlBreak
      The control flow break of this block. Null if this block is not ending with one.
    • labels

      public final List<String> labels
      The labels associated with this block. Empty by default.
    • codeRegions

      public final List<CodeRegion> codeRegions
      The code regions of this block. Should never be empty as long as BlockType.hasCounter() is true.
    • incInsertOffset

      public int incInsertOffset
      The offset for inserting the block's counter-statement. Important for constructor blocks.
    • hits

      public transient long hits
      The number of times this block was hit during execution.

      This information is added from the counts.dat file before report generation.

    • innerControlBreaks

      public final transient List<Block> innerControlBreaks
      The list of inner blocks that contain a control break.

      Used to determine minus blocks for new code regions.

  • Constructor Details

    • Block

      public Block(BlockType type)
      Creates a new Block with the given type.
      Parameters:
      type - the type of the block (one of BlockType)
  • Method Details

    • setParentMethod

      public void setParentMethod(Method method)
      Registers the parent method object for this block.

      If the block is a method block, it also registers this block as the method's method block.

      Parameters:
      method - the parent method object
    • setParentClass

      public void setParentClass(JClass clazz)
      Registers the parent class object for this block.

      Also adds this block to the class' class blocks if it is not a method.

      Parameters:
      clazz - the parent class object
    • setParentBlock

      public void setParentBlock(Block block)
      Registers the parent block object for this block.

      Also adds this block to the parent block's inner blocks.

      Parameters:
      block - the parent block object
    • registerInnerControlBreak

      public void registerInnerControlBreak(Block controlBreakBlock)
      Add the given block to the list of inner control breaks.
      Parameters:
      controlBreakBlock - the block containing the control break
    • addCodeRegion

      public void addCodeRegion(CodeRegion region)
      Insert the given region into the list of code regions.
      Parameters:
      region - the region to add
    • getInnerBlocksRecursive

      public List<Block> getInnerBlocksRecursive()
      Returns the list of all inner blocks, below and excluding this one, recursively.
      Returns:
      the list of all inner blocks
    • hasNoBraces

      public boolean hasNoBraces()
      Returns whether this block has no curly braces surrounding it.
      Returns:
      whether it is a single statement or the block type has no braces
    • isSwitchStatementCase

      public boolean isSwitchStatementCase()
      Returns whether this block is a switch statement case.

      True if the block is a switch case and its parent block is a switch statement.

      Returns:
      whether this block is a switch statement case
    • isSwitchExpressionCase

      public boolean isSwitchExpressionCase()
      Returns whether this block is a switch expression case.

      True if the block is a switch case and its parent block is a switch expression.

      Returns:
      whether this block is a switch expression case
    • getIncInsertPos

      public int getIncInsertPos()
      Returns the position where the increment statement should be inserted.
      Returns:
      the block begin position plus the increment insert offset
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object