/** * INVARIANT: {@code hasReferenceName()} is true if and only if {@code getReferenceName()} returns * a non-null string. * * @return true if the object is named, false if it is anonymous */ public final boolean hasReferenceName() { return getReferenceName() != null; }
@Override public String getReferenceName() { return referencedObjType == null ? "" : referencedObjType.getReferenceName(); }
@Override public String getReferenceName() { return referencedObjType == null ? "" : referencedObjType.getReferenceName(); }
/** * Tells the type system that {@code type} implements interface {@code * interfaceInstance}. * {@code inter} must be an ObjectType for the instance of the interface as it * could be a named type and not yet have the constructor. */ void registerTypeImplementingInterface( FunctionType type, ObjectType interfaceInstance) { interfaceToImplementors.put(interfaceInstance.getReferenceName(), type); }
/** * Returns a collection of types that directly implement {@code * interfaceInstance}. Subtypes of implementing types are not guaranteed to * be returned. {@code interfaceInstance} must be an ObjectType for the * instance of the interface. */ public Collection<FunctionType> getDirectImplementors(ObjectType interfaceInstance) { return interfaceToImplementors.get(interfaceInstance.getReferenceName()); }
/** * Tells the type system that {@code type} implements interface {@code * interfaceInstance}. * {@code inter} must be an ObjectType for the instance of the interface as it * could be a named type and not yet have the constructor. */ void registerTypeImplementingInterface( FunctionType type, ObjectType interfaceInstance) { interfaceToImplementors.put(interfaceInstance.getReferenceName(), type); }
/** * Returns a collection of types that directly implement {@code * interfaceInstance}. Subtypes of implementing types are not guaranteed to * be returned. {@code interfaceInstance} must be an ObjectType for the * instance of the interface. */ public Collection<FunctionType> getDirectImplementors( ObjectType interfaceInstance) { return interfaceToImplementors.get(interfaceInstance.getReferenceName()); }
static int nominalHashCode(ObjectType type) { checkState(type.hasReferenceName()); String name = checkNotNull(type.getReferenceName()); return name.hashCode(); }
/** * Determines if the supplied type should be checked as a bivariant * templatized type rather the standard invariant templatized type * rules. */ static boolean isBivariantType(JSType type) { ObjectType objType = type.toObjectType(); return objType != null // && objType.isNativeObjectType() && BIVARIANT_TYPES.contains(objType.getReferenceName()); }
private static boolean isReferenceNameOf(ObjectType type, String name) { return type.hasReferenceName() && type.getReferenceName().equals(name); } }
/** * Determines if the specified type is exempt from standard invariant * templatized typing rules. */ static boolean isExemptFromTemplateTypeInvariance(JSType type) { ObjectType objType = type.toObjectType(); return objType == null || COVARIANT_TYPES.contains(objType.getReferenceName()); }
private static boolean isInstanceOfObject(JSType type) { // Some type whose class is Object ObjectType obj = type.toMaybeObjectType(); if (obj != null && obj.isNativeObjectType() && "Object".equals(obj.getReferenceName())) { return true; } return type.isRecordType() || type.isLiteralObject(); }
private void declareNativeFunctionType(TypedScope scope, JSTypeNative tId) { FunctionType t = typeRegistry.getNativeFunctionType(tId); declareNativeType(scope, t.getInstanceType().getReferenceName(), t); declareNativeType( scope, t.getPrototype().getReferenceName(), t.getPrototype()); }
@Nullable private String deepestResolvedTypeNameOf(ObjectType objType) { if (!objType.isResolved() || !(objType instanceof ProxyObjectType)) { return objType.getReferenceName(); } ObjectType internal = ((ProxyObjectType) objType).getReferencedObjTypeInternal(); return (internal != null && internal.isNominalType()) ? deepestResolvedTypeNameOf(internal) : null; }
private void declareNativeFunctionType(TypedScope scope, JSTypeNative tId) { FunctionType t = typeRegistry.getNativeFunctionType(tId); declareNativeType(scope, t.getInstanceType().getReferenceName(), t); declareNativeType( scope, t.getPrototype().getReferenceName(), t.getPrototype()); }
private String getConcreteNominalTypeName(ObjectType objType) { if (objType instanceof ProxyObjectType) { ObjectType internal = ((ProxyObjectType) objType) .getReferencedObjTypeInternal(); if (internal != null && internal.isNominalType()) { return getConcreteNominalTypeName(internal); } } return objType.getReferenceName(); }
/** Gets the symbol for the given constructor or interface. */ public Symbol getSymbolDeclaredBy(FunctionType fn) { checkState(fn.isConstructor() || fn.isInterface()); ObjectType instanceType = fn.getInstanceType(); return getSymbolForName(fn.getSource(), instanceType.getReferenceName()); }
/** Gets the symbol for the prototype of the given constructor or interface. */ public Symbol getSymbolForInstancesOf(FunctionType fn) { checkState(fn.isConstructor() || fn.isInterface()); ObjectType pType = fn.getPrototype(); return getSymbolForName(fn.getSource(), pType.getReferenceName()); }
/** * Gets the symbol for the given constructor or interface. */ public Symbol getSymbolDeclaredBy(FunctionType fn) { Preconditions.checkState(fn.isConstructor() || fn.isInterface()); ObjectType instanceType = fn.getInstanceType(); return getSymbolForName(fn.getSource(), instanceType.getReferenceName()); }
/** * Gets the symbol for the prototype of the given constructor or interface. */ public Symbol getSymbolForInstancesOf(FunctionType fn) { Preconditions.checkState(fn.isConstructor() || fn.isInterface()); ObjectType pType = fn.getPrototype(); return getSymbolForName(fn.getSource(), pType.getReferenceName()); }