@Override public JSType autoboxesTo() { return primitiveType.autoboxesTo(); }
public boolean isBoxableScalar() { return autoboxesTo() != null; }
@Override public JSType autoboxesTo() { return primitiveType.autoboxesTo(); }
/** * 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; }
/** * Determines whether the given type is one whose properties should not be * considered for renaming. */ private boolean isTypeToSkip(JSType type) { return type.isEnumType() || (type.autoboxesTo() != null); }
/** * Coerces this type to an Object type, then gets the type of the property * whose name is given. * * Unlike {@link ObjectType#getPropertyType}, returns null if the property * is not found. * * @return The property's type. {@code null} if the current type cannot * have properties, or if the type is not found. */ public JSType findPropertyType(String propertyName) { ObjectType autoboxObjType = ObjectType.cast(autoboxesTo()); if (autoboxObjType != null) { return autoboxObjType.findPropertyType(propertyName); } return null; }
/** * Looks up a property on this type, but without properly replacing any templates in the result. * * <p>Subclasses can override this if they need more complicated logic for property lookup than * just autoboxing to an object. * * <p>This is only for use by {@code findPropertyType(JSType)}. Call that method instead if you * need to lookup a property on a random JSType */ @ForOverride @Nullable protected JSType findPropertyTypeWithoutConsideringTemplateTypes(String propertyName) { ObjectType autoboxObjType = ObjectType.cast(autoboxesTo()); if (autoboxObjType != null) { return autoboxObjType.findPropertyType(propertyName); } return null; }
/** * Expect that the type of a switch condition matches the type of its * case condition. */ void expectSwitchMatchesCase(NodeTraversal t, Node n, JSType switchType, JSType caseType) { // ECMA-262, page 68, step 3 of evaluation of CaseBlock, // but allowing extra autoboxing. // TODO(user): remove extra conditions when type annotations // in the code base have adapted to the change in the compiler. if (!switchType.canTestForShallowEqualityWith(caseType) && (caseType.autoboxesTo() == null || !caseType.autoboxesTo().isSubtype(switchType))) { mismatch(t, n.getFirstChild(), "case expression doesn't match switch", caseType, switchType); } else if (!switchType.canTestForShallowEqualityWith(caseType) && (caseType.autoboxesTo() == null || !caseType.autoboxesTo() .isSubtypeWithoutStructuralTyping(switchType))) { recordStructuralInterfaceUses(caseType, switchType); } }
/** * Expect that the type of a switch condition matches the type of its * case condition. */ void expectSwitchMatchesCase(NodeTraversal t, Node n, JSType switchType, JSType caseType) { // ECMA-262, page 68, step 3 of evaluation of CaseBlock, // but allowing extra autoboxing. // TODO(user): remove extra conditions when type annotations // in the code base have adapted to the change in the compiler. if (!switchType.canTestForShallowEqualityWith(caseType) && (caseType.autoboxesTo() == null || !caseType.autoboxesTo().isSubtypeOf(switchType))) { mismatch(t, n.getFirstChild(), "case expression doesn't match switch", caseType, switchType); } else if (!switchType.canTestForShallowEqualityWith(caseType) && (caseType.autoboxesTo() == null || !caseType.autoboxesTo().isSubtypeWithoutStructuralTyping(switchType))) { TypeMismatch.recordImplicitInterfaceUses(this.implicitInterfaceUses, n, caseType, switchType); TypeMismatch.recordImplicitUseOfNativeObject(this.mismatches, n, caseType, switchType); } }
private Symbol lookupPossiblyDottedName(SymbolScope scope, String dottedName) { // Try the dotted name to start. String[] names = dottedName.split("\\."); Symbol result = null; SymbolScope currentScope = scope; for (int i = 0; i < names.length; i++) { String name = names[i]; result = currentScope.getSlot(name); if (result == null) { break; } if (i < (names.length - 1)) { currentScope = result.getPropertyScope(); if (currentScope == null) { result = null; break; } } } if (result == null) { // If we can't find this type, it might be a reference to a // primitive type (like {string}). Autobox it to check. JSType type = typeRegistry.getType(dottedName); JSType autobox = type == null ? null : type.autoboxesTo(); result = autobox == null ? null : getSymbolForTypeHelper(autobox, true); } return result; } }
/** * @return true if n MUST be a prototype name reference. */ private boolean isPrototypeNameReference(Node n) { if (!n.isGetProp()) { return false; } JSType type = getType(n.getFirstChild()); if (type.isUnknownType() || type.isUnionType()) { return false; } return (type.isInstanceType() || type.autoboxesTo() != null); }
alt = alt.isBoxableScalar() ? alt.autoboxesTo() : alt; boolean isIterable = alt.isSubtypeOf(getNativeType(ITERABLE_TYPE)); boolean isAsyncIterable = alt.isSubtypeOf(getNativeType(ASYNC_ITERABLE_TYPE)); JSType autoboxedType = type.isBoxableScalar() ? type.autoboxesTo() : type; boolean isIterable = autoboxedType.isSubtypeOf(getNativeType(ITERABLE_TYPE)); boolean isAsyncIterable = autoboxedType.isSubtypeOf(getNativeType(ASYNC_ITERABLE_TYPE));
/** * 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; }
JSType autobox = type == null ? null : type.autoboxesTo(); result = autobox == null
private void recordPrototypePropUse(Node n) { Preconditions.checkArgument(n.isGetProp()); Node instance = n.getFirstChild(); JSType instanceType = getType(instance); JSType boxedType = instanceType.autoboxesTo(); instanceType = boxedType != null ? boxedType : instanceType; // Retrieves the property. ObjectType objType = instanceType.toObjectType(); Preconditions.checkState(objType != null); if (!isExtern) { // Don't count reference in extern as a use. Reference ref = new Reference(n); FunctionType constructor = objType.getConstructor(); if (constructor != null) { String propName = n.getLastChild().getString(); if (!constructor.getPrototype().hasOwnProperty(propName)) { recordSuperClassPrototypePropUse(constructor, propName, ref); } // TODO(user): TightenType can help a whole lot here. recordSubclassPrototypePropUse(constructor, propName, ref); } else { recordUnknownUse(n); } } }
? globalScope.getSlot("Function") : globalScope.getQualifiedSlot("Function.prototype"); } else if (type.autoboxesTo() != null) { return getSymbolForTypeHelper(type.autoboxesTo(), linkToCtor); } else { return null;
globalScope.getSlot("Function") : globalScope.getQualifiedSlot("Function.prototype"); } else if (type.autoboxesTo() != null) { return getSymbolForTypeHelper(type.autoboxesTo(), linkToCtor); } else { return null;
if (type.autoboxesTo() != null) { foundType = getTypeWithProperty(field, type.autoboxesTo()); gtwpCachePut(field, type, foundType == null ? BOTTOM_OBJECT : foundType); return foundType;