00001 package de.fub.bytecode.generic;
00002
00003
00004
00005
00006
00007
00008
00009 public final class ArrayType extends ReferenceType {
00010 private int dimensions;
00011 private Type basic_type;
00012
00013
00014
00015
00016
00017
00018 public ArrayType(byte type, int dimensions) {
00019 this(BasicType.getType(type), dimensions);
00020 }
00021
00022
00023
00024
00025
00026 public ArrayType(Type type, int dimensions) {
00027 super(T_ARRAY, "<dummy>");
00028
00029 if((dimensions < 1) || (dimensions > MAX_BYTE))
00030 throw new ClassGenException("Invalid number of dimensions: " + dimensions);
00031
00032 switch(type.getType()) {
00033 case T_ARRAY:
00034 ArrayType array = (ArrayType)type;
00035 this.dimensions = dimensions + array.dimensions;
00036 basic_type = array.basic_type;
00037 break;
00038
00039 case T_VOID:
00040 throw new ClassGenException("Invalid type: void[]");
00041
00042 default:
00043 this.dimensions = dimensions;
00044 basic_type = type;
00045 break;
00046 }
00047
00048 StringBuffer buf = new StringBuffer();
00049 for(int i=0; i < dimensions; i++)
00050 buf.append('[');
00051
00052 buf.append(basic_type.getSignature());
00053
00054 signature = buf.toString();
00055 }
00056
00057
00058
00059
00060
00061 public ArrayType(String class_name, int dimensions) {
00062 this(new ObjectType(class_name), dimensions);
00063 }
00064 public boolean equals(Object type) {
00065 if(type instanceof ArrayType) {
00066 ArrayType array = (ArrayType)type;
00067 return (array.dimensions == dimensions) && array.basic_type.equals(basic_type);
00068 }
00069 else
00070 return false;
00071 }
00072
00073
00074
00075 public Type getBasicType() {
00076 return basic_type;
00077 }
00078
00079
00080
00081 public int getDimensions() { return dimensions; }
00082
00083
00084
00085 public Type getElementType() {
00086 if(dimensions == 1)
00087 return basic_type;
00088 else
00089 return new ArrayType(basic_type, dimensions - 1);
00090 }
00091 }