/** * Dereferences a type for property access. * * Filters null/undefined and autoboxes the resulting type. * Never returns null. */ public JSType autobox() { JSType restricted = restrictByNotNullOrUndefined(); JSType autobox = restricted.autoboxesTo(); return autobox == null ? restricted : autobox; }
/** * Dereference a type for property access. * * Filters null/undefined and autoboxes the resulting type. * Never returns null. */ public JSType autobox() { JSType restricted = restrictByNotNullOrUndefined(); JSType autobox = restricted.autoboxesTo(); return autobox == null ? restricted : autobox; }
private boolean isType(JSType jsType, String fileName) { if (jsType == null) { return false; } jsType = jsType.restrictByNotNullOrUndefined(); if (jsType.toMaybeObjectType() == null) { return false; } String sourceName = getSourceName(jsType); return sourceName != null && sourceName.endsWith(fileName); }
protected boolean isTypeVariable(Node n) { JSType type = n.getJSType().restrictByNotNullOrUndefined(); return type.isTypeVariable(); }
private static boolean isObjectLiteralThatCanBeSkipped(JSType t) { t = t.restrictByNotNullOrUndefined(); return t.isRecordType() || t.isLiteralObject(); }
private boolean isBottom(Node n) { JSType type = n.getJSType().restrictByNotNullOrUndefined(); return type.isEmptyType(); }
@Override public JSType restrictByNotNullOrUndefined() { UnionTypeBuilder restricted = UnionTypeBuilder.create(registry); for (int i = 0; i < alternatesRetainingStructuralSubtypes.size(); i++) { JSType t = alternatesRetainingStructuralSubtypes.get(i); restricted.addAlternate(t.restrictByNotNullOrUndefined()); } return restricted.build(); }
protected boolean isTemplateType(Node n) { JSType type = n.getJSType().restrictByNotNullOrUndefined(); return type.isTemplateType(); }
private boolean isEmptyType(Node n) { JSType type = n.getJSType().restrictByNotNullOrUndefined(); return type.isEmptyType(); }
/** * If this object is known to be an IThenable, returns the type it resolves to. * * <p>Returns unknown otherwise. * * <p>(This is different from {@code getResolvedType}, which will attempt to model the then type * of an expression after calling Promise.resolve() on it. */ static final JSType getTemplateTypeOfThenable(JSTypeRegistry registry, JSType maybeThenable) { return maybeThenable // Without ".restrictByNotNullOrUndefined" we'd get the unknown type for "?IThenable<null>" .restrictByNotNullOrUndefined() .getInstantiatedTypeArgument(registry.getNativeType(JSTypeNative.I_THENABLE_TYPE)); }
protected boolean isNativeObjectType(Node n) { JSType type = n.getJSType().restrictByNotNullOrUndefined(); return type.isEquivalentTo(nativeObjectType); }
private static JSType removeNullUndefinedAndTemplates(JSType t) { JSType result = t.restrictByNotNullOrUndefined(); ObjectType obj = result.toMaybeObjectType(); if (obj != null && obj.isGenericObjectType()) { return obj.instantiateGenericsWithUnknown(); } return result; }
protected boolean isWhitelistedType(Node n) { if (whitelistedTypes != null && n.getJSType() != null) { JSType targetType = n.getJSType().restrictByNotNullOrUndefined(); if (targetType.isSubtypeOf(whitelistedTypes)) { return true; } } return false; }
@Override public JSType restrictByNotNullOrUndefined() { UnionTypeBuilder restricted = new UnionTypeBuilder(registry); for (JSType t : alternatesWithoutStucturalTyping) { restricted.addAlternate(t.restrictByNotNullOrUndefined()); } return restricted.build(); }
protected boolean isWhitelistedType(Node n) { if (whitelistedTypes != null && n.getJSType() != null) { JSType targetType = n.getJSType().restrictByNotNullOrUndefined(); if (targetType.isSubtype(whitelistedTypes)) { return true; } } return false; }
private boolean isMatchingType(Node n, JSType src) { src = src.restrictByNotNullOrUndefined(); JSType dest = getJSType(n).restrictByNotNullOrUndefined(); if (invalidatingTypes.isInvalidating(dest)) { return false; } if (dest.isConstructor() || src.isConstructor()) { // instead of using .isSubtypeOf for functions, check the prototype chain, since the // FunctionType subtyping semantics is not what we want. // This case is for ES6 class-side inheritance return hasInPrototypeChain(dest.toMaybeFunctionType(), src.toMaybeFunctionType()); } return dest.isSubtypeOf(src); }
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 public boolean matches(Node node, NodeMetadata metadata) { JSType providedJsType = getJsType(metadata, type); if (providedJsType == null) { return false; } providedJsType = providedJsType.restrictByNotNullOrUndefined(); JSType jsType = node.getJSType(); return jsType != null && jsType.isEnumType() && providedJsType.isEquivalentTo( jsType.toMaybeEnumType().getElementsType().getPrimitiveType()); } };
private boolean isClassType(Node n) { ObjectType type = n.getJSType().restrictByNotNullOrUndefined().toMaybeObjectType(); if (type != null && type.isInstanceType()) { FunctionType ctor = type.getConstructor(); if (ctor != null) { JSDocInfo info = ctor.getJSDocInfo(); if (info != null && info.isConstructorOrInterface()) { return true; } } } return false; }
private FlowScope traverseGetElem(Node n, FlowScope scope) { scope = traverseChildren(n, scope); JSType type = getJSType(n.getFirstChild()).restrictByNotNullOrUndefined(); TemplateTypeMap typeMap = type.getTemplateTypeMap(); if (typeMap.hasTemplateType(registry.getObjectElementKey())) { n.setJSType(typeMap.getResolvedTemplateType(registry.getObjectElementKey())); } return dereferencePointer(n.getFirstChild(), scope); }