01: // Copyright (c) 1997, 2007 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.bytecode;
05:
06: import java.util.Vector;
07:
08: public class ArrayType extends ObjectType {
09: public Type elements;
10:
11: public ArrayType(Type elements) {
12: this (elements, elements.getName() + "[]");
13: }
14:
15: ArrayType(Type elements, String name) {
16: this _name = name;
17: setSignature("[" + elements.getSignature());
18: this .elements = elements;
19: }
20:
21: public Type getImplementationType() {
22: Type eltype = elements.getImplementationType();
23: return elements == eltype ? this : make(eltype);
24: }
25:
26: /** Name assumed to end with "[]". */
27: static ArrayType make(String name) {
28: Type elements = Type.getType(name.substring(0,
29: name.length() - 2));
30: ArrayType array_type = elements.array_type;
31: if (array_type == null) {
32: array_type = new ArrayType(elements, name);
33: elements.array_type = array_type;
34: }
35: return array_type;
36: }
37:
38: /** Find or create an ArrayType for the specified element type. */
39: public static ArrayType make(Type elements) {
40: ArrayType array_type = elements.array_type;
41: if (array_type == null) {
42: array_type = new ArrayType(elements, elements.getName()
43: + "[]");
44: elements.array_type = array_type;
45: }
46: return array_type;
47: }
48:
49: public Type getComponentType() {
50: return elements;
51: }
52:
53: public String getInternalName() {
54: return getSignature();
55: }
56:
57: public int getMethods(Filter filter, int searchSupers,
58: Vector result, String context) {
59: if (searchSupers > 0) {
60: int count = Type.pointer_type.getMethods(filter, 0, result,
61: null);
62: if (searchSupers > 1 && filter.select(Type.clone_method)) {
63: if (result != null)
64: result.addElement(Type.clone_method);
65: count++;
66: }
67: return count;
68: }
69: return 0;
70: }
71:
72: public int compare(Type other) {
73: if (other == nullType)
74: return 1;
75: if (other instanceof ArrayType)
76: return elements.compare(((ArrayType) other).elements);
77: else if (other.getName().equals("java.lang.Object")
78: || other == tostring_type)
79: return -1;
80: else
81: return -3;
82: }
83: }
|