use of com.google.javascript.rhino.StaticSourceFile in project closure-compiler by google.
the class CheckAccessControls method isPackageAccessAllowed.
private boolean isPackageAccessAllowed(Var var, Node name) {
StaticSourceFile varSrc = var.getSourceFile();
StaticSourceFile refSrc = name.getStaticSourceFile();
if (varSrc == null && refSrc == null) {
// file is unknown. I didn't change it in order not to break existing code.
return false;
}
CodingConvention codingConvention = compiler.getCodingConvention();
String srcPackage = codingConvention.getPackageName(varSrc);
String refPackage = codingConvention.getPackageName(refSrc);
return srcPackage != null && refPackage != null && Objects.equals(srcPackage, refPackage);
}
use of com.google.javascript.rhino.StaticSourceFile 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, ObjectType referenceType, ImmutableMap<StaticSourceFile, Visibility> fileVisibilityMap) {
String propertyName = property.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;
ObjectType objectType = getObjectType(referenceType, isOverride, propertyName);
if (isOverride) {
Visibility overridden = getOverriddenPropertyVisibility(objectType, propertyName);
return getEffectiveVisibilityForOverriddenProperty(overridden, fileOverviewVisibility, propertyName);
} else {
return getEffectiveVisibilityForNonOverriddenProperty(property, objectType, fileOverviewVisibility);
}
}
use of com.google.javascript.rhino.StaticSourceFile in project closure-compiler by google.
the class ParserRunner method parse.
public static ParseResult parse(StaticSourceFile sourceFile, String sourceString, Config config, ErrorReporter errorReporter) {
// TODO(johnlenz): unify "SourceFile", "Es6ErrorReporter" and "Config"
String sourceName = sourceFile.getName();
try {
SourceFile file = new SourceFile(sourceName, sourceString);
boolean keepGoing = config.runMode() == Config.RunMode.KEEP_GOING;
Es6ErrorReporter es6ErrorReporter = new Es6ErrorReporter(errorReporter, keepGoing);
com.google.javascript.jscomp.parsing.parser.Parser.Config es6config = newParserConfig(config);
Parser p = new Parser(es6config, es6ErrorReporter, file);
ProgramTree tree = p.parseProgram();
Node root = null;
List<Comment> comments = ImmutableList.of();
FeatureSet features = p.getFeatures();
if (tree != null && (!es6ErrorReporter.hadError() || keepGoing)) {
IRFactory factory = IRFactory.transformTree(tree, sourceFile, config, errorReporter);
root = factory.getResultNode();
features = features.union(factory.getFeatures());
root.putProp(Node.FEATURE_SET, features);
if (config.jsDocParsingMode().shouldParseDescriptions()) {
comments = p.getComments();
}
}
return new ParseResult(root, comments, features, p.getSourceMapURL());
} catch (Throwable t) {
throw new RuntimeException("Exception parsing \"" + sourceName + "\"", t);
}
}
use of com.google.javascript.rhino.StaticSourceFile in project closure-compiler by google.
the class CheckMissingSemicolon method checkSemicolon.
private void checkSemicolon(NodeTraversal t, Node n) {
StaticSourceFile staticSourceFile = n.getStaticSourceFile();
if (staticSourceFile instanceof SourceFile) {
SourceFile sourceFile = (SourceFile) staticSourceFile;
String code;
try {
code = sourceFile.getCode();
} catch (IOException e) {
// We can't read the original source file. Just skip this check.
return;
}
int length = n.getLength();
if (length == 0) {
// that information, so just skip the check.
return;
}
int position = n.getSourceOffset() + length - 1;
boolean endsWithSemicolon = code.charAt(position) == ';';
if (!endsWithSemicolon) {
t.report(n, MISSING_SEMICOLON);
}
}
}
use of com.google.javascript.rhino.StaticSourceFile in project closure-compiler by google.
the class DefaultCodingConventionTest method assertPackageName.
private void assertPackageName(String filename, String expectedPackageName) {
StaticSourceFile sourceFile = SourceFile.fromCode(filename, "");
assertThat(conv.getPackageName(sourceFile)).isEqualTo(expectedPackageName);
}
Aggregations