use of com.google.javascript.rhino.JSDocInfo.Visibility in project closure-compiler by google.
the class AccessControlUtils method getEffectivePropertyVisibility.
/**
* Returns the effective visibility of the given property. This can differ
* from the property's declared visibility if the property is inherited from
* a superclass, or if the file's {@code @fileoverview} JsDoc specifies
* a default visibility.
*
* @param property The property to compute effective visibility for.
* @param referenceType The JavaScript type of the property.
* @param fileVisibilityMap A map of {@code @fileoverview} visibility
* annotations, used to compute the property's default visibility.
* @param codingConvention The coding convention in effect (if any),
* used to determine whether the property is private by lexical convention
* (example: trailing underscore).
*/
static Visibility getEffectivePropertyVisibility(Node property, ObjectTypeI referenceType, ImmutableMap<StaticSourceFile, Visibility> fileVisibilityMap, @Nullable CodingConvention codingConvention) {
String propertyName = property.getLastChild().getString();
StaticSourceFile definingSource = getDefiningSource(property, referenceType, propertyName);
Visibility fileOverviewVisibility = fileVisibilityMap.get(definingSource);
Node parent = property.getParent();
boolean isOverride = parent.getJSDocInfo() != null && parent.isAssign() && parent.getFirstChild() == property;
ObjectTypeI objectType = getObjectType(referenceType, isOverride, propertyName);
if (isOverride) {
Visibility overridden = getOverriddenPropertyVisibility(objectType, propertyName);
return getEffectiveVisibilityForOverriddenProperty(overridden, fileOverviewVisibility, propertyName, codingConvention);
} else {
return getEffectiveVisibilityForNonOverriddenProperty(property, objectType, fileOverviewVisibility, codingConvention);
}
}
use of com.google.javascript.rhino.JSDocInfo.Visibility in project closure-compiler by google.
the class Es6TypedToEs6Converter method maybeAddVisibility.
private void maybeAddVisibility(Node n) {
Visibility access = (Visibility) n.getProp(Node.ACCESS_MODIFIER);
if (access != null) {
if (n.isComputedProp()) {
compiler.report(JSError.make(n, COMPUTED_PROP_ACCESS_MODIFIER));
}
JSDocInfoBuilder memberDoc = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo());
memberDoc.recordVisibility(access);
n.setJSDocInfo(memberDoc.build());
n.removeProp(Node.ACCESS_MODIFIER);
}
}
use of com.google.javascript.rhino.JSDocInfo.Visibility 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.JSDocInfo.Visibility in project closure-compiler by google.
the class AccessControlUtils method getEffectiveNameVisibility.
/**
* Returns the effective visibility of the given name. This can differ
* from the name's declared visibility if the file's {@code @fileoverview}
* JsDoc specifies a default visibility.
*
* @param name The name node to compute effective visibility for.
* @param var The name to compute effective visibility for.
* @param fileVisibilityMap A map of {@code @fileoverview} visibility
* annotations, used to compute the name's default visibility.
*/
static Visibility getEffectiveNameVisibility(Node name, Var var, ImmutableMap<StaticSourceFile, Visibility> fileVisibilityMap) {
JSDocInfo jsDocInfo = var.getJSDocInfo();
Visibility raw = (jsDocInfo == null || jsDocInfo.getVisibility() == null) ? Visibility.INHERITED : jsDocInfo.getVisibility();
if (raw != Visibility.INHERITED) {
return raw;
}
Visibility defaultVisibilityForFile = fileVisibilityMap.get(var.getSourceFile());
TypeI type = name.getTypeI();
boolean createdFromGoogProvide = (type != null && type.isLiteralObject());
// effectively package-private.
return (createdFromGoogProvide || defaultVisibilityForFile == null) ? raw : defaultVisibilityForFile;
}
use of com.google.javascript.rhino.JSDocInfo.Visibility in project closure-compiler by google.
the class CollectFileOverviewVisibility method visit.
private void visit(Node scriptNode) {
JSDocInfo jsDocInfo = scriptNode.getJSDocInfo();
if (jsDocInfo == null) {
return;
}
Visibility v = jsDocInfo.getVisibility();
if (v == null) {
return;
}
builder.put(scriptNode.getStaticSourceFile(), v);
}
Aggregations