001: package com.ibm.sigtest;
002:
003: import java.lang.reflect.Modifier;
004: import java.util.List;
005: import java.util.Vector;
006:
007: /**
008: * This class stores all the information needed to identify a method signature.
009: * @author Matthew J. Duftler (duftler@us.ibm.com)
010: */
011: public class MethodDesc extends MemberDesc {
012:
013: private String returnTypeName = null;
014:
015: private List paramTypeNames = new Vector();
016:
017: private List exceptionTypeNames = new Vector();
018:
019: public MethodDesc(String name, int modifiers,
020: String returnTypeName, List paramTypeNames,
021: List exceptionTypeNames) {
022: super (name, modifiers);
023:
024: this .returnTypeName = returnTypeName;
025: this .paramTypeNames = paramTypeNames;
026: this .exceptionTypeNames = exceptionTypeNames;
027: }
028:
029: public void setReturnTypeName(String returnTypeName) {
030: this .returnTypeName = returnTypeName;
031: }
032:
033: public String getReturnTypeName() {
034: return returnTypeName;
035: }
036:
037: public void setParameterTypeNames(List paramTypeNames) {
038: this .paramTypeNames = paramTypeNames;
039: }
040:
041: public List getParameterTypeNames() {
042: return paramTypeNames;
043: }
044:
045: public void setExceptionTypeNames(List exceptionTypeNames) {
046: this .exceptionTypeNames = exceptionTypeNames;
047: }
048:
049: public List getExceptionTypeNames() {
050: return exceptionTypeNames;
051: }
052:
053: public static MethodDesc parseMethodDesc(String methodDescStr) {
054: String[] tokens = SigTestUtils.tokenize(methodDescStr, " ");
055:
056: int modifiers = Integer.parseInt(tokens[0]);
057: String returnTypeName = null;
058: int offset = 0;
059:
060: if (!tokens[2].startsWith("(")) {
061: returnTypeName = tokens[1];
062: offset = 1;
063: }
064:
065: String methodName = tokens[1 + offset];
066: String parameterTypeNamesStr = tokens[2 + offset];
067:
068: parameterTypeNamesStr = parameterTypeNamesStr.substring(1,
069: parameterTypeNamesStr.length() - 1);
070:
071: List parameterTypeNames = SigTestUtils.stringToList(
072: parameterTypeNamesStr, ",");
073: List exceptionTypeNames;
074:
075: if (tokens.length > (3 + offset)) {
076: String exceptionTypeNamesStr = tokens[4 + offset];
077:
078: exceptionTypeNames = SigTestUtils.stringToList(
079: exceptionTypeNamesStr, ",");
080: } else {
081: exceptionTypeNames = new Vector();
082: }
083:
084: MethodDesc methodDesc = new MethodDesc(methodName, modifiers,
085: returnTypeName, parameterTypeNames, exceptionTypeNames);
086:
087: return methodDesc;
088: }
089:
090: public boolean equals(Object obj) {
091: if (obj == null) {
092: return false;
093: } else if (obj == this ) {
094: return true;
095: } else {
096: MethodDesc that = (MethodDesc) obj;
097:
098: if (!SigTestUtils.objectsEqual(name, that.name)) {
099: return false;
100: } else if (modifiers != that.modifiers) {
101: return false;
102: } else if (!SigTestUtils.objectsEqual(returnTypeName,
103: that.returnTypeName)) {
104: return false;
105: } else if (!SigTestUtils.objectsEqual(paramTypeNames,
106: that.paramTypeNames)) {
107: return false;
108: } else if (!SigTestUtils.collectionsMatch(
109: exceptionTypeNames, that.exceptionTypeNames)) {
110: return false;
111: } else {
112: return true;
113: }
114: }
115: }
116:
117: public int hashCode() {
118: return toString().hashCode();
119: }
120:
121: public String toString(boolean expandModifiers) {
122: return (expandModifiers ? Modifier.toString(modifiers)
123: : modifiers + "")
124: + " "
125: + (returnTypeName != null ? returnTypeName + " " : "")
126: + name
127: + " ("
128: + SigTestUtils.listToString(paramTypeNames)
129: + ")"
130: + (exceptionTypeNames.size() > 0 ? " throws "
131: + SigTestUtils.listToString(exceptionTypeNames)
132: : "");
133: }
134:
135: public String toString() {
136: return toString(false);
137: }
138: }
|