FileDocCategorySizeDatePackage
ArrayType.javaAPI DocJava SE 6 API5456Tue Jun 10 00:22:18 BST 2008com.sun.org.apache.bcel.internal.generic

ArrayType

public final class ArrayType extends ReferenceType
Denotes array type, such as int[][]
version
$Id: ArrayType.java,v 1.1.2.1 2005/07/31 23:45:20 jeffsuttor Exp $
author
M. Dahm

Fields Summary
private int
dimensions
private Type
basic_type
Constructors Summary
public ArrayType(byte type, int dimensions)
Convenience constructor for array type, e.g. int[]

param
type array type, e.g. T_INT

    this(BasicType.getType(type), dimensions);
  
public ArrayType(String class_name, int dimensions)
Convenience constructor for reference array type, e.g. Object[]

param
class_name complete name of class (java.lang.String, e.g.)

    this(new ObjectType(class_name), dimensions);
  
public ArrayType(Type type, int dimensions)
Constructor for array of given type

param
type type of array (may be an array itself)

    super(Constants.T_ARRAY, "<dummy>");

    if((dimensions < 1) || (dimensions > Constants.MAX_BYTE))
      throw new ClassGenException("Invalid number of dimensions: " + dimensions);

    switch(type.getType()) {
    case Constants.T_ARRAY:
      ArrayType array = (ArrayType)type;
      this.dimensions = dimensions + array.dimensions;
      basic_type      = array.basic_type;
      break;
      
    case Constants.T_VOID:
      throw new ClassGenException("Invalid type: void[]");

    default: // Basic type or reference
      this.dimensions = dimensions;
      basic_type = type;
      break;
    }

    StringBuffer buf = new StringBuffer();
    for(int i=0; i < this.dimensions; i++)
      buf.append('[");

    buf.append(basic_type.getSignature());

    signature = buf.toString();
  
Methods Summary
public booleanequals(java.lang.Object type)

return
true if both type objects refer to the same array type.

    if(type instanceof ArrayType) {
      ArrayType array = (ArrayType)type;
      return (array.dimensions == dimensions) && array.basic_type.equals(basic_type);
    } else
      return false;
  
public com.sun.org.apache.bcel.internal.generic.TypegetBasicType()

return
basic type of array, i.e., for int[][][] the basic type is int

    return basic_type;
  
public intgetDimensions()

return
number of dimensions of array

 return dimensions; 
public com.sun.org.apache.bcel.internal.generic.TypegetElementType()

return
element type of array, i.e., for int[][][] the element type is int[][]

    if(dimensions == 1)
      return basic_type;
    else
      return new ArrayType(basic_type, dimensions - 1);
  
public inthashcode()

return
a hash code value for the object.

 return basic_type.hashCode() ^ dimensions;