@Override public final boolean isNativeObjectType() { return referencedObjType == null ? false : referencedObjType.isNativeObjectType(); }
@Override public boolean isNativeObjectType() { return referencedObjType == null ? false : referencedObjType.isNativeObjectType(); }
private static boolean isInstanceOfObject(JSType type) { // Some type whose class is Object ObjectType obj = type.toMaybeObjectType(); if (obj != null && obj.isNativeObjectType() && "Object".equals(obj.getReferenceName())) { return true; } return type.isRecordType() || type.isLiteralObject(); }
current != null && !current.isNativeObjectType() && propertyNames.size() <= MAX_PRETTY_PRINTED_PROPERTIES; current = current.getImplicitPrototype()) {
current != null && !current.isNativeObjectType() && propertyNames.size() <= MAX_PRETTY_PRINTED_PROPERTIES; current = current.getImplicitPrototype()) {
/** @return return an immutable list of template types of the given builtin. */ public ImmutableList<TemplateType> maybeGetTemplateTypesOfBuiltin(String fnName) { JSType type = getType(null, fnName); ObjectType objType = type == null ? null : type.toObjectType(); if (objType != null && objType.isNativeObjectType()) { ImmutableList<TemplateType> templateKeys = objType.getTemplateTypeMap().getUnfilledTemplateKeys(); return templateKeys; } return null; }
/** * Checks whether current type is Object type with non-stringifable key. */ private boolean isObjectTypeWithNonStringifiableKey(JSType type) { if (!type.isTemplatizedType()) { return false; } TemplatizedType templatizedType = type.toMaybeTemplatizedType(); if (templatizedType.getReferencedType().isNativeObjectType() && templatizedType.getTemplateTypes().size() > 1) { return !isReasonableObjectPropertyKey(templatizedType.getTemplateTypes().get(0)); } else { return false; } }
/** * Checks whether current type is Object type with non-stringifable key. */ private boolean isObjectTypeWithNonStringifiableKey(JSType type) { if (!type.isTemplatizedType()) { return false; } TemplatizedType templatizedType = type.toMaybeTemplatizedType(); if (templatizedType.getReferencedType().isNativeObjectType() && templatizedType.getTemplateTypes().size() > 1) { return !isStringifiable(templatizedType.getTemplateTypes().get(0)); } else { return false; } }
/** * Checks whether class has overridden toString() method. All objects has native toString() * method but we ignore it as it is not useful so we need user-provided toString() method. */ private boolean classHasToString(ObjectType type) { Property toStringProperty = type.getOwnSlot("toString"); if (toStringProperty != null) { return toStringProperty.getType().isFunctionType(); } ObjectType parent = type.getImplicitPrototype(); if (parent != null && !parent.isNativeObjectType()) { return classHasToString(parent); } return false; } }
/** * Returns true for types that are class like, i.e. that define a constructor or interface, but * excludes typedefs and the built-in constructor functions such as {@code Function}. */ private boolean isClassLike(JSType propType) { // Confusingly, the typedef type returns true on isConstructor checks, so we need to filter // the NoType through this utility method. return !isTypedef(propType) && (propType.isConstructor() || propType.isInterface()) // "Function" is a constructor, but does not define a new type for our purposes. && !propType.toMaybeObjectType().isNativeObjectType() && !propType.isFunctionPrototypeType(); }
/** * Checks whether class has overridden toString() method. All objects has native toString() * method but we ignore it as it is not useful so we need user-provided toString() method. */ private boolean classHasToString(ObjectType type) { Property toStringProperty = type.getOwnSlot("toString"); if (toStringProperty != null) { return toStringProperty.getType().isFunctionType(); } ObjectType parent = type.getParentScope(); if (parent != null && !parent.isNativeObjectType()) { return classHasToString(parent); } return false; } }
/** * 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; }
/** * 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; }
/** * Declares a property on its owner, if necessary. * @return True if a property was declared. */ private boolean ensurePropertyDeclaredHelper( Node getprop, ObjectType objectType) { String propName = getprop.getLastChild().getString(); String qName = getprop.getQualifiedName(); if (qName != null) { TypedVar var = syntacticScope.getVar(qName); if (var != null && !var.isTypeInferred()) { // Handle normal declarations that could not be addressed earlier. if (propName.equals("prototype") || // Handle prototype declarations that could not be addressed earlier. (!objectType.hasOwnProperty(propName) && (!objectType.isInstanceType() || (var.isExtern() && !objectType.isNativeObjectType())))) { return objectType.defineDeclaredProperty( propName, var.getType(), getprop); } } } return false; }
/** * Declares a property on its owner, if necessary. * * @return True if a property was declared. */ private boolean ensurePropertyDeclaredHelper( Node getprop, ObjectType objectType, FlowScope scope) { if (getprop.isQualifiedName()) { String propName = getprop.getLastChild().getString(); String qName = getprop.getQualifiedName(); TypedVar var = getDeclaredVar(scope, qName); if (var != null && !var.isTypeInferred()) { // Handle normal declarations that could not be addressed earlier. if (propName.equals("prototype") || // Handle prototype declarations that could not be addressed earlier. (!objectType.hasOwnProperty(propName) && (!objectType.isInstanceType() || (var.isExtern() && !objectType.isNativeObjectType())))) { return objectType.defineDeclaredProperty( propName, var.getType(), getprop); } } } return false; }
void declarePropertyIfNamespaceType( NodeTraversal t, ObjectType ownerType, Node getpropNode, JSType valueType) { checkState(getpropNode.isGetProp()); String propName = getpropNode.getLastChild().getString(); // Only declare this as an official property if it has not been // declared yet. if (ownerType.hasOwnProperty(propName) && !ownerType.isPropertyTypeInferred(propName)) { return; } // Define the property if any of the following are true: // (1) it's a non-native extern type. Native types are excluded here because we don't // want externs of the form "/** @type {!Object} */ var api = {}; api.foo;" to // cause a property "foo" to be declared on Object. // (2) it's a non-instance type. This primarily covers static properties on // constructors (which are FunctionTypes, not InstanceTypes). // (3) it's an assignment to 'this', which covers instance properties assigned in // constructors or other methods. boolean isNonNativeExtern = t.getInput() != null && t.getInput().isExtern() && !ownerType.isNativeObjectType(); if (isNonNativeExtern || !ownerType.isInstanceType() || getpropNode.getFirstChild().isThis()) { // If the property is undeclared or inferred, declare it now. ownerType.defineDeclaredProperty(propName, valueType, getpropNode); } } } // end AbstractScopeBuilder
/** * Handle cases #1 and #3 in the class doc. */ private static void attachJSDocInfoToNominalTypeOrShape( ObjectType objType, JSDocInfo docInfo, @Nullable String qName) { if (objType.isConstructor() || objType.isEnumType() || objType.isInterface()) { // Named types. if (objType.hasReferenceName() && objType.getReferenceName().equals(qName)) { objType.setJSDocInfo(docInfo); if (objType.isConstructor() || objType.isInterface()) { JSType.toMaybeFunctionType(objType).getInstanceType().setJSDocInfo(docInfo); } else if (objType instanceof EnumType) { ((EnumType) objType).getElementsType().setJSDocInfo(docInfo); } } } else if (!objType.isNativeObjectType() && objType.isFunctionType()) { // Structural functions. objType.setJSDocInfo(docInfo); } } }
/** Handle cases #1 and #3 in the class doc. */ private static void attachJSDocInfoToNominalTypeOrShape( ObjectType objType, JSDocInfo docInfo, @Nullable String qName) { if (objType.isConstructor() || objType.isInterface()) { if (!isReferenceNameOf(objType, qName)) { return; } objType.setJSDocInfo(docInfo); JSType.toMaybeFunctionType(objType).getInstanceType().setJSDocInfo(docInfo); } else if (objType.isEnumType()) { // Given: `/** @enum {number} */ MyEnum = { FOO: 0 };` // Then: typeOf(MyEnum).referenceName() == "enum{MyEnum}" // Then: typeOf(MyEnum.FOO).referenceName() == "MyEnum" ObjectType elementType = objType.toMaybeEnumType().getElementsType(); if (!isReferenceNameOf(elementType, qName)) { return; } objType.setJSDocInfo(docInfo); elementType.setJSDocInfo(docInfo); } else if (!objType.isNativeObjectType() && objType.isFunctionType()) { // Anonymous function types identified by their parameter and return types. Remember there can // be many unique but equal instances. objType.setJSDocInfo(docInfo); } }
!functionType.getTypeOfThis().isUnknownType() && !(functionType.getTypeOfThis().toObjectType() != null && functionType.getTypeOfThis().toObjectType().isNativeObjectType()) && !(child.isGetElem() || child.isGetProp())) {
&& !functionType.getTypeOfThis().isUnknownType() && !(functionType.getTypeOfThis().toObjectType() != null && functionType.getTypeOfThis().toObjectType().isNativeObjectType()) && !(child.isGetElem() || child.isGetProp())) { report(t, n, EXPECTED_THIS_TYPE, functionType.toString());