1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler.util; 21 22 import java.util.Vector ; 23 24 28 public final class MethodType extends Type { 29 private final Type _resultType; 30 private final Vector _argsType; 31 32 public MethodType(Type resultType) { 33 _argsType = null; 34 _resultType = resultType; 35 } 36 37 public MethodType(Type resultType, Type arg1) { 38 if (arg1 != Type.Void) { 39 _argsType = new Vector (); 40 _argsType.addElement(arg1); 41 } 42 else { 43 _argsType = null; 44 } 45 _resultType = resultType; 46 } 47 48 public MethodType(Type resultType, Type arg1, Type arg2) { 49 _argsType = new Vector (2); 50 _argsType.addElement(arg1); 51 _argsType.addElement(arg2); 52 _resultType = resultType; 53 } 54 55 public MethodType(Type resultType, Type arg1, Type arg2, Type arg3) { 56 _argsType = new Vector (3); 57 _argsType.addElement(arg1); 58 _argsType.addElement(arg2); 59 _argsType.addElement(arg3); 60 _resultType = resultType; 61 } 62 63 public MethodType(Type resultType, Vector argsType) { 64 _resultType = resultType; 65 _argsType = argsType.size() > 0 ? argsType : null; 66 } 67 68 public String toString() { 69 StringBuffer result = new StringBuffer ("method{"); 70 if (_argsType != null) { 71 final int count = _argsType.size(); 72 for (int i=0; i<count; i++) { 73 result.append(_argsType.elementAt(i)); 74 if (i != (count-1)) result.append(','); 75 } 76 } 77 else { 78 result.append("void"); 79 } 80 result.append('}'); 81 return result.toString(); 82 } 83 84 public String toSignature() { 85 return toSignature(""); 86 } 87 88 92 public String toSignature(String lastArgSig) { 93 final StringBuffer buffer = new StringBuffer (); 94 buffer.append('('); 95 if (_argsType != null) { 96 final int n = _argsType.size(); 97 for (int i = 0; i < n; i++) { 98 buffer.append(((Type)_argsType.elementAt(i)).toSignature()); 99 } 100 } 101 return buffer 102 .append(lastArgSig) 103 .append(')') 104 .append(_resultType.toSignature()) 105 .toString(); 106 } 107 108 public com.sun.org.apache.bcel.internal.generic.Type toJCType() { 109 return null; } 111 112 public boolean identicalTo(Type other) { 113 boolean result = false; 114 if (other instanceof MethodType) { 115 final MethodType temp = (MethodType) other; 116 if (_resultType.identicalTo(temp._resultType)) { 117 final int len = argsCount(); 118 result = len == temp.argsCount(); 119 for (int i = 0; i < len && result; i++) { 120 final Type arg1 = (Type)_argsType.elementAt(i); 121 final Type arg2 = (Type)temp._argsType.elementAt(i); 122 result = arg1.identicalTo(arg2); 123 } 124 } 125 } 126 return result; 127 } 128 129 public int distanceTo(Type other) { 130 int result = Integer.MAX_VALUE; 131 if (other instanceof MethodType) { 132 final MethodType mtype = (MethodType) other; 133 if (_argsType != null) { 134 final int len = _argsType.size(); 135 if (len == mtype._argsType.size()) { 136 result = 0; 137 for (int i = 0; i < len; i++) { 138 Type arg1 = (Type) _argsType.elementAt(i); 139 Type arg2 = (Type) mtype._argsType.elementAt(i); 140 final int temp = arg1.distanceTo(arg2); 141 if (temp == Integer.MAX_VALUE) { 142 result = temp; break; 144 } 145 else { 146 result += arg1.distanceTo(arg2); 147 } 148 } 149 } 150 } 151 else if (mtype._argsType == null) { 152 result = 0; } 154 } 155 return result; 156 } 157 158 public Type resultType() { 159 return _resultType; 160 } 161 162 public Vector argsType() { 163 return _argsType; 164 } 165 166 public int argsCount() { 167 return _argsType == null ? 0 : _argsType.size(); 168 } 169 } 170 | Popular Tags |