1 19 20 package org.netbeans.modules.javacore.parser; 21 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.OutputStream ; 25 import java.util.Arrays ; 26 import org.netbeans.mdr.storagemodel.StorableBaseObject; 27 import org.netbeans.mdr.util.IOUtils; 28 29 public class ArrayRef extends TypeRef { 30 public final PrimitiveTypeRef parent; 31 public final int dimCount; 32 33 private int hashCode; 34 35 public static Object read(InputStream stream, StorableBaseObject storable) throws IOException { 36 return new ArrayRef((PrimitiveTypeRef) IOUtils.read(stream, storable), IOUtils.readInt(stream)); 37 } 38 39 public void write(OutputStream outputStream, StorableBaseObject storable) throws IOException { 40 IOUtils.write(outputStream, parent, storable); 41 IOUtils.writeInt(outputStream, dimCount); 42 } 43 44 public ArrayRef(PrimitiveTypeRef parent, int dimCount) { 45 this.parent = parent; 46 this.dimCount = dimCount; 47 } 48 49 public boolean equals(Object typeRef) { 50 ArrayRef ref; 51 52 if (this==typeRef) 53 return true; 54 if (!(typeRef instanceof ArrayRef)) 55 return false; 56 ref=(ArrayRef)typeRef; 57 if (!parent.equals(ref.parent)) 58 return false; 59 return dimCount==ref.dimCount; 60 } 61 62 String getName() { 63 char d[]=new char[dimCount]; 64 65 Arrays.fill(d,'['); 66 return new String (d).concat(parent.getName()); 67 } 68 69 public int hashCode() { 70 if (hashCode==0) { 71 hashCode=parent.hashCode()^dimCount; 72 } 73 return hashCode; 74 } 75 } 76 | Popular Tags |