private static JSDocInfoBuilder makeBuilderWithType(@Nullable JSDocInfo oldJSDoc, Node typeAst) { JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(oldJSDoc); builder.recordType(new JSTypeExpression(typeAst, "<synthetic>")); return builder; }
static JSDocInfo markConstant(JSDocInfo oldJSDoc) { JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(oldJSDoc); builder.recordConstancy(); return builder.build(); }
static JSDocInfo mergeJsdocs(@Nullable JSDocInfo classicJsdoc, @Nullable JSDocInfo inlineJsdoc) { if (inlineJsdoc == null || !inlineJsdoc.hasType()) { return classicJsdoc; } JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(classicJsdoc); builder.recordType(inlineJsdoc.getType()); return 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 at-constructor to the JSDoc of the given node. * * @param node */ private void addAtConstructor(Node node) { JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(node.getJSDocInfo()); builder.recordConstructor(); node.setJSDocInfo(builder.build()); } }
private void markConst(Node n) { JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo()); builder.recordConstancy(); n.setJSDocInfo(builder.build()); }
private static void extractInlineJSDoc(Node srcDeclaration, Node srcName, Node destDeclaration) { JSDocInfo existingInfo = srcDeclaration.getJSDocInfo(); if (existingInfo == null) { // Extract inline JSDoc from "src" and add it to the "dest" node. existingInfo = srcName.getJSDocInfo(); srcName.setJSDocInfo(null); } JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(existingInfo); destDeclaration.setJSDocInfo(builder.build()); }
private static void extractInlineJSDoc(Node srcDeclaration, Node srcName, Node destDeclaration) { JSDocInfo existingInfo = srcDeclaration.getJSDocInfo(); if (existingInfo == null) { // Extract inline JSDoc from "src" and add it to the "dest" node. existingInfo = srcName.getJSDocInfo(); srcName.setJSDocInfo(null); } JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(existingInfo); destDeclaration.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. // 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()); } }
/** Adds return type information to class getters */ private void addReturnTypeIfMissing( PolymerClassDefinition cls, String getterPropName, JSTypeExpression jsType) { Node classMembers = NodeUtil.getClassMembers(cls.definition); Node getter = NodeUtil.getFirstGetterMatchingKey(classMembers, getterPropName); if (getter != null) { JSDocInfo info = NodeUtil.getBestJSDocInfo(getter); if (info == null || !info.hasReturnType()) { JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(info); builder.recordReturnType(jsType); getter.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 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); } }
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); } }
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()); }
/** @return The proper constructor doc for the Polymer call. */ private JSDocInfoBuilder getConstructorDoc(final PolymerClassDefinition cls) { JSDocInfoBuilder constructorDoc = JSDocInfoBuilder.maybeCopyFrom(cls.constructor.info); constructorDoc.recordConstructor(); JSTypeExpression baseType = new JSTypeExpression( new Node(Token.BANG, IR.string(PolymerPassStaticUtils.getPolymerElementType(cls))), VIRTUAL_FILE); constructorDoc.recordBaseType(baseType); String interfaceName = getInterfaceName(cls); JSTypeExpression interfaceType = new JSTypeExpression(new Node(Token.BANG, IR.string(interfaceName)), VIRTUAL_FILE); constructorDoc.recordImplementedInterface(interfaceType); return constructorDoc; }
/** * @return The proper constructor doc for the Polymer call. */ private JSDocInfoBuilder getConstructorDoc(final PolymerClassDefinition cls) { JSDocInfoBuilder constructorDoc = JSDocInfoBuilder.maybeCopyFrom(cls.constructor.info); constructorDoc.recordConstructor(); JSTypeExpression baseType = new JSTypeExpression( new Node(Token.BANG, IR.string(PolymerPassStaticUtils.getPolymerElementType(cls))), PolymerPass.VIRTUAL_FILE); constructorDoc.recordBaseType(baseType); String interfaceName = getInterfaceName(cls); JSTypeExpression interfaceType = new JSTypeExpression( new Node(Token.BANG, IR.string(interfaceName)), PolymerPass.VIRTUAL_FILE); constructorDoc.recordImplementedInterface(interfaceType); return constructorDoc; }
private void maybeAddGenerics(Node n, Node jsDocNode) { Node name = n.getFirstChild(); Node generics = (Node) name.getProp(Node.GENERIC_TYPE_LIST); if (generics != null) { JSDocInfoBuilder doc = JSDocInfoBuilder.maybeCopyFrom(jsDocNode.getJSDocInfo()); // Discard the type bound (the "extends" part) for now for (Node typeName : generics.children()) { doc.recordTemplateTypeName(typeName.getString()); if (typeName.hasChildren()) { compiler.report(JSError.make(name, CANNOT_CONVERT_BOUNDED_GENERICS)); typeName.removeChildren(); } } name.removeProp(Node.GENERIC_TYPE_LIST); jsDocNode.setJSDocInfo(doc.build()); } }