@Override public String getDisplayName() { return elementsType.getDisplayName(); }
@Override StringBuilder appendTo(StringBuilder sb, boolean forAnnotations) { if (forAnnotations) { // TODO(dimvar): this should use getReferenceName() instead of this.primitiveType return sb.append(this.primitiveType); } return sb.append(getReferenceName()).append("<").append(this.primitiveType).append(">"); }
/** * Returns the infimum of a enum element type and another type, or null * if the infimum is empty. * * This can be a little bit weird. For example, suppose you have an enum * of {(string|number)}, and you want the greatest subtype of the enum * and a {number}. * * The infimum is non-empty. But at the same time, we don't really have * a name for this infimum. It's equivalent to "elements of this enum that * are numbers". * * The best we can do is make up a new type. This is similar to what * we do in UnionType#meet, which kind-of-sort-of makes sense, because * an EnumElementType is a union of instances of a type. */ JSType meet(JSType that) { JSType meetPrimitive = primitiveType.getGreatestSubtype(that); if (meetPrimitive.isEmptyType()) { return null; } else { return new EnumElementType(registry, meetPrimitive, name, getEnumType()); } }
/** * If this is equal to a NamedType object, its hashCode must be equal * to the hashCode of the NamedType object. */ @Override public int hashCode() { if (hasReferenceName()) { return getReferenceName().hashCode(); } else { return super.hashCode(); } }
/** Gets the enumerated type. */ @Override public JSType getEnumeratedTypeOfEnumObject() { return elementsType.getPrimitiveType(); }
@Override JSType resolveInternal(ErrorReporter reporter) { elementsType = (EnumElementType) elementsType.resolve(reporter); return super.resolveInternal(reporter); } }
/** * Creates an enum type. * * @param name the enum's name * @param elementsType the base type of the individual elements */ EnumType(JSTypeRegistry registry, String name, Node source, JSType elementsType) { super(registry, "enum{" + name + "}", null); this.elementsType = new EnumElementType(registry, elementsType, name, this); }
@Override public boolean isNominalType() { return hasReferenceName(); }
@Override public boolean isSubtype(JSType that) { return isSubtype(that, ImplCache.create()); }
@Override public Boolean caseEnumElementType( EnumElementType typeType, JSType thatType) { return typeType.getPrimitiveType().visit(this, thatType); } }
@Override JSType resolveInternal(ErrorReporter t, StaticTypedScope<JSType> scope) { elementsType = (EnumElementType) elementsType.resolve(t, scope); return super.resolveInternal(t, scope); } }
/** * Creates an enum type. * * @param name the enum's name * @param elementsType the base type of the individual elements */ EnumType(JSTypeRegistry registry, String name, Node source, JSType elementsType) { super(registry, "enum{" + name + "}", null); this.elementsType = new EnumElementType(registry, elementsType, name, this); }
@Override public boolean isNominalType() { return hasReferenceName(); }
@Override public boolean isSubtype(JSType that) { return isSubtype(that, ImplCache.create(), SubtypingMode.NORMAL); }
@Override public JSType caseEnumElementType(EnumElementType enumElementType) { JSType type = enumElementType.getPrimitiveType().visit(this); if (type != null && enumElementType.getPrimitiveType().isEquivalentTo(type)) { return enumElementType; } else { return type; } }
@Override String toStringHelper(boolean forAnnotations) { return forAnnotations ? primitiveType.toString() : (getReferenceName() + "<" + primitiveType + ">"); }
/** * Returns the infimum of a enum element type and another type, or null * if the infimum is empty. * * This can be a little bit weird. For example, suppose you have an enum * of {(string|number)}, and you want the greatest subtype of the enum * and a {number}. * * The infimum is non-empty. But at the same time, we don't really have * a name for this infimum. It's equivalent to "elements of this enum that * are numbers". * * The best we can do is make up a new type. This is similar to what * we do in UnionType#meet, which kind-of-sort-of makes sense, because * an EnumElementType is a union of instances of a type. */ JSType meet(JSType that) { JSType meetPrimitive = primitiveType.getGreatestSubtype(that); if (meetPrimitive.isEmptyType()) { return null; } else { return new EnumElementType(registry, meetPrimitive, name, getEnumType()); } }
@Override public String getDisplayName() { return elementsType.getDisplayName(); }