private boolean hasAlternate(JSType type, EquivalenceMethod eqMethod, EqCache eqCache) { for (JSType alternate : getAlternatesWithoutStructuralTyping()) { if (alternate.checkEquivalenceHelper(type, eqMethod, eqCache)) { return true; } } return false; }
private boolean hasAlternate(JSType type, EquivalenceMethod eqMethod, EqCache eqCache) { List<JSType> alternatesRetainingStructuralSubtypes = getAlternatesWithoutStructuralTyping(); for (int i = 0; i < alternatesRetainingStructuralSubtypes.size(); i++) { JSType alternate = alternatesRetainingStructuralSubtypes.get(i); if (alternate.checkEquivalenceHelper(type, eqMethod, eqCache)) { return true; } } return false; }
/** * Two union types are equal if, after flattening nested union types, they have the same number of * alternatesCollapsingStructuralSubtypes and all alternatesCollapsingStructuralSubtypes are * equal. */ boolean checkUnionEquivalenceHelper(UnionType that, EquivalenceMethod eqMethod, EqCache eqCache) { List<JSType> thatAlternates = that.getAlternatesWithoutStructuralTyping(); if (eqMethod == EquivalenceMethod.IDENTITY && getAlternatesWithoutStructuralTyping().size() != thatAlternates.size()) { return false; } for (int i = 0; i < thatAlternates.size(); i++) { JSType thatAlternate = thatAlternates.get(i); if (!hasAlternate(thatAlternate, eqMethod, eqCache)) { return false; } } return true; }
/** * Two union types are equal if, after flattening nested union types, * they have the same number of alternates and all alternates are equal. */ boolean checkUnionEquivalenceHelper( UnionType that, EquivalenceMethod eqMethod, EqCache eqCache) { Collection<JSType> thatAlternates = that.getAlternatesWithoutStructuralTyping(); if (eqMethod == EquivalenceMethod.IDENTITY && getAlternatesWithoutStructuralTyping().size() != thatAlternates.size()) { return false; } for (JSType alternate : thatAlternates) { if (!hasAlternate(alternate, eqMethod, eqCache)) { return false; } } return true; }
public Iterable<JSType> getUnionMembers() { return isUnionType() ? this.toMaybeUnionType().getAlternatesWithoutStructuralTyping() : null; }
Collection<JSType> alts = ut.getAlternatesWithoutStructuralTyping();
if (unionType != null && unionType .getAlternatesWithoutStructuralTyping() .stream() .anyMatch(JSType::isVoidType)) {
/** * 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()); } }
|| arrayMembers.toMaybeUnionType().getAlternatesWithoutStructuralTyping().size() != 2) { return false; arrayMembers.toMaybeUnionType().getAlternatesWithoutStructuralTyping().iterator(); visitType(it.next()); emit(",");
.getAlternatesWithoutStructuralTyping() .stream() .anyMatch(JSType::isVoidType)
/** * Returns the alternatives if this is a type that represents multiple * types, and null if not. Union and interface types can correspond to * multiple other types. */ private Iterable<JSType> getTypeAlternatives(JSType type) { if (type.isUnionType()) { return type.toMaybeUnionType().getAlternatesWithoutStructuralTyping(); } else { ObjectType objType = type.toObjectType(); if (objType != null && objType.getConstructor() != null && objType.getConstructor().isInterface()) { List<JSType> list = new ArrayList<JSType>(); for (FunctionType impl : registry.getDirectImplementors(objType)) { list.add(impl.getInstanceType()); } return list; } else { return null; } } }
/** 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); }
for (JSType alt : type.toMaybeUnionType().getAlternatesWithoutStructuralTyping()) { alt = alt.isBoxableScalar() ? alt.autoboxesTo() : alt; boolean isIterable = alt.isSubtypeOf(getNativeType(ITERABLE_TYPE));
/** Returns true if properties on this type should not be renamed. */ private boolean isInvalidatingType(JSType type) { if (type.isUnionType()) { type = type.restrictByNotNullOrUndefined(); if (type.isUnionType()) { for (JSType alt : type.toMaybeUnionType().getAlternatesWithoutStructuralTyping()) { if (isInvalidatingType(alt)) { return true; } } return false; } } ObjectType objType = ObjectType.cast(type); return objType == null || invalidatingTypes.contains(objType) || !objType.hasReferenceName() || objType.isUnknownType() || objType.isEmptyType() /* unresolved types */ || objType.isEnumType() || objType.autoboxesTo() != null; }
UnionType union = alternate.toMaybeUnionType(); List<JSType> alternatesWithoutStructuralTyping = union.getAlternatesWithoutStructuralTyping(); for (int i = 0; i < alternatesWithoutStructuralTyping.size(); i++) { JSType unionAlt = alternatesWithoutStructuralTyping.get(i);
/** * Expect the type to autobox to be an Iterable. * * @return True if there was no warning, false if there was a mismatch. */ boolean expectAutoboxesToIterable(NodeTraversal t, Node n, JSType type, String msg) { // Note: we don't just use JSType.autobox() here because that removes null and undefined. // We want to keep null and undefined around. if (type.isUnionType()) { for (JSType alt : type.toMaybeUnionType().getAlternatesWithoutStructuralTyping()) { alt = alt.isBoxableScalar() ? alt.autoboxesTo() : alt; if (!alt.isSubtypeOf(getNativeType(ITERABLE_TYPE))) { mismatch(t, n, msg, type, ITERABLE_TYPE); return false; } } } else { JSType autoboxedType = type.isBoxableScalar() ? type.autoboxesTo() : type; if (!autoboxedType.isSubtypeOf(getNativeType(ITERABLE_TYPE))) { mismatch(t, n, msg, type, ITERABLE_TYPE); return false; } } return true; }
for (JSType alternate : type.toMaybeUnionType().getAlternatesWithoutStructuralTyping()) { unionTypeBuilder.addAlternate(getResolvedType(registry, alternate));
union.getAlternatesWithoutStructuralTyping(); for (int i = 0; i < alternatesWithoutStucturalTyping.size(); i++) { JSType element = alternatesWithoutStucturalTyping.get(i);
/** * Invalidates the given type, so that no properties on it will be renamed. */ private void recordInvalidatingType(JSType type, JSError error) { type = type.restrictByNotNullOrUndefined(); if (type.isUnionType()) { for (JSType alt : type.toMaybeUnionType().getAlternatesWithoutStructuralTyping()) { recordInvalidatingType(alt, error); } } else if (type.isEnumElementType()) { recordInvalidatingType( type.toMaybeEnumElementType().getPrimitiveType(), error); } else { addInvalidatingType(type); recordInvalidationError(type, error); ObjectType objType = ObjectType.cast(type); if (objType != null && objType.getImplicitPrototype() != null) { addInvalidatingType(objType.getImplicitPrototype()); recordInvalidationError(objType.getImplicitPrototype(), error); } if (objType != null && objType.isConstructor() && objType.isFunctionType()) { addInvalidatingType(objType.toMaybeFunctionType().getInstanceType()); } } }