@Override public final UnionType toMaybeUnionType() { return referencedType.toMaybeUnionType(); }
@Override public UnionType toMaybeUnionType() { return referencedType.toMaybeUnionType(); }
public final boolean isUnionType() { return toMaybeUnionType() != null; }
public final boolean isUnionType() { return toMaybeUnionType() != null; }
public Iterable<JSType> getUnionMembers() { return isUnionType() ? this.toMaybeUnionType().getAlternatesWithoutStructuralTyping() : null; }
/** Gets the string representation of a var args param. */ private void appendVarArgsString(StringBuilder builder, JSType paramType, boolean forAnnotations) { if (paramType.isUnionType()) { // Remove the optionality from the var arg. paramType = paramType.toMaybeUnionType().getRestrictedUnion( registry.getNativeType(JSTypeNative.VOID_TYPE)); } builder.append("...").append( paramType.toStringHelper(forAnnotations)); }
/** Gets the string representation of an optional param. */ private void appendOptionalArgString( StringBuilder builder, JSType paramType, boolean forAnnotations) { if (paramType.isUnionType()) { // Remove the optionality from the var arg. paramType = paramType.toMaybeUnionType().getRestrictedUnion( registry.getNativeType(JSTypeNative.VOID_TYPE)); } builder.append(paramType.toStringHelper(forAnnotations)).append("="); }
/** Gets the string representation of an optional param. */ private void appendOptionalArgString(StringBuilder sb, JSType paramType, boolean forAnnotations) { if (paramType.isUnionType()) { // Remove the optionality from the var arg. paramType = paramType .toMaybeUnionType() .getRestrictedUnion(registry.getNativeType(JSTypeNative.VOID_TYPE)); } paramType.appendAsNonNull(sb, forAnnotations).append("="); }
private JSType restrictByUndefined(JSType type) { if (type.isUnionType()) { return type.toMaybeUnionType().getRestrictedUnion( (JSType) registry.getNativeType(JSTypeNative.VOID_TYPE)); } return type; } }
private void printErrorLocations(List<String> errors, JSType t) { if (!t.isObject() || t.isAllType()) { return; } if (t.isUnionType()) { for (JSType alt : t.toMaybeUnionType().getAlternates()) { printErrorLocations(errors, alt); } return; } for (JSError error : invalidationMap.get(t)) { errors.add(t + " at " + error.sourceName + ":" + error.lineNumber); } }
private static boolean containsForwardDeclaredUnresolvedName(JSType type) { if (type.isUnionType()) { for (JSType alt : type.toMaybeUnionType().getAlternates()) { if (containsForwardDeclaredUnresolvedName(alt)) { return true; } } } return type.isNoResolvedType(); }
private void addReferenceTypeIndexedByProperty( String propertyName, JSType type) { if (type instanceof ObjectType && ((ObjectType) type).hasReferenceName()) { Map<String, ObjectType> typeSet = eachRefTypeIndexedByProperty.computeIfAbsent(propertyName, k -> new LinkedHashMap<>()); ObjectType objType = (ObjectType) type; typeSet.put(objType.getReferenceName(), objType); } else if (type instanceof NamedType) { addReferenceTypeIndexedByProperty( propertyName, ((NamedType) type).getReferencedType()); } else if (type.isUnionType()) { for (JSType alternate : type.toMaybeUnionType().getAlternates()) { addReferenceTypeIndexedByProperty(propertyName, alternate); } } }
private static boolean containsForwardDeclaredUnresolvedName(JSType type) { if (type.isUnionType()) { for (JSType alt : type.toMaybeUnionType().getAlternates()) { if (containsForwardDeclaredUnresolvedName(alt)) { return true; } } } return type.isNoResolvedType(); }
private boolean conforms(JSType type) { if (type.isUnionType()) { // unwrap union types which might contain unresolved type name // references for example {Foo|undefined} for (JSType part : type.toMaybeUnionType().getAlternates()) { if (!conforms(part)) { return false; } } return true; } else { return !type.isNoResolvedType(); } } }
/** * Invalidates the given type, so that no properties on it will be renamed. */ private void addInvalidatingType(JSType type) { type = type.restrictByNotNullOrUndefined(); if (type.isUnionType()) { for (JSType alt : type.toMaybeUnionType().getAlternatesWithoutStructuralTyping()) { addInvalidatingType(alt); } } invalidatingTypes.add(type); ObjectType objType = ObjectType.cast(type); if (objType != null && objType.isInstanceType()) { invalidatingTypes.add(objType.getImplicitPrototype()); } }
/** * Invalidates the given type, so that no properties on it will be renamed. */ private void addInvalidatingType(JSType type) { type = type.restrictByNotNullOrUndefined(); if (type.isUnionType()) { for (JSType alt : type.toMaybeUnionType().getAlternatesWithoutStructuralTyping()) { addInvalidatingType(alt); } } invalidatingTypes.add(type); ObjectType objType = ObjectType.cast(type); if (objType != null && objType.isInstanceType()) { invalidatingTypes.add(objType.getImplicitPrototype()); } }
private boolean containsArray(JSType type) { if (isArray(type)) { return true; } if (type.isUnionType()) { JSType arrayType = typeRegistry.getNativeType(ARRAY_TYPE); for (JSType alternate : type.toMaybeUnionType().getAlternates()) { if (alternate.isSubtype(arrayType)) { return true; } } } return false; }
/** Add this type to this property, calculating */ void addType(JSType newType) { if (skipAmbiguating) { return; } ++numOccurrences; if (newType.isUnionType()) { newType = newType.restrictByNotNullOrUndefined(); if (newType.isUnionType()) { for (JSType alt : newType.toMaybeUnionType().getAlternatesWithoutStructuralTyping()) { addNonUnionType(alt); } return; } } addNonUnionType(newType); }
private void addEventize(JSType thisType, JSType thatType) { if (collectorFilterType(thisType) || collectorFilterType(thatType) || thisType.isEquivalentTo(thatType)) { return; } String className = thisType.getDisplayName(); if (thatType.isUnionType()) { UnionType ut = thatType.toMaybeUnionType(); for (JSType type : ut.getAlternates()) { if (type.isObject()) { addEventizeClass(className, type); } } } else { addEventizeClass(className, thatType); } }
private boolean containsArray(JSType type) { // Check if type is itself an array if (type.isArrayType()) { return true; } TemplatizedType templatizedType = type.toMaybeTemplatizedType(); if (templatizedType != null && templatizedType.getReferencedType().isArrayType()) { return true; } // Check if this is a union that contains an array if (type.isUnionType()) { JSType arrayType = compiler.getTypeRegistry().getNativeType(JSTypeNative.ARRAY_TYPE); for (JSType alternate : type.toMaybeUnionType().getAlternates()) { if (alternate.isSubtypeOf(arrayType)) { return true; } } } return false; }