static JSDocInfo createConstantJsDoc() { JSDocInfoBuilder builder = new JSDocInfoBuilder(false); builder.recordConstancy(); return builder.build(); }
static JSDocInfo createConstantJsDoc() { JSDocInfoBuilder builder = new JSDocInfoBuilder(false); builder.recordConstancy(); return builder.build(); }
private static JSDocInfo getConstJSDoc(JSDocInfo oldJSDoc, Node typeAst) { JSDocInfoBuilder builder = makeBuilderWithType(oldJSDoc, typeAst); builder.recordConstancy(); return builder.build(); }
static JSDocInfo markConstant(JSDocInfo oldJSDoc) { JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(oldJSDoc); builder.recordConstancy(); return builder.build(); }
private JSDocInfo buildNamespaceJSDoc() { JSDocInfoBuilder builder = new JSDocInfoBuilder(false); builder.recordConstancy(); builder.recordSuppressions(ImmutableSet.of("const", "duplicate")); return builder.build(); }
private JSDocInfo buildNamespaceJSDoc() { JSDocInfoBuilder builder = new JSDocInfoBuilder(false); builder.recordConstancy(); builder.recordSuppressions(ImmutableSet.of("const", "duplicate")); return builder.build(); }
private void markConst(Node n) { JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo()); builder.recordConstancy(); n.setJSDocInfo(builder.build()); }
private void markConst(Node n) { JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo()); builder.recordConstancy(); n.setJSDocInfo(builder.build()); }
private static void markConstAndCopyJsDoc(Node from, Node target) { JSDocInfo info = from.getJSDocInfo(); JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(info); builder.recordConstancy(); target.setJSDocInfo(builder.build()); }
/** * Add an @const annotation to each key of an object literal */ private void addConstToObjLitKeys(Node n) { Preconditions.checkState(n.isObjectLit()); for (Node key = n.getFirstChild(); key != null; key = key.getNext()) { if (key.getJSDocInfo() == null) { JSDocInfoBuilder builder = new JSDocInfoBuilder(true); builder.recordConstancy(); JSDocInfo info = builder.build(); key.setJSDocInfo(info); } } }
private static void maybeAddConstJSDoc(Node srcDeclaration, Node srcParent, Node srcName, Node destDeclaration) { if (srcDeclaration.isConst() // Don't add @const for the left side of a for/in. If we do we get warnings from the NTI. // TODO(lharker): Check if this condition is still necessary, since NTI is deleted && !(srcParent.isForIn() && srcDeclaration == srcParent.getFirstChild())) { extractInlineJSDoc(srcDeclaration, srcName, destDeclaration); JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(destDeclaration.getJSDocInfo()); builder.recordConstancy(); destDeclaration.setJSDocInfo(builder.build()); } }
/** * Will skip const if the target is a class definition as that has a different meaning. */ private void markConstAndCopyJsDoc(Node from, Node target, Node value) { JSDocInfo info = from.getJSDocInfo(); JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(info); // Don't add @const on class declarations because in that context it means "not subclassable". if (!isCallTo(value, "goog.defineClass") && !(info != null && info.isConstructorOrInterface())) { builder.recordConstancy(); compiler.reportCodeChange(); } target.setJSDocInfo(builder.build()); }
private static void maybeAddConstJSDoc(Node srcDeclaration, Node srcParent, Node srcName, Node destDeclaration) { if (srcDeclaration.isConst() // Don't add @const for the left side of a for/in. If we do we get warnings from the NTI. && !(NodeUtil.isForIn(srcParent) && srcDeclaration == srcParent.getFirstChild())) { extractInlineJSDoc(srcDeclaration, srcName, destDeclaration); JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(destDeclaration.getJSDocInfo()); builder.recordConstancy(); destDeclaration.setJSDocInfo(builder.build()); } }
private void visitNamespaceDeclaration(NodeTraversal t, Node n, Node parent) { popNamespace(n, parent); for (Node name = NodeUtil.getRootOfQualifiedName(n.getFirstChild()); name != n; name = name.getParent()) { String fullName = maybePrependCurrNamespace(name.getQualifiedName()); if (!convertedNamespaces.contains(fullName)) { JSDocInfoBuilder doc = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo()); doc.recordConstancy(); Node namespaceDec = NodeUtil.newQNameDeclaration( compiler, fullName, IR.objectlit(), doc.build()).useSourceInfoFromForTree(n); parent.addChildBefore(namespaceDec, n); convertedNamespaces.add(fullName); } } replaceWithNodes(t, n, n.getLastChild().children()); }
private void visitNamespaceDeclaration(Node n, Node parent) { popNamespace(n, parent); for (Node name = NodeUtil.getRootOfQualifiedName(n.getFirstChild()); name != n; name = name.getParent()) { String fullName = maybePrependCurrNamespace(name.getQualifiedName()); if (!convertedNamespaces.contains(fullName)) { JSDocInfoBuilder doc = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo()); doc.recordConstancy(); Node namespaceDec = NodeUtil.newQNameDeclaration( compiler, fullName, IR.objectlit(), doc.build()).useSourceInfoFromForTree(n); parent.addChildBefore(namespaceDec, n); convertedNamespaces.add(fullName); } } replaceWithNodes(n, n.getLastChild().children()); }
moduleVar.getFirstChild().putBooleanProp(Node.MODULE_EXPORT, true); JSDocInfoBuilder infoBuilder = new JSDocInfoBuilder(false); infoBuilder.recordConstancy(); moduleVar.setJSDocInfo(infoBuilder.build()); script.addChildToBack(moduleVar.useSourceInfoIfMissingFromForTree(script)); builder.recordConstancy(); JSDocInfo info = builder.build(); assign.setJSDocInfo(info);
private void visitVarInsideNamespace(NodeTraversal t, Node n, Node parent) { if (currNamespace != null) { Node insertPoint = n; for (Node child : n.children()) { Node name = child; String oldName = name.getString(); String qName = maybePrependCurrNamespace(oldName); JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(child.getJSDocInfo()); if (n.isConst()) { builder.recordConstancy(); } Node newDec = NodeUtil.newQNameDeclaration( compiler, qName, child.removeFirstChild(), builder.build()).useSourceInfoFromForTree(n); parent.addChildAfter(newDec, insertPoint); insertPoint = newDec; } n.detach(); t.reportCodeChange(); } }
private void visitVarInsideNamespace(Node n, Node parent) { if (currNamespace != null) { Node insertPoint = n; for (Node child : n.children()) { Node name = child; String oldName = name.getString(); String qName = maybePrependCurrNamespace(oldName); JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(child.getJSDocInfo()); if (n.isConst()) { builder.recordConstancy(); } Node newDec = NodeUtil.newQNameDeclaration( compiler, qName, child.removeFirstChild(), builder.build()).useSourceInfoFromForTree(n); parent.addChildAfter(newDec, insertPoint); insertPoint = newDec; } n.detachFromParent(); compiler.reportCodeChange(); } }
private void visitAmbientDeclaration(NodeTraversal t, Node n, Node parent) { if (!n.isFromExterns()) { compiler.report(JSError.make(n, DECLARE_IN_NON_EXTERNS)); } Node insertionPoint = n; Node topLevel = parent; boolean insideExport = parent.isExport(); if (insideExport) { insertionPoint = parent; topLevel = parent.getParent(); } // The node can have multiple children if transformed from an ambient namespace declaration. for (Node c : n.children()) { if (c.isConst()) { JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(c.getJSDocInfo()); builder.recordConstancy(); c.setToken(Token.VAR); c.setJSDocInfo(builder.build()); } Node toAdd = c.detach(); if (insideExport && !toAdd.isExprResult()) { // We want to keep the "export" declaration in externs toAdd = new Node(Token.EXPORT, toAdd).srcref(parent); } topLevel.addChildBefore(toAdd, insertionPoint); } insertionPoint.detach(); t.reportCodeChange(); }
private void visitAmbientDeclaration(Node n, Node parent) { if (!n.isFromExterns()) { compiler.report(JSError.make(n, DECLARE_IN_NON_EXTERNS)); } Node insertionPoint = n; Node topLevel = parent; boolean insideExport = parent.getType() == Token.EXPORT; if (insideExport) { insertionPoint = parent; topLevel = parent.getParent(); } // The node can have multiple children if transformed from an ambient namespace declaration. for (Node c : n.children()) { if (c.getType() == Token.CONST) { JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(c.getJSDocInfo()); builder.recordConstancy(); c.setType(Token.VAR); c.setJSDocInfo(builder.build()); } Node toAdd = c.detachFromParent(); if (insideExport && !toAdd.isExprResult()) { // We want to keep the "export" declaration in externs toAdd = new Node(Token.EXPORT, toAdd).srcref(parent); } topLevel.addChildBefore(toAdd, insertionPoint); } insertionPoint.detachFromParent(); compiler.reportCodeChange(); }