Class NewArray

java.lang.Object
javassist.expr.Expr
javassist.expr.NewArray
All Implemented Interfaces:
Opcode

public class NewArray extends Expr
Array creation.

This class does not provide methods for obtaining the initial values of array elements.

  • Method Details

    • where

      public CtBehavior where()
      Returns the method or constructor containing the array creation represented by this object.
      Overrides:
      where in class Expr
    • getLineNumber

      public int getLineNumber()
      Returns the line number of the source line containing the array creation.
      Overrides:
      getLineNumber in class Expr
      Returns:
      -1 if this information is not available.
    • getFileName

      public String getFileName()
      Returns the source file containing the array creation.
      Overrides:
      getFileName in class Expr
      Returns:
      null if this information is not available.
    • mayThrow

      public CtClass[] mayThrow()
      Returns the list of exceptions that the expression may throw. This list includes both the exceptions that the try-catch statements including the expression can catch and the exceptions that the throws declaration allows the method to throw.
      Overrides:
      mayThrow in class Expr
    • getComponentType

      public CtClass getComponentType() throws NotFoundException
      Returns the type of array components. If the created array is a two-dimensional array of int, the type returned by this method is not int[] but int.
      Throws:
      NotFoundException
    • getDimension

      public int getDimension()
      Returns the dimension of the created array.
    • getCreatedDimensions

      public int getCreatedDimensions()
      Returns the number of dimensions of arrays to be created. If the opcode is multianewarray, this method returns the second operand. Otherwise, it returns 1.
    • replace

      public void replace(String statement) throws CannotCompileException
      Replaces the array creation with the bytecode derived from the given source text.

      $0 is available even if the called method is static. If the field access is writing, $_ is available but the value of $_ is ignored.

      Specified by:
      replace in class Expr
      Parameters:
      statement - a Java statement except try-catch.
      Throws:
      CannotCompileException