19 * limitations under the License. |
19 * limitations under the License. |
20 */ |
20 */ |
21 |
21 |
22 package com.sun.org.apache.xalan.internal.xsltc.compiler.util; |
22 package com.sun.org.apache.xalan.internal.xsltc.compiler.util; |
23 |
23 |
24 import java.util.Vector; |
24 import java.util.ArrayList; |
|
25 import java.util.List; |
25 |
26 |
26 /** |
27 /** |
27 * @author Jacek Ambroziak |
28 * @author Jacek Ambroziak |
28 * @author Santiago Pericas-Geertsen |
29 * @author Santiago Pericas-Geertsen |
29 */ |
30 */ |
30 public final class MethodType extends Type { |
31 public final class MethodType extends Type { |
31 private final Type _resultType; |
32 private final Type _resultType; |
32 private final Vector _argsType; |
33 private final List<Type> _argsType; |
33 |
34 |
34 public MethodType(Type resultType) { |
35 public MethodType(Type resultType) { |
35 _argsType = null; |
36 _argsType = null; |
36 _resultType = resultType; |
37 _resultType = resultType; |
37 } |
38 } |
38 |
39 |
39 public MethodType(Type resultType, Type arg1) { |
40 public MethodType(Type resultType, Type arg1) { |
40 if (arg1 != Type.Void) { |
41 if (arg1 != Type.Void) { |
41 _argsType = new Vector(); |
42 _argsType = new ArrayList<>(); |
42 _argsType.addElement(arg1); |
43 _argsType.add(arg1); |
43 } |
44 } |
44 else { |
45 else { |
45 _argsType = null; |
46 _argsType = null; |
46 } |
47 } |
47 _resultType = resultType; |
48 _resultType = resultType; |
48 } |
49 } |
49 |
50 |
50 public MethodType(Type resultType, Type arg1, Type arg2) { |
51 public MethodType(Type resultType, Type arg1, Type arg2) { |
51 _argsType = new Vector(2); |
52 _argsType = new ArrayList<>(2); |
52 _argsType.addElement(arg1); |
53 _argsType.add(arg1); |
53 _argsType.addElement(arg2); |
54 _argsType.add(arg2); |
54 _resultType = resultType; |
55 _resultType = resultType; |
55 } |
56 } |
56 |
57 |
57 public MethodType(Type resultType, Type arg1, Type arg2, Type arg3) { |
58 public MethodType(Type resultType, Type arg1, Type arg2, Type arg3) { |
58 _argsType = new Vector(3); |
59 _argsType = new ArrayList<>(3); |
59 _argsType.addElement(arg1); |
60 _argsType.add(arg1); |
60 _argsType.addElement(arg2); |
61 _argsType.add(arg2); |
61 _argsType.addElement(arg3); |
62 _argsType.add(arg3); |
62 _resultType = resultType; |
63 _resultType = resultType; |
63 } |
64 } |
64 |
65 |
65 public MethodType(Type resultType, Vector argsType) { |
66 public MethodType(Type resultType, List<Type> argsType) { |
66 _resultType = resultType; |
67 _resultType = resultType; |
67 _argsType = argsType.size() > 0 ? argsType : null; |
68 _argsType = argsType.size() > 0 ? argsType : null; |
68 } |
69 } |
69 |
70 |
70 public String toString() { |
71 public String toString() { |
71 StringBuffer result = new StringBuffer("method{"); |
72 StringBuffer result = new StringBuffer("method{"); |
72 if (_argsType != null) { |
73 if (_argsType != null) { |
73 final int count = _argsType.size(); |
74 final int count = _argsType.size(); |
74 for (int i=0; i<count; i++) { |
75 for (int i=0; i<count; i++) { |
75 result.append(_argsType.elementAt(i)); |
76 result.append(_argsType.get(i)); |
76 if (i != (count-1)) result.append(','); |
77 if (i != (count-1)) result.append(','); |
77 } |
78 } |
78 } |
79 } |
79 else { |
80 else { |
80 result.append("void"); |
81 result.append("void"); |
117 final MethodType temp = (MethodType) other; |
118 final MethodType temp = (MethodType) other; |
118 if (_resultType.identicalTo(temp._resultType)) { |
119 if (_resultType.identicalTo(temp._resultType)) { |
119 final int len = argsCount(); |
120 final int len = argsCount(); |
120 result = len == temp.argsCount(); |
121 result = len == temp.argsCount(); |
121 for (int i = 0; i < len && result; i++) { |
122 for (int i = 0; i < len && result; i++) { |
122 final Type arg1 = (Type)_argsType.elementAt(i); |
123 final Type arg1 = _argsType.get(i); |
123 final Type arg2 = (Type)temp._argsType.elementAt(i); |
124 final Type arg2 = temp._argsType.get(i); |
124 result = arg1.identicalTo(arg2); |
125 result = arg1.identicalTo(arg2); |
125 } |
126 } |
126 } |
127 } |
127 } |
128 } |
128 return result; |
129 return result; |
135 if (_argsType != null) { |
136 if (_argsType != null) { |
136 final int len = _argsType.size(); |
137 final int len = _argsType.size(); |
137 if (len == mtype._argsType.size()) { |
138 if (len == mtype._argsType.size()) { |
138 result = 0; |
139 result = 0; |
139 for (int i = 0; i < len; i++) { |
140 for (int i = 0; i < len; i++) { |
140 Type arg1 = (Type) _argsType.elementAt(i); |
141 Type arg1 = _argsType.get(i); |
141 Type arg2 = (Type) mtype._argsType.elementAt(i); |
142 Type arg2 = mtype._argsType.get(i); |
142 final int temp = arg1.distanceTo(arg2); |
143 final int temp = arg1.distanceTo(arg2); |
143 if (temp == Integer.MAX_VALUE) { |
144 if (temp == Integer.MAX_VALUE) { |
144 result = temp; // return MAX_VALUE |
145 result = temp; // return MAX_VALUE |
145 break; |
146 break; |
146 } |
147 } |