1 package org.simantics.scl.compiler.types.kinds;
3 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
6 * This is an abstract base class for type kinds. It has three child classes:
7 * KCon for constants, KArrow for kind arrows and KMetaVar for kind meta-variables.
9 * Child classes need to implement the method {@link #contains(KMetaVar)}, which
10 * returns true, if a given kind meta-variable points to this instance.
12 * The default implementation of {@link #toString()} is infinitely recursive, with
13 * {@link #toString(TypeUnparsingContext, StringBuilder)} and {@link #toStringPar(TypeUnparsingContext, StringBuilder)}
14 * both calling each other.
16 public abstract class Kind {
17 public static final Kind[] EMPTY_ARRAY = new Kind[0];
20 public String toString() {
21 return toString(new TypeUnparsingContext());
24 public String toString(TypeUnparsingContext tuc) {
25 StringBuilder b = new StringBuilder();
31 * Write this kind to a string builder as an unparenthesized expression.
32 * If a subclass does not need parenthesis, it can implement the
33 * {@link #toStringPar(TypeUnparsingContext, StringBuilder)} method instead.
35 protected void toString(TypeUnparsingContext tuc, StringBuilder b) {
40 * Write this kind to a string builder as an atomic expression. The default implementation
41 * encloses the output of {@link #toString(TypeUnparsingContext, StringBuilder)} in parenthesis.
43 protected void toStringPar(TypeUnparsingContext tuc, StringBuilder b) {
50 * Return true, if this kind has been unified with the given kind meta-variable.
52 public abstract boolean contains(KMetaVar var);