use of com.google.javascript.rhino.FunctionTypeI 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.FunctionTypeI in project closure-compiler by google.
the class DevirtualizePrototypeMethods method fixFunctionType.
/**
* Creates a new type based on the original function type by
* adding the original this pointer type to the beginning of the
* argument type list and replacing the this pointer type with bottom.
*/
private void fixFunctionType(Node functionNode) {
TypeI t = functionNode.getTypeI();
if (t == null) {
return;
}
FunctionTypeI ft = t.toMaybeFunctionType();
if (ft != null) {
functionNode.setTypeI(ft.convertMethodToFunction());
}
}
use of com.google.javascript.rhino.FunctionTypeI 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.FunctionTypeI in project closure-compiler by google.
the class DisambiguateProperties method getConstructor.
private FunctionTypeI getConstructor(TypeI type) {
ObjectTypeI objType = type.toMaybeObjectType();
if (objType == null) {
return null;
}
FunctionTypeI constructor = null;
if (objType.isFunctionType()) {
constructor = objType.toMaybeFunctionType();
} else if (objType.isPrototypeObject()) {
constructor = objType.getOwnerFunction();
} else {
constructor = objType.getConstructor();
}
return constructor;
}
use of com.google.javascript.rhino.FunctionTypeI in project closure-compiler by google.
the class TypeMismatch method registerMismatch.
static void registerMismatch(List<TypeMismatch> mismatches, List<TypeMismatch> implicitInterfaceUses, TypeI found, TypeI required, JSError error) {
// Don't register a mismatch for differences in null or undefined or if the
// code didn't downcast.
found = removeNullUndefinedAndTemplates(found);
required = removeNullUndefinedAndTemplates(required);
if (found.isSubtypeOf(required) || required.isSubtypeOf(found)) {
boolean strictMismatch = !found.isSubtypeWithoutStructuralTyping(required) && !required.isSubtypeWithoutStructuralTyping(found);
if (strictMismatch && bothAreNotTypeVariables(found, required)) {
implicitInterfaceUses.add(new TypeMismatch(found, required, Suppliers.ofInstance(error)));
}
return;
}
if (bothAreNotTypeVariables(found, required)) {
mismatches.add(new TypeMismatch(found, required, Suppliers.ofInstance(error)));
}
if (found.isFunctionType() && required.isFunctionType()) {
FunctionTypeI fnTypeA = found.toMaybeFunctionType();
FunctionTypeI fnTypeB = required.toMaybeFunctionType();
Iterator<TypeI> paramItA = fnTypeA.getParameterTypes().iterator();
Iterator<TypeI> paramItB = fnTypeB.getParameterTypes().iterator();
while (paramItA.hasNext() && paramItB.hasNext()) {
TypeMismatch.registerIfMismatch(mismatches, implicitInterfaceUses, paramItA.next(), paramItB.next(), error);
}
TypeMismatch.registerIfMismatch(mismatches, implicitInterfaceUses, fnTypeA.getReturnType(), fnTypeB.getReturnType(), error);
}
}
Aggregations