/** * Returns a set of types that should be skipped given the given type. This is * necessary for interfaces, as all super interfaces must also be skipped. */ private ImmutableSet<JSType> getTypesToSkipForType(JSType type) { type = type.restrictByNotNullOrUndefined(); if (type.isUnionType()) { ImmutableSet.Builder<JSType> types = ImmutableSet.builder(); types.add(type); for (JSType alt : type.getUnionMembers()) { types.addAll(getTypesToSkipForTypeNonUnion(alt)); } return types.build(); } else if (type.isEnumElementType()) { return getTypesToSkipForType(type.getEnumeratedTypeOfEnumElement()); } return ImmutableSet.copyOf(getTypesToSkipForTypeNonUnion(type)); }
/** * Returns a set of types that should be skipped given the given type. This is * necessary for interfaces, as all super interfaces must also be skipped. */ private ImmutableSet<JSType> getTypesToSkipForType(JSType type) { type = type.restrictByNotNullOrUndefined(); if (type.isUnionType()) { ImmutableSet.Builder<JSType> types = ImmutableSet.builder(); types.add(type); for (JSType alt : type.toMaybeUnionType().getAlternates()) { types.addAll(getTypesToSkipForTypeNonUnion(alt)); } return types.build(); } else if (type.isEnumElementType()) { return getTypesToSkipForType( type.toMaybeEnumElementType().getPrimitiveType()); } return ImmutableSet.copyOf(getTypesToSkipForTypeNonUnion(type)); }
private boolean isPrivate(JSType type) { // Due to https://github.com/google/closure-compiler/issues/1975 we cannot obtain the JSDoc // for a typedef. Assume non-private as it is more common. // Closure creates a NamedType when the typedef is used in an union, eg: T | null. // Dereference the named type before checking if it is a typedef. NamedType nType = type.toMaybeNamedType(); if (typedefs.containsKey(type) || (nType != null && typedefs.containsKey(nType.getReferencedType()))) { return false; } // For unknown reasons, enum types do not keep their defining jsdoc info. if (type.isEnumType() || type.isEnumElementType()) { return isPrivate(type.getDisplayName()); } else { return isPrivate(type.getJSDocInfo()); } }
/** Invalidates the given type, so that no properties on it will be inlined or renamed. */ private Builder addType(JSType type, TypeMismatch mismatch) { type = type.restrictByNotNullOrUndefined(); if (type.isUnionType()) { for (JSType alt : type.getUnionMembers()) { addType(alt, mismatch); } } else if (type.isEnumElementType()) { // only in disamb addType(type.getEnumeratedTypeOfEnumElement(), mismatch); } else { // amb and inl both do this without the else checkState(!type.isUnionType()); types.add(type); recordInvalidation(type, mismatch); ObjectType objType = type.toMaybeObjectType(); if (objType != null) { ObjectType proto = objType.getImplicitPrototype(); if (proto != null) { types.add(proto); recordInvalidation(proto, mismatch); } if (objType.isConstructor()) { types.add(objType.toMaybeFunctionType().getInstanceType()); } else if (objType.isInstanceType()) { types.add(objType.getConstructor()); } } } return this; }
private JSType getType(String typeName) { JSType type = registry.getType(typeEnv, typeName); if (type != null) { return type; } StaticTypedSlot slot = typeEnv.getSlot(typeName); type = slot != null ? slot.getType() : null; if (type != null) { if (type.isConstructor() || type.isInterface()) { return type.toMaybeFunctionType().getInstanceType().getRawType(); } if (type.isEnumElementType()) { return type.getEnumeratedTypeOfEnumElement(); } return type; } JSDocInfo jsdoc = slot == null ? null : slot.getJSDocInfo(); if (jsdoc != null && jsdoc.hasTypedefType()) { return this.registry.evaluateTypeExpression(jsdoc.getTypedefType(), typeEnv); } return null; }
if (type.isUnknownType() && registryType != null && registryType.isEnumElementType()) { visitTypeValueAlias(symbol.getName(), (EnumElementType) registryType); return;
if (bType.isEnumElementType() || bType.isUnionType()) { return bType.testForEquality(aType);
/** * Invalidates the given type, so that no properties on it will be renamed. */ private void recordInvalidatingType(JSType type, JSError error) { type = type.restrictByNotNullOrUndefined(); if (type.isUnionType()) { for (JSType alt : type.toMaybeUnionType().getAlternatesWithoutStructuralTyping()) { recordInvalidatingType(alt, error); } } else if (type.isEnumElementType()) { recordInvalidatingType( type.toMaybeEnumElementType().getPrimitiveType(), error); } else { addInvalidatingType(type); recordInvalidationError(type, error); ObjectType objType = ObjectType.cast(type); if (objType != null && objType.getImplicitPrototype() != null) { addInvalidatingType(objType.getImplicitPrototype()); recordInvalidationError(objType.getImplicitPrototype(), error); } if (objType != null && objType.isConstructor() && objType.isFunctionType()) { addInvalidatingType(objType.toMaybeFunctionType().getInstanceType()); } } }
Boolean castCastToHelper(JSType thisType, JSType thatType) { if (thatType.isUnknownType() || thatType.isAllType() || thatType.isNoObjectType() // TODO(johnlenz): restrict to objects || thatType.isNoType()) { return true; } else if (thisType.isRecordType() || thatType.isRecordType()) { return true; // TODO(johnlenz): are there any misuses we can catch? } else if (isInterface(thisType) || isInterface(thatType)) { return true; // TODO(johnlenz): are there any misuses we can catch? } else if (thatType.isEnumElementType()) { return thisType.visit(this, thatType.toMaybeEnumElementType().getPrimitiveType()); } else if (thatType.isUnionType()) { return canCastToUnion(thisType, thatType.toMaybeUnionType()); } else if (thatType.isFunctionType()) { return canCastToFunction(thisType, thatType.toMaybeFunctionType()); } else if (thatType.isTemplatizedType()) { // TODO(johnlenz): once the templated type work is finished, // restrict the type parameters. return thisType.visit(this, thatType.toMaybeTemplatizedType().getReferencedTypeInternal()); } return thisType.isSubtypeOf(thatType) || thatType.isSubtypeOf(thisType); }
if (type.isEnumElementType()) { foundType = getTypeWithProperty(field, type.getEnumeratedTypeOfEnumElement()); gtwpCachePut(field, type, foundType == null ? bottomObjectType : foundType);
Boolean castCastToHelper(JSType thisType, JSType thatType) { if (thatType.isUnknownType() || thatType.isAllType() || thatType.isNoObjectType() // TODO(johnlenz): restrict to objects || thatType.isNoType()) { return true; } else if (thisType.isRecordType() || thatType.isRecordType()) { return true; // TODO(johnlenz): are there any misuses we can catch? } else if (isInterface(thisType) || isInterface(thatType)) { return true; // TODO(johnlenz): are there any misuses we can catch? } else if (thatType.isEnumElementType()) { return thisType.visit(this, thatType.toMaybeEnumElementType().getPrimitiveType()); } else if (thatType.isUnionType()) { return canCastToUnion(thisType, thatType.toMaybeUnionType()); } else if (thatType.isFunctionType()) { return canCastToFunction(thisType, thatType.toMaybeFunctionType()); } else if (thatType.isTemplatizedType()) { // TODO(johnlenz): once the templated type work is finished, // restrict the type parameters. return thisType.visit(this, thatType.toMaybeTemplatizedType().getReferencedTypeInternal()); } return thisType.isSubtype(thatType) || thatType.isSubtype(thisType); }
if (type.isEnumElementType()) { foundType = getTypeWithProperty( field, type.toMaybeEnumElementType().getPrimitiveType());
if (thisType.isEnumElementType()) { JSType inf = thisType.toMaybeEnumElementType().meet(thatType); if (inf != null) { return inf; } else if (thatType.isEnumElementType()) { JSType inf = thatType.toMaybeEnumElementType().meet(thisType); if (inf != null) {
if (thisType.isEnumElementType()) { JSType inf = thisType.toMaybeEnumElementType().meet(thatType); if (inf != null) { return inf; } else if (thatType.isEnumElementType()) { JSType inf = thatType.toMaybeEnumElementType().meet(thisType); if (inf != null) {
if (bType.isEnumElementType() || bType.isUnionType()) { return bType.testForEquality(aType);
if (allowedValueType.isEnumElementType()) { allowedValueType = allowedValueType.toMaybeEnumElementType().getPrimitiveType();
if (allowedValueType.isEnumElementType()) { allowedValueType = allowedValueType.toMaybeEnumElementType().getPrimitiveType();