/** * Returns a version of type where null is not present. */ protected final JSType getRestrictedWithoutNull(JSType type) { return type == null ? null : type.visit(restrictNullVisitor); }
/** * Returns a version of type where undefined is not present. */ protected final JSType getRestrictedWithoutUndefined(JSType type) { return type == null ? null : type.visit(restrictUndefinedVisitor); }
/** * Tests whether values of {@code this} type can be safely assigned * to values of {@code that} type.<p> * * The default implementation verifies that {@code this} is a subtype * of {@code that}.<p> */ public boolean canCastTo(JSType that) { return this.visit(CAN_CAST_TO_VISITOR, that); }
/** * Returns a version of type where null is not present. */ protected final JSType getRestrictedWithoutNull(JSType type) { return type == null ? null : type.visit(restrictNullVisitor); }
/** * Tests whether values of {@code this} type can be safely assigned * to values of {@code that} type.<p> * * The default implementation verifies that {@code this} is a subtype * of {@code that}.<p> */ public final boolean canCastTo(JSType that) { return this.visit(CAN_CAST_TO_VISITOR, that); }
public void visitOnce(JSType type) { // Handle recursive types by only ever visiting the same type once. if (seenTypes.add(type)) { type.visit(this); } }
@Override public JSType getPropertyType(String propertyName) { JSType result = super.getPropertyType(propertyName); return result == null ? null : result.visit(replacer); }
boolean canCastToUnion(JSType thisType, UnionType unionType) { for (JSType type : unionType.getAlternates()) { if (thisType.visit(this, type)) { return true; } } return false; }
@Override public JSType caseProxyObjectType(ProxyObjectType type) { // Be careful not to unwrap a type unless it has changed. JSType beforeType = type.getReferencedTypeInternal(); JSType replacement = beforeType.visit(this); if (replacement != beforeType) { return replacement; } return type; } }
@Override public Boolean caseTemplatizedType( TemplatizedType thisType, JSType thatType) { // TODO(johnlenz): once the templated type work is finished, // restrict the type parameters. return thisType.getReferencedTypeInternal().visit(this, thatType); }
@Override public JSType caseProxyObjectType(ProxyObjectType type) { // Be careful not to unwrap a type unless it has changed. JSType beforeType = type.getReferencedTypeInternal(); JSType replacement = beforeType.visit(this); if (replacement != beforeType) { return replacement; } return type; } }
boolean canCastToUnion(JSType thisType, UnionType unionType) { for (JSType type : unionType.getAlternates()) { if (thisType.visit(this, type)) { return true; } } return false; }
@Override public Boolean caseEnumElementType( EnumElementType typeType, JSType thatType) { return typeType.getPrimitiveType().visit(this, thatType); } }
@Override public Boolean caseEnumElementType( EnumElementType typeType, JSType thatType) { return typeType.getPrimitiveType().visit(this, thatType); } }
@CheckReturnValue private FlowScope caseIsArray(Node value, FlowScope blindScope, boolean outcome) { JSType type = getTypeIfRefinable(value, blindScope); if (type != null) { Visitor<JSType> visitor = outcome ? restrictToArrayVisitor : restrictToNotArrayVisitor; return maybeRestrictName(blindScope, value, type, type.visit(visitor)); } return blindScope; }
private FlowScope caseIsArray(Node value, FlowScope blindScope, boolean outcome) { JSType type = getTypeIfRefinable(value, blindScope); if (type != null) { Visitor<JSType> visitor = outcome ? restrictToArrayVisitor : restrictToNotArrayVisitor; return maybeRestrictName(blindScope, value, type, type.visit(visitor)); } return blindScope; }
@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 public JSType caseEnumElementType(EnumElementType enumElementType) { JSType type = enumElementType.getPrimitiveType().visit(this); if (type != null && enumElementType.getPrimitiveType().isEquivalentTo(type)) { return enumElementType; } else { return type; } }
@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 public JSType caseEnumElementType(EnumElementType enumElementType) { JSType type = enumElementType.getPrimitiveType().visit(this); if (type != null && enumElementType.getPrimitiveType().isEquivalentTo(type)) { return enumElementType; } else { return type; } }