/** * Whether the given property is declared on this object. */ final boolean hasOwnDeclaredProperty(String name) { return hasOwnProperty(name) && isPropertyTypeDeclared(name); }
/** * Whether the given property is declared on this object. */ final boolean hasOwnDeclaredProperty(String name) { return hasOwnProperty(name) && isPropertyTypeDeclared(name); }
/** * Look up the visibility of the overridden property recursively. In Closure, a child class can * override an implicit public property with tighter visibility, but it is not allowed in * TypeScript. So clutz ignores and emits it as a public property. */ private boolean isProtectedProperty(ObjectType prototype, final String propName) { Visibility visibility = Visibility.INHERITED; while (prototype != null) { if (prototype.hasOwnProperty(propName)) { final JSDocInfo jsDocInfo = prototype.getOwnPropertyJSDocInfo(propName); if (jsDocInfo != null) { visibility = jsDocInfo.getVisibility(); } } prototype = prototype.getImplicitPrototype(); } return visibility == Visibility.PROTECTED; }
/** * Look for the super class implementation up the tree. */ private void recordSuperClassPrototypePropUse( FunctionType classType, String prop, Reference ref) { FunctionType superClass = classType.getSuperClassConstructor(); while (superClass != null) { if (superClass.getPrototype().hasOwnProperty(prop)) { graph.connect(getNamedContainingFunction(), ref, graph.defineNameIfNotExists( superClass.getReferenceName() + ".prototype." + prop, false)); return; } else { superClass = superClass.getSuperClassConstructor(); } } }
/** * Conservatively assumes that all subclass implementation of this property * might be called. */ private void recordSubclassPrototypePropUse( FunctionType classType, String prop, Reference ref) { if (classType.getPrototype().hasOwnProperty(prop)) { graph.connect(getNamedContainingFunction(), ref, graph.defineNameIfNotExists( classType.getReferenceName() + ".prototype." + prop, false)); } if (classType.getSubTypes() != null) { for (FunctionType subclass : classType.getSubTypes()) { recordSubclassPrototypePropUse(subclass, prop, ref); } } }
/** * 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; }
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); } } }
/** * 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
if (objType.hasOwnProperty(field)) { foundType = objType; if (maybeType != null && maybeType.hasOwnProperty(field)) { foundType = maybeType;
if (objType.hasOwnProperty(field)) { foundType = objType; if (maybeType != null && maybeType.hasOwnProperty(field)) { foundType = maybeType;
} else { while (objectType != null && !objectType.hasOwnProperty(propName)) { objectType = objectType.getImplicitPrototype();
Set<String> names = paramRecordType.getPropertyNames(); for (String name : names) { if (paramRecordType.hasOwnProperty(name) && argObjectType.hasProperty(name)) { maybeResolveTemplatedType(paramRecordType.getPropertyType(name), argObjectType.getPropertyType(name), resolvedTypes, seenTypes);
boolean declaredLocally = ctorType.isConstructor() && (ctorType.getPrototype().hasOwnProperty(propertyName) || ctorType.getInstanceType().hasOwnProperty(propertyName)); if (!declaredOverride && superClassHasDeclaredProperty
if ((!ownerType.hasOwnProperty(propName) || ownerType.isPropertyTypeInferred(propName)) && ((isExtern && !ownerType.isNativeObjectType()) ||
boolean declaredLocally = ctorType.isConstructor() && (ctorType.getPrototype().hasOwnProperty(propertyName) || ctorType.getInstanceType().hasOwnProperty(propertyName)); if (reportMissingOverride.isOn() && !declaredOverride
if (owningType != null) { String propName = n.getString(); if (owningType.hasOwnProperty(propName)) { owningType.setPropertyJSDocInfo(propName, docInfo); if (lhsType.hasOwnProperty(propName)) { lhsType.setPropertyJSDocInfo(propName, docInfo);
} else { while (objectType != null && !objectType.hasOwnProperty(propName)) { objectType = objectType.getImplicitPrototype();
Set<String> names = paramRecordType.getPropertyNames(); for (String name : names) { if (paramRecordType.hasOwnProperty(name) && argObjectType.hasProperty(name)) { maybeResolveTemplatedType(paramRecordType.getPropertyType(name), argObjectType.getPropertyType(name), resolvedTypes, seenTypes);
if (owningType.hasOwnProperty(propName)) { owningType.setPropertyJSDocInfo(propName, typeDoc); if (lhsType.hasOwnProperty(propName)) { lhsType.setPropertyJSDocInfo(propName, typeDoc);