1 package jdk.incubator.code.dialect.core;
2
3 import jdk.incubator.code.TypeElement;
4 import jdk.incubator.code.extern.ExternalizedTypeElement;
5
6 import java.util.List;
7
8 /**
9 * A tuple type.
10 */
11 public final class TupleType implements CoreType {
12 static final String NAME = "Tuple";
13
14 final List<TypeElement> componentTypes;
15
16 TupleType(List<? extends TypeElement> componentTypes) {
17 this.componentTypes = List.copyOf(componentTypes);
18 }
19
20 /**
21 * {@return the tuple's component types, in order}
22 */
23 public List<TypeElement> componentTypes() {
24 return componentTypes;
25 }
26
27 @Override
28 public ExternalizedTypeElement externalize() {
29 return ExternalizedTypeElement.of(NAME,
30 componentTypes.stream().map(TypeElement::externalize).toList());
31 }
32
33 @Override
34 public String toString() {
35 return externalize().toString();
36 }
37
38 @Override
39 public boolean equals(Object o) {
40 if (this == o) return true;
41 return o instanceof TupleType that && componentTypes.equals(that.componentTypes);
42 }
43
44 @Override
45 public int hashCode() {
46 return componentTypes.hashCode();
47 }
48 }