private void validateHasSourceName(Node n) { String sourceName = n.getSourceFileName(); if (isNullOrEmpty(sourceName)) { violation("Missing 'source name' annotation.", n); } }
/** * @param n The node. * @return The source name property on the node or its ancestors. */ public static String getSourceName(Node n) { String sourceName = null; while (sourceName == null && n != null) { sourceName = n.getSourceFileName(); n = n.getParent(); } return sourceName; }
public SyntheticAst(Node root) { this.inputId = new InputId(root.getSourceFileName()); this.sourceFile = new SourceFile(root.getSourceFileName(), SourceKind.STRONG); this.root = checkNotNull(root); }
@Override public boolean shouldTraverse(NodeTraversal nodeTraversal, Node n, Node parent) { // Only look inside the referenced class file. return !n.isScript() || n.getSourceFileName().endsWith(classFileName) || classFileName.equals(ALL_CLASS_FILE_NAMES); }
private static boolean hasJ2cl(Node root) { for (Node script : root.children()) { checkState(script.isScript()); if (script.getSourceFileName() != null && script.getSourceFileName().endsWith(".java.js")) { return true; } } return false; }
protected void emitSeeSourceFileName(StringBuilder sb) { sb.append(indent); sb.append(" * @see ").append(getNode().getSourceFileName()).append("\n"); }
private void validateHasSourceName(Node n) { String sourceName = n.getSourceFileName(); if (isNullOrEmpty(sourceName)) { violation("Missing 'source name' annotation.", n); } }
/** * Creates a JSError from a file and Node position. * * @param n Determines the line and char position and source file name * @param type The DiagnosticType * @param arguments Arguments to be incorporated into the message */ public static JSError make(Node n, DiagnosticType type, String... arguments) { return new JSError(n.getSourceFileName(), n, type, arguments); }
@Override public int compare(Node a, Node b) { int result = sourceNameOrdering.compare(a.getSourceFileName(), b.getSourceFileName()); if (result != 0) { return result; } // Source position is a bit mask of line in the top 4 bits, so this // is a quick way to compare order without computing absolute position. return a.getSourcePosition() - b.getSourcePosition(); } };
@Override public int compare(Node a, Node b) { int result = sourceNameOrdering.compare( a.getSourceFileName(), b.getSourceFileName()); if (result != 0) { return result; } // Source position is a bit mask of line in the top 4 bits, so this // is a quick way to compare order without computing absolute position. return a.getSourcePosition() - b.getSourcePosition(); } };
public boolean isExternalTypedef(BaseReference reference) { String sourceFileName = reference.getNode().getSourceFileName(); for (TypedefFile file : externalTypedefs) { if (sourceFileName.equals("[" + file.getName() + "]")) { return true; } } return false; }
@Override public String toString() { String sourceName = node == null ? null : node.getSourceFileName(); int lineNo = node == null ? -1 : node.getLineno(); return node.getQualifiedName() + "@" + sourceName + ":" + lineNo; } }
@Override public void hotSwapScript(Node scriptRoot, Node originalRoot) { String srcName = originalRoot.getSourceFileName(); Callback cb = new QualifiedNameSearchTraversal(compiler.getTypeRegistry(), srcName); NodeTraversal.traverse(compiler, originalRoot, cb); }
/** * Inserts a new node as the first child of the provided node. */ public Builder addChildToFront(Node parentNode, String content) { Preconditions.checkState(parentNode.isBlock(), "addChildToFront is only supported for BLOCK statements."); int startPosition = parentNode.getSourceOffset() + 1; replacements.put( parentNode.getSourceFileName(), new CodeReplacement(startPosition, 0, "\n" + content)); return this; }
static String getIdForGeneratorNode(boolean consistent, Node n) { checkState(n.isString() || n.isStringKey(), n); if (consistent) { return n.getString(); } else { return n.getSourceFileName() + ':' + n.getLineno() + ":" + n.getCharno(); } } }
private String getBestFunctionName(Node n) { checkState(n.isClass() || n.isFunction()); String name = NodeUtil.getBestLValueName(NodeUtil.getBestLValue(n)); return name != null ? name : "<anonymous@" + n.getSourceFileName() + ":" + n.getLineno() + ">"; }
/** * Reports a reassigned constant error. */ void reportError(NodeTraversal t, Node n, Var var, String name) { JSDocInfo info = NodeUtil.getBestJSDocInfo(n); if (info == null || !info.getSuppressions().contains("const")) { Node declNode = var.getNode(); String declaredPosition = declNode.getSourceFileName() + ":" + declNode.getLineno(); compiler.report(t.makeError(n, CONST_REASSIGNED_VALUE_ERROR, name, declaredPosition)); } } }
/** * Reports a reassigned constant error. */ void reportError(NodeTraversal t, Node n, Var var, String name) { JSDocInfo info = NodeUtil.getBestJSDocInfo(n); if (info == null || !info.getSuppressions().contains("const")) { Node declNode = var.getNode(); String declaredPosition = declNode.getSourceFileName() + ":" + declNode.getLineno(); compiler.report(t.makeError(n, CONST_REASSIGNED_VALUE_ERROR, name, declaredPosition)); } } }
boolean isInstrumentation(Node n) { //if (n == null) // return false; if (n.getSourceFileName() == null) return true; Node child = n.getFirstChild(); return child != null && child.isGetProp() && child.getFirstChild().isName() && child.getFirstChild().getString().equals("_$jscoverage"); }
private String getImportedModuleName(NodeTraversal t, Node n, String importPath) { ModulePath modulePath = t.getInput() .getPath() .resolveJsModule(importPath, n.getSourceFileName(), n.getLineno(), n.getCharno()); if (modulePath == null) { return ModuleIdentifier.forFile(importPath).getModuleName(); } return modulePath.toModuleName(); }