/** * Sets the source node. */ @Override public void setSource(Node source) { if (prototypeSlot != null) { // NOTE(bashir): On one hand when source is null we want to drop any // references to old nodes retained in prototypeSlot. On the other hand // we cannot simply drop prototypeSlot, so we retain all information // except the propertyNode for which we use an approximation! These // details mostly matter in hot-swap passes. if (source == null || prototypeSlot.getNode() == null) { prototypeSlot = new Property(prototypeSlot.getName(), prototypeSlot.getType(), prototypeSlot.isTypeInferred(), source); } } this.source = source; }
void putProperty(String name, Property newProp) { Property oldProp = properties.get(name); if (oldProp != null) { // This is to keep previously inferred JsDoc info, e.g., in a // replaceScript scenario. newProp.setJSDocInfo(oldProp.getJSDocInfo()); } properties.put(name, newProp); }
/** Checks whether the property was defined in the externs. */ public final boolean isPropertyInExterns(String propertyName) { Property p = getSlot(propertyName); return p == null ? false : p.isFromExterns(); }
private static ConformanceResult checkCtorProperties(ObjectType type) { for (String propertyName : type.getOwnPropertyNames()) { Property prop = type.getOwnSlot(propertyName); JSDocInfo docInfo = prop.getJSDocInfo(); Node scriptNode = getScriptNode(prop.getNode()); ConformanceResult result = visibilityAtDeclarationOrFileoverview( docInfo, scriptNode); if (result != ConformanceResult.CONFORMANCE) { return result; } } return ConformanceResult.CONFORMANCE; }
@Override JSType resolveInternal(ErrorReporter reporter) { setResolvedTypeInternal(this); ObjectType implicitPrototype = getImplicitPrototype(); if (implicitPrototype != null) { implicitPrototypeFallback = (ObjectType) implicitPrototype.resolve(reporter); FunctionType ctor = getConstructor(); if (ctor != null) { FunctionType superCtor = ctor.getSuperClassConstructor(); if (superCtor != null) { // If the super ctor of this prototype object was not known before resolution, then the // subTypes would not have been set. Update them. superCtor.addSubClassAfterResolution(ctor); } } } for (Property prop : properties.values()) { prop.setType(safeResolve(prop.getType(), reporter)); } return this; }
private void addNewPropsFromRecordType(Map<String, JSType> props, RecordType recType) { for (String newPropName : recType.getOwnPropertyNames()) { JSType newPropValue = recType.getSlot(newPropName).getType(); // Put the new property depending if it already exists in the map putNewPropInPropertyMap(props, newPropName, newPropValue); } }
/** * Gets the docInfo on the specified property on this type. This should not * be implemented recursively, as you generally need to know exactly on * which type in the prototype chain the JSDocInfo exists. */ public final JSDocInfo getOwnPropertyJSDocInfo(String propertyName) { Property p = getOwnSlot(propertyName); return p == null ? null : p.getJSDocInfo(); }
public final Node getOwnPropertyDefSite(String propertyName) { Property p = getOwnSlot(propertyName); return p == null ? null : p.getNode(); }
@Override public void setPropertyNode(String propertyName, Node defSite) { Property property = properties.getOwnProperty(propertyName); if (property != null) { property.setNode(defSite); } }
@Override boolean defineProperty(String name, JSType type, boolean inferred, Node propertyNode) { if (hasOwnDeclaredProperty(name)) { return false; } Property newProp = new Property( name, type, inferred, propertyNode); properties.putProperty(name, newProp); return true; }
@Override public void setPropertyJSDocInfo(String propertyName, JSDocInfo info) { if (info != null) { if (properties.getOwnProperty(propertyName) == null) { // If docInfo was attached, but the type of the property // was not defined anywhere, then we consider this an explicit // declaration of the property. defineInferredProperty(propertyName, getPropertyType(propertyName), null); } // The prototype property is not represented as a normal Property. // We probably don't want to attach any JSDoc to it anyway. Property property = properties.getOwnProperty(propertyName); if (property != null) { property.setJSDocInfo(info); } } }
@Override JSType resolveInternal(ErrorReporter t, StaticTypedScope<JSType> scope) { setResolvedTypeInternal(this); ObjectType implicitPrototype = getImplicitPrototype(); if (implicitPrototype != null) { implicitPrototypeFallback = (ObjectType) implicitPrototype.resolve(t, scope); FunctionType ctor = getConstructor(); if (ctor != null) { FunctionType superCtor = ctor.getSuperClassConstructor(); if (superCtor != null) { // If the super ctor of this prototype object was not known before resolution, then the // subTypes would not have been set. Update them. superCtor.addSubTypeIfNotPresent(ctor); } } } for (Property prop : properties.values()) { prop.setType(safeResolve(prop.getType(), t, scope)); } return this; }
@Override boolean defineProperty(String name, JSType type, boolean inferred, Node propertyNode) { if ("prototype".equals(name)) { ObjectType objType = type.toObjectType(); if (objType != null) { if (prototypeSlot != null && objType.isEquivalentTo(prototypeSlot.getType())) { return true; } setPrototypeBasedOn(objType, propertyNode); return true; } else { return false; } } return super.defineProperty(name, type, inferred, propertyNode); }
Node node = p.getNode(); if (node == null) { isClassType = p.getJSDocInfo().isConstructor(); } else if (isPrivateByConvention) {
/** * Gets the docInfo on the specified property on this type. This should not * be implemented recursively, as you generally need to know exactly on * which type in the prototype chain the JSDocInfo exists. */ public JSDocInfo getOwnPropertyJSDocInfo(String propertyName) { Property p = getOwnSlot(propertyName); return p == null ? null : p.getJSDocInfo(); }
/** * Gets the node corresponding to the definition of the specified property. * This could be the node corresponding to declaration of the property or the * node corresponding to the first reference to this property, e.g., * "this.propertyName" in a constructor. Note this is mainly intended to be * an estimate of where in the source code a property is defined. Sometime * the returned node is not even part of the global AST but in the AST of the * JsDoc that defines a type. * * @param propertyName the name of the property * @return the {@code Node} corresponding to the property or null. */ public Node getPropertyNode(String propertyName) { Property p = getSlot(propertyName); return p == null ? null : p.getNode(); }