void collectPropertyNames(Set<String> props) { props.addAll(properties.keySet()); PropertyMap primaryParent = getPrimaryParent(); if (primaryParent != null) { primaryParent.collectPropertyNames(props); } for (PropertyMap p : getSecondaryParents()) { if (p != null) { p.collectPropertyNames(props); } } }
Property getSlot(String name) { if (properties.containsKey(name)) { return properties.get(name); } PropertyMap primaryParent = getPrimaryParent(); if (primaryParent != null) { Property prop = primaryParent.getSlot(name); if (prop != null) { return prop; } } for (PropertyMap p : getSecondaryParents()) { if (p != null) { Property prop = p.getSlot(name); if (prop != null) { return prop; } } } return null; }
/** * Returns the property map that manages the set of properties for an object. */ PropertyMap getPropertyMap() { return PropertyMap.immutableEmptyMap(); }
int getPropertiesCount() { PropertyMap primaryParent = getPrimaryParent(); if (primaryParent == null) { return this.properties.size(); } Set<String> props = new HashSet<>(); collectPropertyNames(props); return props.size(); }
Property getSlot(String name) { Property prop = properties.get(name); if (prop != null) { return prop; } PropertyMap primaryParent = getPrimaryParent(); if (primaryParent != null) { prop = primaryParent.getSlot(name); if (prop != null) { return prop; } } for (ObjectType o : getSecondaryParentObjects()) { PropertyMap p = o.getPropertyMap(); if (p != null) { prop = p.getSlot(name); if (prop != null) { return prop; } } } return null; }
/** * Creates an object type, allowing specification of the implicit prototype, * whether the object is native, and any templatized types. */ PrototypeObjectType(JSTypeRegistry registry, String className, ObjectType implicitPrototype, boolean nativeType, TemplateTypeMap templateTypeMap, boolean anonymousType) { super(registry, templateTypeMap); this.properties = new PropertyMap(); this.properties.setParentSource(this); this.className = className; this.nativeType = nativeType; this.anonymousType = anonymousType; if (nativeType || implicitPrototype != null) { setImplicitPrototype(implicitPrototype); } else { setImplicitPrototype( registry.getNativeObjectType(JSTypeNative.OBJECT_TYPE)); } }
private void collectPropertyNamesHelper( Set<String> props, Set<PropertyMap> cache) { if (!cache.add(this)) { return; } props.addAll(properties.keySet()); PropertyMap primaryParent = getPrimaryParent(); if (primaryParent != null) { primaryParent.collectPropertyNamesHelper(props, cache); } for (ObjectType o : getSecondaryParentObjects()) { PropertyMap p = o.getPropertyMap(); if (p != null) { p.collectPropertyNamesHelper(props, cache); } } }
@Override public void setPropertyNode(String propertyName, Node defSite) { Property property = properties.getOwnProperty(propertyName); if (property != null) { property.setNode(defSite); } }
/** * Returns the names of all the properties directly on this type. * * Overridden by FunctionType to add "prototype". */ public Set<String> getOwnPropertyNames() { // TODO(sdh): ObjectType specifies that this should include prototype properties, // but currently it does not. Check if this is a constructor and add them, but // this could possibly break things so it should be done separately. return getPropertyMap().getOwnPropertyNames(); }
/** * Gets the number of properties of this object. */ public final int getPropertiesCount() { return getPropertyMap().getPropertiesCount(); }
@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; }
/** * Default getSlot implementation. This gets overridden by FunctionType * for lazily-resolved prototypes. */ public Property getSlot(String name) { return getPropertyMap().getSlot(name); }
/** * Adds any properties defined on this type or its supertypes to the set. */ final void collectPropertyNames(Set<String> props) { getPropertyMap().collectPropertyNames(props); }
@Override public boolean removeProperty(String name) { return properties.removeProperty(name); }
int getPropertiesCount() { PropertyMap primaryParent = getPrimaryParent(); if (primaryParent == null) { return this.properties.size(); } Set<String> props = new HashSet<String>(); collectPropertyNames(props); return props.size(); }
/** * Creates an object type, allowing specification of the implicit prototype, * whether the object is native, and any templatized types. */ private PrototypeObjectType(JSTypeRegistry registry, String className, ObjectType implicitPrototype, boolean nativeType, TemplateTypeMap templateTypeMap, boolean anonymousType) { super(registry, templateTypeMap); this.properties = new PropertyMap(); this.properties.setParentSource(this); this.className = className; this.nativeType = nativeType; this.anonymousType = anonymousType; if (nativeType || implicitPrototype != null) { setImplicitPrototype(implicitPrototype); } else { setImplicitPrototype(registry.getNativeObjectType(JSTypeNative.OBJECT_TYPE)); } }
@Override public void setPropertyNode(String propertyName, Node defSite) { Property property = properties.getOwnProperty(propertyName); if (property != null) { property.setNode(defSite); } }
/** * Returns the names of all the properties directly on this type. * * Overridden by FunctionType to add "prototype". */ public Set<String> getOwnPropertyNames() { return getPropertyMap().getOwnPropertyNames(); }
/** * Gets the number of properties of this object. */ public int getPropertiesCount() { return getPropertyMap().getPropertiesCount(); }
@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; }