@Override public boolean apply(Node n) { return n == expr.getRoot(); } };
@Override public Node apply(JSTypeExpression expr) { return expr.getRoot(); } });
@Override public boolean apply(Node n) { return n == expr.getRoot(); } };
public Node apply(JSTypeExpression expr) { return expr.getRoot(); } });
private ParameterType parseParameter( JSTypeExpression jsdoc, ParameterKind p, DeclaredTypeRegistry registry, ImmutableList<String> typeParameters) { if (jsdoc == null) { return null; } return parseParameter(jsdoc.getRoot(), p, registry, typeParameters); }
private JSType getTypeFromJSTypeExpression(JSTypeExpression expr, DeclaredTypeRegistry registry, ImmutableList<String> typeParameters) { if (expr == null) { return null; } return getTypeFromComment(expr.getRoot(), registry, typeParameters); }
private String buildParamType(String name, JSTypeExpression type) { if (type != null) { return "{" + typeNode(type.getRoot()) + "} " + name; } else { return name; } }
@Nullable public static TypeDeclarationNode convert(@Nullable JSTypeExpression typeExpr) { if (typeExpr == null) { return null; } return convertTypeNodeAST(typeExpr.getRoot()); }
private static String buildParamType(String name, JSTypeExpression type) { if (type != null) { return "{" + typeNode(type.getRoot()) + "} " + name; } else { return name; } }
@Nullable public TypeDeclarationNode convert(@Nullable JSTypeExpression typeExpr, boolean isReturnType) { if (typeExpr == null) { return null; } return convertTypeNodeAST(typeExpr.getRoot(), isReturnType); }
private String buildAnnotationWithType(String annotation, JSTypeExpression type) { return buildAnnotationWithType(annotation, type.getRoot()); }
private static String buildAnnotationWithType(String annotation, JSTypeExpression type) { return buildAnnotationWithType(annotation, type.getRoot()); }
/** * Adds a usage for the given type expression (unless it references a variable that is defined in * the externs, in which case no goog.require() is needed). When a usage is added, it means that * there should be a goog.require for that type. */ private void maybeAddUsage(NodeTraversal t, Node n, final JSTypeExpression expr) { // Just look at the root node, don't traverse. Predicate<Node> pred = new Predicate<Node>() { @Override public boolean apply(Node n) { return n == expr.getRoot(); } }; maybeAddUsage(t, n, expr.getRoot(), true, pred); }
/** * Adds a usage for the given type expression (unless it references a variable that is * defined in the externs, in which case no goog.require() is needed). When a usage is * added, it means that there should be a goog.require for that type. */ private void maybeAddUsage(NodeTraversal t, Node n, final JSTypeExpression expr) { // Just look at the root node, don't traverse. Predicate<Node> pred = new Predicate<Node>() { @Override public boolean apply(Node n) { return n == expr.getRoot(); } }; maybeAddUsage(t, n, expr.getRoot(), true, pred); }
public static boolean isRestArg(JSDocInfo funJsdoc, String formalParamName) { if (funJsdoc == null) { return false; } JSTypeExpression texp = funJsdoc.getParameterType(formalParamName); Node jsdocNode = texp == null ? null : texp.getRoot(); return jsdocNode != null && jsdocNode.getType() == Token.ELLIPSIS; }
public JSType evaluateTypeExpression(JSTypeExpression expr, StaticTypedScope scope) { return createTypeFromCommentNode(expr.getRoot(), expr.getSourceName(), scope); }
private void checkTypeContainsObjectWithBadKey(NodeTraversal t, Node n, JSTypeExpression type) { if (type != null && type.getRoot().getJSType() != null) { JSType realType = type.getRoot().getJSType(); JSType objectWithBadKey = findObjectWithNonStringifiableKey(realType, new HashSet<JSType>()); if (objectWithBadKey != null){ compiler.report(t.makeError(n, NON_STRINGIFIABLE_OBJECT_KEY, objectWithBadKey.toString())); } } }
private void checkTypeContainsObjectWithBadKey(NodeTraversal t, Node n, JSTypeExpression type) { if (type != null && type.getRoot().getJSType() != null) { JSType realType = type.getRoot().getJSType(); JSType objectWithBadKey = findObjectWithNonStringifiableKey(realType); if (objectWithBadKey != null){ compiler.report(t.makeError(n, NON_STRINGIFIABLE_OBJECT_KEY, objectWithBadKey.toString())); } } }
/** * Check that an arrow function is not annotated with {@constructor}. */ private void validateDefaultValue(Node n, JSDocInfo info) { if (n.isDefaultValue() && n.getParent().isParamList() && info != null) { JSTypeExpression typeExpr = info.getType(); if (typeExpr == null) { return; } Node typeNode = typeExpr.getRoot(); if (typeNode.getType() != Token.EQUALS) { report(typeNode, DEFAULT_PARAM_MUST_BE_MARKED_OPTIONAL); } } }
/** * @return Whether there is a declaration of a callable type. */ public boolean containsFunctionDeclaration() { boolean hasFunctionType = hasType() && getType().getRoot().isFunction(); return hasFunctionType || hasReturnType() || hasThisType() || getParameterCount() > 0 || getFlag(MASK_CONSTRUCTOR) || (getFlag(MASK_NOSIDEEFFECTS) && !hasType()); }