KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > bytecode > ArrayType


1 // Copyright (c) 1997 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.bytecode;
5
6 public class ArrayType extends ObjectType
7 {
8   public Type elements;
9
10   public ArrayType (Type elements)
11   {
12     this(elements, elements.getName() + "[]");
13   }
14
15   ArrayType (Type elements, String JavaDoc name)
16   {
17     this_name = name;
18     setSignature("[" + elements.getSignature());
19     this.elements = elements;
20   }
21
22   public Type getImplementationType()
23   {
24     Type eltype = elements.getImplementationType();
25     return elements == eltype ? this : make(eltype);
26   }
27
28   /** Name assumed to end with "[]". */
29   static ArrayType make(String JavaDoc name)
30   {
31     Type elements = Type.getType(name.substring(0, name.length()-2));
32     ArrayType array_type = elements.array_type;
33     if (array_type == null)
34       {
35     array_type = new ArrayType(elements, name);
36     elements.array_type = array_type;
37       }
38     return array_type;
39   }
40
41   /** Find or create an ArrayType for the specified element type. */
42   public static ArrayType make(Type elements)
43   {
44     ArrayType array_type = elements.array_type;
45     if (array_type == null)
46       {
47     array_type = new ArrayType(elements, elements.getName() + "[]");
48     elements.array_type = array_type;
49       }
50     return array_type;
51   }
52
53   public Type getComponentType() { return elements; }
54
55   public String JavaDoc getInternalName() { return getSignature(); }
56
57   public int compare(Type other)
58   {
59     if (other == nullType)
60       return 1;
61     if (other instanceof ArrayType)
62       return elements.compare(((ArrayType) other).elements);
63     else if (other.getName().equals("java.lang.Object")
64          || other == tostring_type)
65       return -1;
66     else
67       return -3;
68   }
69 }
70
Popular Tags