@Override public final boolean isAllType() { return referencedType.isAllType(); }
@Override public boolean isAllType() { return referencedType.isAllType(); }
@Override protected JSType caseTopType(JSType topType) { return topType.isAllType() ? getNativeType(ARRAY_TYPE) : topType; }
protected boolean isTop(Node n) { JSType type = n.getJSType(); return type != null && type.isAllType(); }
@Override protected JSType caseTopType(JSType topType) { return topType.isAllType() ? getNativeType(ARRAY_TYPE) : topType; }
protected boolean isAllType(Node n) { JSType type = n.getJSType(); return type != null && type.isAllType(); }
/** * Creates a type representing optional values of the given type. * @return the union of the type and the void type */ public JSType createOptionalType(JSType type) { if (type instanceof UnknownType || type.isAllType()) { return type; } else { return createUnionType(type, getNativeType(JSTypeNative.VOID_TYPE)); } }
/** * Creates a type representing optional values of the given type. * @return the union of the type and the void type */ public JSType createOptionalType(JSType type) { if (type instanceof UnknownType || type.isAllType()) { return type; } else { return createUnionType(type, getNativeType(JSTypeNative.VOID_TYPE)); } }
static boolean isLooseType(JSType type) { return type.isUnknownType() || type.isUnresolved() || type.isAllType(); }
private boolean invalidDeref(Node n) { JSType type = n.getJSType(); // TODO(johnlenz): top type should not be allowed here return !type.isAllType() && (type.isNullable() || type.isVoidable()); } }
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 void printErrorLocations(List<String> errors, JSType t) { if (!t.isObjectType() || t.isAllType()) { return; } if (t.isUnionType()) { for (JSType alt : t.getUnionMembers()) { printErrorLocations(errors, alt); } return; } Iterable<JSError> invalidations = FluentIterable.from(invalidationMap.get(t)) .transform(Suppliers.supplierFunction()) .limit(MAX_INVALIDATION_WARNINGS_PER_PROPERTY); for (JSError error : invalidations) { errors.add(t + " at " + error.sourceName + ":" + error.lineNumber); } } }
@Override protected boolean isSubtype(JSType that, ImplCache implicitImplCache) { // unknown if (that.isUnknownType() || this.isUnknownType()) { return true; } // all type if (that.isAllType()) { return true; } for (JSType element : alternatesWithoutStucturalTyping) { if (!element.isSubtype(that, implicitImplCache)) { return false; } } return true; }
private boolean canOnlyBeObject(Node n) { JSType type = n.getJSType(); if (type == null) { return false; } type = type.restrictByNotNullOrUndefined(); return !type.isUnknownType() && !type.isEmptyType() && !type.isAllType() && type.isObjectType(); }
@Override protected ConformanceResult checkConformance(NodeTraversal t, Node n) { if (errorObjType != null && n.isThrow()) { JSType thrown = n.getFirstChild().getJSType(); if (thrown != null) { // Allow vague types, as is typical of re-throws of exceptions if (!thrown.isUnknownType() && !thrown.isAllType() && !thrown.isEmptyType() && !thrown.isSubtypeOf(errorObjType)) { return ConformanceResult.VIOLATION; } } } return ConformanceResult.CONFORMANCE; } }
@Override protected ConformanceResult checkConformance(NodeTraversal t, Node n) { if (errorObjType != null && n.isThrow()) { JSType thrown = n.getFirstChild().getJSType(); if (thrown != null) { // Allow vague types, as is typical of re-throws of exceptions if (!thrown.isUnknownType() && !thrown.isAllType() && !thrown.isEmptyType() && !thrown.isSubtype(errorObjType)) { return ConformanceResult.VIOLATION; } } } return ConformanceResult.CONFORMANCE; } }
public MatchResult match(JSType templateType, JSType type) { if (templateType.isUnknownType()) { // If the template type is '?', then any type is a match and this is not considered a loose // match. return MatchResult.MATCH; } if (type == null || type.isUnknownType() || type.isAllType()) { return allowLooseMatches ? MatchResult.LOOSE_MATCH : MatchResult.NO_MATCH; } if (allowSubtypes) { if (ignoreNullability) { type = type.restrictByNotNullOrUndefined(); } if (type.isSubtypeOf(templateType)) { return MatchResult.MATCH; } } boolean nullableMismatch = templateType.isNullable() != type.isNullable(); boolean voidableMismatch = templateType.isVoidable() != type.isVoidable(); if (!ignoreNullability && (nullableMismatch || voidableMismatch)) { return MatchResult.NO_MATCH; } return type.isEquivalentTo(templateType) ? MatchResult.MATCH : MatchResult.NO_MATCH; }
JSType determineReceiverType(Node n) { JSType receiverType = n.getFirstChild().getJSType(); if (NodeUtil.isPrototypeProperty(n)) { JSType maybeCtor = n.getFirstFirstChild().getJSType(); if (maybeCtor != null && maybeCtor.isConstructor()) { receiverType = maybeCtor.toMaybeFunctionType().getInstanceType(); } } // No type information at all, return null. if (receiverType == null) { return null; } // If the known type is too generic to be useful, also return null. receiverType = receiverType.restrictByNotNullOrUndefined(); if (receiverType.isUnknownType() || receiverType.isEmptyType() || receiverType.isAllType() || receiverType.isEquivalentTo( compiler.getTypeRegistry().getNativeType(JSTypeNative.OBJECT_TYPE))) { return null; } return receiverType; }
public MatchResult match(JSType templateType, JSType type) { if (templateType.isUnknownType()) { // If the template type is '?', then any type is a match and this is not considered a loose // match. return new MatchResult(true, false); } if (type == null || type.isUnknownType() || type.isAllType()) { return new MatchResult(allowLooseMatches, allowLooseMatches); } if (allowSubtypes) { if (ignoreNullability) { type = type.restrictByNotNullOrUndefined(); } if (type.isSubtype(templateType)) { return new MatchResult(true, false); } } boolean nullableMismatch = templateType.isNullable() != type.isNullable(); boolean voidableMismatch = templateType.isVoidable() != type.isVoidable(); if (!ignoreNullability && (nullableMismatch || voidableMismatch)) { return new MatchResult(false, false); } return new MatchResult(type.isEquivalentTo(templateType), false); }
Boolean castCastToHelper(JSType thisType, JSType thatType) { if (thatType.isUnknownType() || thatType.isAllType() || thatType.isNoObjectType() // TODO(johnlenz): restrict to objects || thatType.isNoType()) { return true; } else if (thisType.isRecordType() || thatType.isRecordType()) { return true; // TODO(johnlenz): are there any misuses we can catch? } else if (isInterface(thisType) || isInterface(thatType)) { return true; // TODO(johnlenz): are there any misuses we can catch? } else if (thatType.isEnumElementType()) { return thisType.visit(this, thatType.toMaybeEnumElementType().getPrimitiveType()); } else if (thatType.isUnionType()) { return canCastToUnion(thisType, thatType.toMaybeUnionType()); } else if (thatType.isFunctionType()) { return canCastToFunction(thisType, thatType.toMaybeFunctionType()); } else if (thatType.isTemplatizedType()) { // TODO(johnlenz): once the templated type work is finished, // restrict the type parameters. return thisType.visit(this, thatType.toMaybeTemplatizedType().getReferencedTypeInternal()); } return thisType.isSubtype(thatType) || thatType.isSubtype(thisType); }