1 17 package org.apache.bcel.generic; 18 19 import org.apache.bcel.Constants; 20 21 27 public final class ArrayType extends ReferenceType { 28 29 private int dimensions; 30 private Type basic_type; 31 32 33 38 public ArrayType(byte type, int dimensions) { 39 this(BasicType.getType(type), dimensions); 40 } 41 42 43 48 public ArrayType(String class_name, int dimensions) { 49 this(new ObjectType(class_name), dimensions); 50 } 51 52 53 58 public ArrayType(Type type, int dimensions) { 59 super(Constants.T_ARRAY, "<dummy>"); 60 if ((dimensions < 1) || (dimensions > Constants.MAX_BYTE)) { 61 throw new ClassGenException("Invalid number of dimensions: " + dimensions); 62 } 63 switch (type.getType()) { 64 case Constants.T_ARRAY: 65 ArrayType array = (ArrayType) type; 66 this.dimensions = dimensions + array.dimensions; 67 basic_type = array.basic_type; 68 break; 69 case Constants.T_VOID: 70 throw new ClassGenException("Invalid type: void[]"); 71 default: this.dimensions = dimensions; 73 basic_type = type; 74 break; 75 } 76 StringBuffer buf = new StringBuffer (); 77 for (int i = 0; i < this.dimensions; i++) { 78 buf.append('['); 79 } 80 buf.append(basic_type.getSignature()); 81 signature = buf.toString(); 82 } 83 84 85 88 public Type getBasicType() { 89 return basic_type; 90 } 91 92 93 96 public Type getElementType() { 97 if (dimensions == 1) { 98 return basic_type; 99 } 100 return new ArrayType(basic_type, dimensions - 1); 101 } 102 103 104 106 public int getDimensions() { 107 return dimensions; 108 } 109 110 111 113 public int hashCode() { 114 return basic_type.hashCode() ^ dimensions; 115 } 116 117 118 120 public boolean equals( Object _type ) { 121 if (_type instanceof ArrayType) { 122 ArrayType array = (ArrayType) _type; 123 return (array.dimensions == dimensions) && array.basic_type.equals(basic_type); 124 } 125 return false; 126 } 127 } 128 | Popular Tags |