001: /*
002: * ConstructorInfo.java - part of the CodeAid plugin.
003: * Copyright (C) 1999 Jason Ginchereau
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * as published by the Free Software Foundation; either version 2
008: * of the License, or any later version.
009: *
010: * This program is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU General Public License for more details.
014: *
015: * You should have received a copy of the GNU General Public License
016: * along with this program; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: */
019:
020: //package codeaid.info;
021: package org.acm.seguin.completer.info;
022:
023: import java.lang.reflect.Constructor;
024:
025: public final class ConstructorInfo extends MemberInfo {
026: private String[] parameterTypes;
027: private String[] parameterNames;
028: private String[] exceptionTypes;
029:
030: public ConstructorInfo(Constructor c) {
031: super (c);
032: Class[] pt = c.getParameterTypes();
033: parameterTypes = new String[pt.length];
034: for (int i = 0; i < pt.length; i++) {
035: parameterTypes[i] = pt[i].getName();
036: }
037: parameterNames = null;
038: Class[] et = c.getExceptionTypes();
039: exceptionTypes = new String[et.length];
040: for (int i = 0; i < et.length; i++) {
041: exceptionTypes[i] = et[i].getName();
042: }
043: }
044:
045: public ConstructorInfo(String declaringClass, int modifiers,
046: String name, String[] parameterTypes,
047: String[] parameterNames, String[] exceptionTypes,
048: String comment) {
049: super (declaringClass, modifiers, name, comment);
050: this .parameterTypes = parameterTypes;
051: this .parameterNames = parameterNames;
052: if (exceptionTypes == null) {
053: exceptionTypes = new String[] {};
054: }
055: this .exceptionTypes = exceptionTypes;
056: }
057:
058: public String getType() {
059: return getDeclaringClass();
060: }
061:
062: public String getLine() {
063: return modifiersToString(getModifiers())
064: + getName()
065: + MethodInfo.parametersToString(parameterTypes,
066: parameterNames, exceptionTypes);
067: }
068:
069: public String[] getParameterNames() {
070: return parameterNames;
071: }
072:
073: public String[] getParameterTypes() {
074: return parameterTypes;
075: }
076:
077: public String[] getExceptionTypes() {
078: return exceptionTypes;
079: }
080:
081: public int compareTo(MemberInfo mi) {
082: int nc = getName().compareTo(mi.getName());
083: if (nc != 0) {
084: return nc;
085: }
086:
087: if (mi instanceof ConstructorInfo) {
088: String[] opt = ((ConstructorInfo) mi).parameterTypes;
089: if (parameterTypes.length < opt.length) {
090: return -1;
091: } else if (parameterTypes.length > opt.length) {
092: return 1;
093: } else {
094: for (int i = 0; i < parameterTypes.length; i++) {
095: int tc = parameterTypes[i].compareTo(opt[i]);
096: if (tc != 0) {
097: return tc;
098: }
099: }
100: }
101: return 0;
102: } else if (mi instanceof MethodInfo) {
103: return -1;
104: } else {
105: return 1;
106: }
107: }
108: }
|