use of com.google.javascript.rhino.StaticSourceFile in project closure-compiler by google.
the class NodeUtil method getSourceFile.
/**
* @param n The node.
* @return The source name property on the node or its ancestors.
*/
public static StaticSourceFile getSourceFile(Node n) {
StaticSourceFile sourceName = null;
while (sourceName == null && n != null) {
sourceName = n.getStaticSourceFile();
n = n.getParent();
}
return sourceName;
}
use of com.google.javascript.rhino.StaticSourceFile in project closure-compiler by google.
the class CheckAccessControls method isPrivateAccessAllowed.
private static boolean isPrivateAccessAllowed(Var var, Node name) {
StaticSourceFile varSrc = var.getSourceFile();
StaticSourceFile refSrc = name.getStaticSourceFile();
return varSrc == null || refSrc == null || Objects.equals(varSrc.getName(), refSrc.getName());
}
use of com.google.javascript.rhino.StaticSourceFile in project closure-compiler by google.
the class CheckAccessControls method checkPropertyVisibility.
/**
* Reports an error if the given property is not visible in the current context.
*
* <p>This method covers both:
*
* <ul>
* <li>accesses to properties during execution
* <li>overrides of properties during declaration
* </ul>
*
* TODO(nickreid): Things would probably be a lot simpler, though a bit duplicated, if these two
* concepts were separated. Much of the underlying logic could stop checking various inconsistent
* definitions of "is this an override".
*/
private void checkPropertyVisibility(PropertyReference propRef) {
if (NodeUtil.isEs6ConstructorMemberFunctionDef(propRef.getSourceNode())) {
// because it ignores cases where there's no overridden definition.
return;
}
JSType rawReferenceType = typeOrUnknown(propRef.getReceiverType()).autobox();
ObjectType referenceType = castToObject(rawReferenceType);
String propertyName = propRef.getName();
StaticSourceFile definingSource = AccessControlUtils.getDefiningSource(propRef.getSourceNode(), referenceType, propertyName);
// Is this a normal property access, or are we trying to override
// an existing property?
boolean isOverride = propRef.isDocumentedDeclaration() || propRef.isOverride();
ObjectType objectType = AccessControlUtils.getObjectType(referenceType, isOverride, propertyName);
Visibility fileOverviewVisibility = defaultVisibilityForFiles.get(definingSource);
Visibility visibility = getEffectivePropertyVisibility(propRef, referenceType, defaultVisibilityForFiles);
if (isOverride) {
Visibility overriding = getOverridingPropertyVisibility(propRef);
if (overriding != null) {
checkPropertyOverrideVisibilityIsSame(overriding, visibility, fileOverviewVisibility, propRef);
}
}
JSType reportType = rawReferenceType;
if (objectType != null) {
Node node = objectType.getOwnPropertyDefSite(propertyName);
if (node == null) {
// Assume the property is public.
return;
}
reportType = objectType;
definingSource = node.getStaticSourceFile();
} else if (fileOverviewVisibility == null) {
// Otherwise just assume the property is public.
return;
}
StaticSourceFile referenceSource = propRef.getSourceNode().getStaticSourceFile();
if (isOverride) {
boolean sameInput = referenceSource != null && referenceSource.getName().equals(definingSource.getName());
checkPropertyOverrideVisibility(propRef, visibility, fileOverviewVisibility, reportType, sameInput);
} else {
checkPropertyAccessVisibility(propRef, visibility, reportType, referenceSource, definingSource);
}
}
Aggregations