Represents a union type, which is of the form: UnionType ::= IntersectionType ('|' IntersectionType) Union types are used to compose types together. For example, the type int|null represents the type which is either an int or null . Represents t
| 6161 | * @return |
| 6162 | */ |
| 6163 | public static class Union extends AbstractType implements Type { |
| 6164 | public static Type create(WyilFile.Tuple<Type> types) { |
| 6165 | return create(types.toArray(Type.class)); |
| 6166 | } |
| 6167 | /** |
| 6168 | * Create a sequence of zero or more types. |
| 6169 | * |
| 6170 | * @param types |
| 6171 | * @return |
| 6172 | */ |
| 6173 | public static Type create(Type... _types) { |
| 6174 | Type[] types = _types; |
| 6175 | for (int i = 0; i != types.length; ++i) { |
| 6176 | Type ith = types[i]; |
| 6177 | if (ith instanceof Type.Union) { |
| 6178 | Type.Union u = (Type.Union) ith; |
| 6179 | Type[] nTypes = new Type[types.length + u.size() - 1]; |
| 6180 | System.arraycopy(types, 0, nTypes, 0, i); |
| 6181 | System.arraycopy(u.getAll(), 0, nTypes, i, u.size()); |
| 6182 | System.arraycopy(types, i + 1, nTypes, i + u.size(), (types.length - i - 1)); |
| 6183 | return create(nTypes); |
| 6184 | } else if(ith instanceof Type.Void) { |
| 6185 | if(types == _types) { |
| 6186 | types = Arrays.copyOf(_types, _types.length); |
| 6187 | } |
| 6188 | types[i] = null; |
| 6189 | } |
| 6190 | } |
| 6191 | // |
| 6192 | types = ArrayUtils.removeAll(types, null); |
| 6193 | types = ArrayUtils.removeDuplicates(types); |
| 6194 | // |
| 6195 | switch (types.length) { |
| 6196 | case 0: |
| 6197 | return Type.Void; |
| 6198 | case 1: |
| 6199 | return types[0]; |
| 6200 | default: |
| 6201 | return new Type.Union(types); |
| 6202 | } |
| 6203 | } |
| 6204 | |
| 6205 | public Union(Type... types) { |
| 6206 | super(TYPE_union, types); |
| 6207 | } |
| 6208 | |
| 6209 | @Override |
| 6210 | public boolean isWriteable() { |
| 6211 | for(int i=0;i!=size();++i) { |
| 6212 | if(!get(i).isWriteable()) { |
| 6213 | return false; |
| 6214 | } |
| 6215 | } |
| 6216 | return true; |
| 6217 | } |
| 6218 | |
| 6219 | @Override |
| 6220 | public boolean isReadable() { |
nothing calls this directly
no outgoing calls
no test coverage detected