1 package jdk.incubator.code.dialect.core;
 2 
 3 import jdk.incubator.code.TypeElement;
 4 import jdk.incubator.code.extern.ExternalizedTypeElement;
 5 
 6 /**
 7  * A variable type.
 8  */
 9 public final class VarType implements CoreType {
10     static final String NAME = "Var";
11 
12     final TypeElement valueType;
13 
14     VarType(TypeElement valueType) {
15         this.valueType = valueType;
16     }
17 
18     /**
19      * {@return the variable type's value type}
20      */
21     public TypeElement valueType() {
22         return valueType;
23     }
24 
25     @Override
26     public ExternalizedTypeElement externalize() {
27         return ExternalizedTypeElement.of(NAME,
28                 valueType.externalize());
29     }
30 
31     @Override
32     public String toString() {
33         return externalize().toString();
34     }
35 
36     @Override
37     public boolean equals(Object o) {
38         if (this == o) return true;
39         return o instanceof VarType that &&
40                 valueType.equals(that.valueType);
41     }
42 
43     @Override
44     public int hashCode() {
45         return valueType.hashCode();
46     }
47 }