ObjectType getPrototypeObjectType(ObjectType objectType) { checkNotNull(objectType); if (objectType.isUnknownType()) { // Calling getImplicitPrototype() on the unknown type returns `null`, but we want // the prototype of an unknown type to also be unknown. // TODO(bradfordcsmith): Can we fix this behavior of the unknown type? return objectType; } else { return checkNotNull(objectType.getImplicitPrototype(), "null prototype: %s", objectType); } }
@Override public boolean hasProperty(String propertyName) { // Unknown types have all properties. return isEmptyType() || isUnknownType() || getSlot(propertyName) != null; }
private boolean implicitPrototypeChainIsUnknown() { ObjectType p = getImplicitPrototype(); while (p != null) { if (p.isUnknownType()) { return true; } p = p.getImplicitPrototype(); } return false; }
private void finishPropertyContinuations() { ObjectType referencedObjType = getReferencedObjTypeInternal(); if (referencedObjType != null && !referencedObjType.isUnknownType() && propertyContinuations != null) { for (PropertyContinuation c : propertyContinuations) { c.commit(this); } } propertyContinuations = null; }
private void finishPropertyContinuations() { ObjectType referencedObjType = getReferencedObjTypeInternal(); if (referencedObjType != null && !referencedObjType.isUnknownType() && propertyContinuations != null) { for (PropertyContinuation c : propertyContinuations) { c.commit(this); } } propertyContinuations = null; }
/** * We treat this as the unknown type if any of its implicit prototype * properties is unknown. */ @Override public boolean isUnknownType() { // If the object is unknown now, check the supertype again, // because it might have been resolved since the last check. if (unknown) { ObjectType implicitProto = getImplicitPrototype(); if (implicitProto == null || implicitProto.isNativeObjectType()) { unknown = false; for (ObjectType interfaceType : getCtorExtendedInterfaces()) { if (interfaceType.isUnknownType()) { unknown = true; break; } } } else { unknown = implicitProto.isUnknownType(); } } return unknown; }
@Override public boolean apply(JSType type) { ObjectType objectType = ObjectType.cast(type); if (objectType == null) { reportError(BAD_IMPLEMENTED_TYPE, fnName); return false; } else if (objectType.isEmptyType()) { reportWarning(RESOLVED_TAG_EMPTY, "@implements", fnName); return false; } else if (objectType.isUnknownType()) { if (hasMoreTagsToResolve(objectType)) { return true; } else { reportWarning(RESOLVED_TAG_EMPTY, "@implements", fnName); return false; } } else { return true; } } }
@Override public boolean apply(JSType type) { ObjectType objectType = ObjectType.cast(type); if (objectType == null) { reportError(BAD_IMPLEMENTED_TYPE, fnName); return false; } else if (objectType.isEmptyType()) { reportWarning(RESOLVED_TAG_EMPTY, "@implements", fnName); return false; } else if (objectType.isUnknownType()) { if (hasMoreTagsToResolve(objectType)) { return true; } else { reportWarning(RESOLVED_TAG_EMPTY, "@implements", fnName); return false; } } else { return true; } } }
@Override public HasPropertyKind getPropertyKind(String propertyName, boolean autobox) { // Unknown types have all properties. return HasPropertyKind.of(isEmptyType() || isUnknownType() || getSlot(propertyName) != null); }
private JSType applyCommonRestriction(JSType type) { if (target.isUnknownType()) { return type; } FunctionType funcTarget = target.toMaybeFunctionType(); if (funcTarget.hasInstanceType()) { return type.getGreatestSubtype(funcTarget.getInstanceType()); } return null; } }
@Override public JSType caseUnionType(UnionType type) { if (target.isUnknownType()) { return type; } FunctionType funcTarget = target.toMaybeFunctionType(); if (funcTarget.hasInstanceType()) { return type.getRestrictedUnion(funcTarget.getInstanceType()); } return null; }
@Override public JSType caseUnionType(UnionType type) { if (target.isUnknownType()) { return type; } FunctionType funcTarget = target.toMaybeFunctionType(); if (funcTarget.hasInstanceType()) { return type.getRestrictedUnion(funcTarget.getInstanceType()); } return null; }
private JSType applyCommonRestriction(JSType type) { if (target.isUnknownType()) { return type; } FunctionType funcTarget = target.toMaybeFunctionType(); if (funcTarget.hasInstanceType()) { return type.getGreatestSubtype(funcTarget.getInstanceType()); } return null; } }
@Override public JSType caseObjectType(ObjectType type) { if (target.isUnknownType()) { return type; } FunctionType funcTarget = target.toMaybeFunctionType(); if (funcTarget.hasInstanceType()) { if (type.isSubtypeOf(funcTarget.getInstanceType())) { return null; } return type; } return null; }
@Override public JSType caseObjectType(ObjectType type) { if (target.isUnknownType()) { return type; } FunctionType funcTarget = target.toMaybeFunctionType(); if (funcTarget.hasInstanceType()) { if (type.isSubtype(funcTarget.getInstanceType())) { return null; } return type; } return null; }
private JSType evalRecordType(Node ttlAst, NameResolver nameResolver) { int paramCount = getCallParamCount(ttlAst); ImmutableList.Builder<ObjectType> recTypesBuilder = new ImmutableList.Builder<>(); for (int i = 0; i < paramCount; i++) { JSType type = evalRecordParam(getCallArgument(ttlAst, i), nameResolver); // Check that each parameter evaluates to an object ObjectType objType = type.toMaybeObjectType(); if (objType == null || objType.isUnknownType()) { reportWarning(ttlAst, RECPARAM_INVALID, type.toString()); return getUnknownType(); } JSType recType = this.registry.buildRecordTypeFromObject(objType); if (!recType.isEquivalentTo(getObjectType())) { recTypesBuilder.add(recType.toMaybeObjectType()); } } return joinRecordTypes(recTypesBuilder.build()); }
private JSType evalRecordType(Node ttlAst, NameResolver nameResolver) { int paramCount = getCallParamCount(ttlAst); ImmutableList.Builder<RecordType> recTypesBuilder = new ImmutableList.Builder<RecordType>(); for (int i = 0; i < paramCount; i++) { JSType type = evalRecordParam(getCallArgument(ttlAst, i), nameResolver); // Check that each parameter evaluates to an object ObjectType objType = type.toObjectType(); if (objType == null || objType.isUnknownType()) { reportWarning(ttlAst, RECPARAM_INVALID, type.toString()); return getUnknownType(); } JSType recType = buildRecordTypeFromObject(objType); if (!recType.isEquivalentTo(getObjectType())) { recTypesBuilder.add(recType.toMaybeRecordType()); } } return joinRecordTypes(recTypesBuilder.build()); }
@Override public boolean apply(JSType type) { ObjectType objectType = ObjectType.cast(type); if (objectType == null) { reportWarning(EXTENDS_NON_OBJECT, formatFnName(), type.toString()); return false; } else if (objectType.isEmptyType()) { reportWarning(RESOLVED_TAG_EMPTY, "@extends", formatFnName()); return false; } else if (objectType.isUnknownType()) { if (hasMoreTagsToResolve(objectType)) { return true; } else { reportWarning(RESOLVED_TAG_EMPTY, "@extends", fnName); return false; } } else { return true; } } }
@Override public boolean apply(JSType type) { ObjectType objectType = ObjectType.cast(type); if (objectType == null) { reportWarning(EXTENDS_NON_OBJECT, formatFnName(), type.toString()); return false; } if (objectType.isEmptyType()) { reportWarning(RESOLVED_TAG_EMPTY, "@extends", formatFnName()); return false; } if (objectType.isUnknownType()) { if (hasMoreTagsToResolve(objectType) || type.isTemplateType()) { return true; } else { reportWarning(RESOLVED_TAG_EMPTY, "@extends", fnName); return false; } } return true; } }
/** 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; }