/** * @return Whether the node is the declaration of a Behavior. */ private static boolean isBehavior(Node value) { return value.getJSDocInfo() != null && value.getJSDocInfo().isPolymerBehavior(); }
/** @return Whether the node has a JSDoc that actually declares something. */ private boolean jsdocContainsDeclarations(Node node) { JSDocInfo info = node.getJSDocInfo(); return (info != null && info.containsDeclaration()); }
@Override protected ConformanceResult checkConformance(NodeTraversal t, Node n) { JSDocInfo info = n.getJSDocInfo(); if (info != null && info.isExpose()) { return ConformanceResult.VIOLATION; } return ConformanceResult.CONFORMANCE; } }
/** * Get the value of the @nosideeffects annotation stored in the * doc info. */ private static boolean hasNoSideEffectsAnnotation(Node node) { JSDocInfo docInfo = node.getJSDocInfo(); return docInfo != null && docInfo.isNoSideEffects(); }
/** Find the best JSDoc for the given node. */ @Nullable public static JSDocInfo getBestJSDocInfo(Node n) { Node jsdocNode = getBestJSDocInfoNode(n); return jsdocNode == null ? null : jsdocNode.getJSDocInfo(); }
private static boolean isMarkedExpose(Node n) { JSDocInfo info = n.getJSDocInfo(); return info != null && info.isExpose(); } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.getJSDocInfo() != null) { // Find references in the JSDocInfo. JSDocInfo info = n.getJSDocInfo(); docInfos.add(n); for (Node typeAst : info.getTypeNodes()) { SymbolScope scope = scopes.get(t.getScopeRoot()); visitTypeNode(info.getTemplateTypeNames(), scope == null ? globalScope : scope, typeAst); } } }
/** Reports a warning for with statements. */ private static void checkWith(NodeTraversal t, Node n) { JSDocInfo info = n.getJSDocInfo(); boolean allowWith = info != null && info.getSuppressions().contains("with"); if (!allowWith) { t.report(n, USE_OF_WITH); } }
/** Determine if the given SCRIPT is a @typeSummary file, like an i.js file */ public static boolean isFromTypeSummary(Node n) { checkArgument(n.isScript(), n); JSDocInfo info = n.getJSDocInfo(); return info != null && info.isTypeSummary(); }
private void fixTypeAnnotationsForNode(NodeTraversal t, Node n) { JSDocInfo info = n.getJSDocInfo(); if (info != null) { for (Node typeNode : info.getTypeNodes()) { fixTypeNode(t, typeNode); } } }
private void checkForPrimitiveObjectDeclaration(NodeTraversal t, Node n) { JSDocInfo jsDocInfo = n.getJSDocInfo(); if (jsDocInfo != null) { for (Node typeRoot : jsDocInfo.getTypeNodes()) { checkTypeNodeForPrimitiveObjectDeclaration(t, typeRoot); } } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { JSDocInfo docInfo = n.getJSDocInfo(); if (docInfo != null && docInfo.isNgInject()) { addNode(n, t); } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isScript()) { JSDocInfo info = n.getJSDocInfo(); if (info == null || !info.isExterns()) { t.report(n, EXTERNS_FILES_SHOULD_BE_ANNOTATED); } } } }
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 maybeProcessType(Node typeTarget, ParseTree typeTree) { if (typeTree != null) { recordJsDoc(typeTree.location, typeTarget.getJSDocInfo()); Node typeExpression = convertTypeTree(typeTree); if (typeExpression.isString()) { typeExpression = cloneProps( new TypeDeclarationNode(Token.STRING, typeExpression.getString())); } typeTarget.setDeclaredTypeExpression((TypeDeclarationNode) typeExpression); } }
/** Converts a member function into a quoted string key to avoid property renaming */ private void rewriteMemberDefInObjLit(Node memberDef, Node objLit) { String name = memberDef.getString(); Node stringKey = IR.stringKey(name, memberDef.getFirstChild().detach()); objLit.replaceChild(memberDef, stringKey); stringKey.setQuotedString(); stringKey.setJSDocInfo(memberDef.getJSDocInfo()); compiler.reportChangeToEnclosingScope(objLit); }
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()); } }
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); } }