1 package com.sun.org.apache.bcel.internal.generic; 2 3 56 import com.sun.org.apache.bcel.internal.Constants; 57 58 64 public final class ArrayType extends ReferenceType { 65 private int dimensions; 66 private Type basic_type; 67 68 73 public ArrayType(byte type, int dimensions) { 74 this(BasicType.getType(type), dimensions); 75 } 76 77 82 public ArrayType(String class_name, int dimensions) { 83 this(new ObjectType(class_name), dimensions); 84 } 85 86 91 public ArrayType(Type type, int dimensions) { 92 super(Constants.T_ARRAY, "<dummy>"); 93 94 if((dimensions < 1) || (dimensions > Constants.MAX_BYTE)) 95 throw new ClassGenException("Invalid number of dimensions: " + dimensions); 96 97 switch(type.getType()) { 98 case Constants.T_ARRAY: 99 ArrayType array = (ArrayType)type; 100 this.dimensions = dimensions + array.dimensions; 101 basic_type = array.basic_type; 102 break; 103 104 case Constants.T_VOID: 105 throw new ClassGenException("Invalid type: void[]"); 106 107 default: this.dimensions = dimensions; 109 basic_type = type; 110 break; 111 } 112 113 StringBuffer buf = new StringBuffer (); 114 for(int i=0; i < this.dimensions; i++) 115 buf.append('['); 116 117 buf.append(basic_type.getSignature()); 118 119 signature = buf.toString(); 120 } 121 122 125 public Type getBasicType() { 126 return basic_type; 127 } 128 129 132 public Type getElementType() { 133 if(dimensions == 1) 134 return basic_type; 135 else 136 return new ArrayType(basic_type, dimensions - 1); 137 } 138 139 141 public int getDimensions() { return dimensions; } 142 143 145 public int hashcode() { return basic_type.hashCode() ^ dimensions; } 146 147 149 public boolean equals(Object type) { 150 if(type instanceof ArrayType) { 151 ArrayType array = (ArrayType)type; 152 return (array.dimensions == dimensions) && array.basic_type.equals(basic_type); 153 } else 154 return false; 155 } 156 } 157 | Popular Tags |