use of com.google.javascript.rhino.ObjectTypeI in project closure-compiler by google.
the class AmbiguateProperties method addRelatedInstance.
/**
* Adds the instance of the given constructor, its implicit prototype and all
* its related types to the given bit set.
*/
private void addRelatedInstance(FunctionTypeI constructor, JSTypeBitSet related) {
checkArgument(constructor.hasInstanceType(), "Constructor %s without instance type.", constructor);
ObjectTypeI instanceType = constructor.getInstanceType();
related.set(getIntForType(instanceType.getPrototypeObject()));
computeRelatedTypes(instanceType);
related.or(relatedBitsets.get(instanceType));
}
use of com.google.javascript.rhino.ObjectTypeI in project closure-compiler by google.
the class DisambiguateProperties method recordInterfaces.
/**
* Records that this property could be referenced from any interface that
* this type inherits from.
*
* If the property p is defined only on a subtype of constructor, then this
* method has no effect. But we tried modifying getTypeWithProperty to tell us
* when the returned type is a subtype, and then skip those calls to
* recordInterface, and there was no speed-up.
* And it made the code harder to understand, so we don't do it.
*/
private void recordInterfaces(FunctionTypeI constructor, TypeI relatedType, Property p) {
Iterable<ObjectTypeI> interfaces = ancestorInterfaces.get(constructor);
if (interfaces == null) {
interfaces = constructor.getAncestorInterfaces();
ancestorInterfaces.put(constructor, interfaces);
}
for (ObjectTypeI itype : interfaces) {
TypeI top = getTypeWithProperty(p.name, itype);
if (top != null) {
p.addType(itype, relatedType);
}
// If this interface invalidated this property, return now.
if (p.skipRenaming) {
return;
}
}
}
use of com.google.javascript.rhino.ObjectTypeI in project closure-compiler by google.
the class DisambiguateProperties method getTypeAlternatives.
/**
* Returns the alternatives if this is a type that represents multiple
* types, and null if not. Union and interface types can correspond to
* multiple other types.
*/
private Iterable<? extends TypeI> getTypeAlternatives(TypeI type) {
if (type.isUnionType()) {
return type.getUnionMembers();
} else {
ObjectTypeI objType = type.toMaybeObjectType();
FunctionTypeI constructor = objType != null ? objType.getConstructor() : null;
if (constructor != null && constructor.isInterface()) {
List<TypeI> list = new ArrayList<>();
for (FunctionTypeI impl : constructor.getDirectSubTypes()) {
list.add(impl.getInstanceType());
}
return list.isEmpty() ? null : list;
} else {
return null;
}
}
}
use of com.google.javascript.rhino.ObjectTypeI in project closure-compiler by google.
the class CheckAccessControls method checkConstantProperty.
/**
* Determines whether the given constant property got reassigned
* @param t The current traversal.
* @param getprop The getprop node.
*/
private void checkConstantProperty(NodeTraversal t, Node getprop) {
// Check whether the property is modified
Node parent = getprop.getParent();
boolean isDelete = parent.isDelProp();
if (!(NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == getprop) && !parent.isInc() && !parent.isDec() && !isDelete) {
return;
}
ObjectTypeI objectType = castToObject(dereference(getprop.getFirstChild().getTypeI()));
String propertyName = getprop.getLastChild().getString();
boolean isConstant = isPropertyDeclaredConstant(objectType, propertyName);
// Check whether constant properties are reassigned
if (isConstant) {
JSDocInfo info = parent.getJSDocInfo();
if (info != null && info.getSuppressions().contains("const")) {
return;
}
if (isDelete) {
compiler.report(t.makeError(getprop, CONST_PROPERTY_DELETED, propertyName));
return;
}
// the type is being inspected incorrectly.
if (objectType == null || (objectType.isFunctionType() && !objectType.toMaybeFunctionType().isConstructor())) {
return;
}
ObjectTypeI oType = objectType;
while (oType != null) {
if (initializedConstantProperties.containsEntry(oType, propertyName) || initializedConstantProperties.containsEntry(getCanonicalInstance(oType), propertyName)) {
compiler.report(t.makeError(getprop, CONST_PROPERTY_REASSIGNED_VALUE, propertyName));
break;
}
oType = oType.getPrototypeObject();
}
initializedConstantProperties.put(objectType, propertyName);
// Add the prototype when we're looking at an instance object
if (objectType.isInstanceType()) {
ObjectTypeI prototype = objectType.getPrototypeObject();
if (prototype != null && prototype.hasProperty(propertyName)) {
initializedConstantProperties.put(prototype, propertyName);
}
}
}
}
use of com.google.javascript.rhino.ObjectTypeI in project closure-compiler by google.
the class Es6ToEs3Util method createGenericType.
/**
* Returns the TypeI as specified by the typeName and instantiated by the typeArg.
* Returns null if shouldCreate is false.
*/
static TypeI createGenericType(boolean shouldCreate, TypeIRegistry registry, JSTypeNative typeName, TypeI typeArg) {
if (!shouldCreate) {
return null;
}
ObjectTypeI genericType = (ObjectTypeI) (registry.getNativeType(typeName));
ObjectTypeI uninstantiated = genericType.getRawType();
return registry.instantiateGenericType(uninstantiated, ImmutableList.of(typeArg));
}
Aggregations