01: /*
02: * ArrayClassInfo.java - part of the CodeAid plugin.
03: * Copyright (C) 1999 Jason Ginchereau
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * as published by the Free Software Foundation; either version 2
08: * of the License, or any later version.
09: *
10: * This program is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: */
19:
20: package org.acm.seguin.completer.info;
21:
22: import java.lang.reflect.Modifier;
23:
24: /**
25: * @see ClassInfo
26: *
27: * @author Jason Ginchereau
28: **/
29: public class ArrayClassInfo extends ClassInfo {
30: private int dimensions;
31: private ClassInfo arrayType;
32:
33: public ArrayClassInfo(ClassInfo arrayType, int dimensions) {
34: super (null, Modifier.PUBLIC, false, arrayType.getName(),
35: "java.lang.Object", new String[] {}, null, null);
36: this .dimensions = dimensions;
37: this .arrayType = arrayType;
38:
39: add(new FieldInfo(getFullName(), Modifier.PUBLIC, "int",
40: "length", null));
41: }
42:
43: /**
44: * Gets the fully-qualified name of the class.
45: **/
46: public String getFullName() {
47: String s = arrayType.getFullName();
48: for (int n = 0; n < dimensions; n++) {
49: s += "[]";
50: }
51: return s;
52: }
53:
54: public String getLine() {
55: return "class " + getFullName();
56: }
57:
58: public ClassInfo getArrayType() {
59: return arrayType;
60: }
61:
62: public int getDimensions() {
63: return dimensions;
64: }
65:
66: public int compareTo(MemberInfo mi) {
67: int nc = getName().compareTo(mi.getName());
68: if (nc != 0) {
69: return nc;
70: }
71:
72: if (mi instanceof ArrayClassInfo) {
73: if (dimensions < ((ArrayClassInfo) mi).dimensions) {
74: return -1;
75: } else if (dimensions > ((ArrayClassInfo) mi).dimensions) {
76: return 1;
77: } else {
78: return 0;
79: }
80: } else if (mi instanceof ClassInfo) {
81: return 1;
82: } else {
83: return -1;
84: }
85: }
86: }
|