use of com.google.javascript.rhino.ObjectTypeI in project closure-compiler by google.
the class AccessControlUtils method getEffectiveVisibilityForNonOverriddenProperty.
/**
* Returns the effective visibility of the given non-overridden property.
* Non-overridden properties without an explicit visibility annotation
* receive the default visibility declared in the file's {@code @fileoverview}
* block, if one exists.
*/
private static Visibility getEffectiveVisibilityForNonOverriddenProperty(Node getprop, ObjectTypeI objectType, @Nullable Visibility fileOverviewVisibility, @Nullable CodingConvention codingConvention) {
String propertyName = getprop.getLastChild().getString();
if (codingConvention != null && codingConvention.isPrivate(propertyName)) {
return Visibility.PRIVATE;
}
Visibility raw = Visibility.INHERITED;
if (objectType != null) {
raw = objectType.getOwnPropertyJSDocInfo(propertyName).getVisibility();
}
TypeI type = getprop.getTypeI();
boolean createdFromGoogProvide = (type != null && type.isLiteralObject());
// every a.b.* namespace effectively package-private.
return (raw != Visibility.INHERITED || fileOverviewVisibility == null || createdFromGoogProvide) ? raw : fileOverviewVisibility;
}
use of com.google.javascript.rhino.ObjectTypeI in project closure-compiler by google.
the class DisambiguateProperties method getTypeWithProperty.
/**
* Returns the type in the chain from the given type that contains the given
* field or null if it is not found anywhere.
* Can return a subtype of the input type.
*/
private ObjectTypeI getTypeWithProperty(String field, TypeI type) {
if (type == null) {
return null;
}
ObjectTypeI foundType = gtwpCacheGet(field, type);
if (foundType != null) {
return foundType.equals(BOTTOM_OBJECT) ? null : foundType;
}
if (type.isEnumElement()) {
foundType = getTypeWithProperty(field, type.getEnumeratedTypeOfEnumElement());
gtwpCachePut(field, type, foundType == null ? BOTTOM_OBJECT : foundType);
return foundType;
}
if (!type.isObjectType()) {
if (type.isBoxableScalar()) {
foundType = getTypeWithProperty(field, type.autobox());
gtwpCachePut(field, type, foundType == null ? BOTTOM_OBJECT : foundType);
return foundType;
} else {
gtwpCachePut(field, type, BOTTOM_OBJECT);
return null;
}
}
// Ignore the prototype itself at all times.
if ("prototype".equals(field)) {
gtwpCachePut(field, type, BOTTOM_OBJECT);
return null;
}
// We look up the prototype chain to find the highest place (if any) that
// this appears. This will make references to overridden properties look
// like references to the initial property, so they are renamed alike.
ObjectTypeI objType = type.toMaybeObjectType();
if (objType != null && objType.getConstructor() != null && objType.getConstructor().isInterface()) {
ObjectTypeI topInterface = objType.getTopDefiningInterface(field);
if (topInterface != null && topInterface.getConstructor() != null) {
foundType = topInterface.getPrototypeObject();
}
} else {
while (objType != null && !Objects.equals(objType.getPrototypeObject(), objType)) {
if (objType.hasOwnProperty(field)) {
foundType = objType;
}
objType = objType.getPrototypeObject();
}
}
// type is an object type, see if any subtype has the property.
if (foundType == null) {
TypeI subtypeWithProp = type.getGreatestSubtypeWithProperty(field);
ObjectTypeI maybeType = subtypeWithProp == null ? null : subtypeWithProp.toMaybeObjectType();
// so we have to double check.
if (maybeType != null && maybeType.hasOwnProperty(field)) {
foundType = maybeType;
}
}
// Unwrap templatized types, they are not unique at runtime.
if (foundType != null && foundType.isGenericObjectType()) {
foundType = foundType.getRawType();
}
// so that the returned type has the correct name.
if (foundType != null && foundType.isLegacyNamedType()) {
foundType = foundType.getLegacyResolvedType().toMaybeObjectType();
}
gtwpCachePut(field, type, foundType == null ? BOTTOM_OBJECT : foundType);
return foundType;
}
use of com.google.javascript.rhino.ObjectTypeI in project closure-compiler by google.
the class DisambiguateProperties method getTypesToSkipForTypeNonUnion.
private Set<TypeI> getTypesToSkipForTypeNonUnion(TypeI type) {
Set<TypeI> types = new HashSet<>();
TypeI skipType = type;
while (skipType != null) {
types.add(skipType);
ObjectTypeI objSkipType = skipType.toMaybeObjectType();
if (objSkipType != null) {
skipType = objSkipType.getPrototypeObject();
} else {
break;
}
}
return types;
}
use of com.google.javascript.rhino.ObjectTypeI 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.ObjectTypeI in project closure-compiler by google.
the class TypedCodeGenerator method appendInterfaceAnnotations.
private void appendInterfaceAnnotations(StringBuilder sb, FunctionTypeI funType) {
Set<String> interfaces = new TreeSet<>();
for (ObjectTypeI interfaceType : funType.getAncestorInterfaces()) {
interfaces.add(interfaceType.toAnnotationString(Nullability.IMPLICIT));
}
for (String interfaze : interfaces) {
sb.append(" * ");
appendAnnotation(sb, "extends", interfaze);
sb.append("\n");
}
if (funType.isStructuralInterface()) {
sb.append(" * @record\n");
} else {
sb.append(" * @interface\n");
}
}
Aggregations