/** * Declares a template type name. Template type names are described using the * {@code @template} annotation. * * @param newTemplateTypeName the template type name. */ boolean declareTemplateTypeName(String newTemplateTypeName) { lazyInitInfo(); if (isTypeTransformationName(newTemplateTypeName) || hasTypedefType()) { return false; } if (info.templateTypeNames == null){ info.templateTypeNames = new ArrayList<>(); } else if (info.templateTypeNames.contains(newTemplateTypeName)) { return false; } info.templateTypeNames.add(newTemplateTypeName); return true; }
/** * Whether the current doc info has any of the singleton type * tags that may not appear with other type tags, like * {@code @type} or {@code @typedef}. */ private boolean hasAnySingletonTypeTags() { return currentInfo.hasType() || currentInfo.hasTypedefType() || currentInfo.hasEnumParameterType(); }
private void validateTypedefs(Node n, JSDocInfo info) { if (info != null && info.hasTypedefType() && isClassDecl(n)) { reportMisplaced(n, "typedef", "@typedef does not make sense on a class declaration."); } }
/** * Declares a template type name. Template type names are described using the * {@code @template} annotation. * * @param newTemplateTypeName the template type name. */ boolean declareTemplateTypeName(String newTemplateTypeName) { lazyInitInfo(); if (isTypeTransformationName(newTemplateTypeName) || hasTypedefType()) { return false; } if (info.templateTypeNames == null){ info.templateTypeNames = new ArrayList<String>(); } else if (info.templateTypeNames.contains(newTemplateTypeName)) { return false; } info.templateTypeNames.add(newTemplateTypeName); return true; }
/** * Whether the current doc info has any of the singleton type * tags that may not appear with other type tags, like * {@code @type} or {@code @typedef}. */ private boolean hasAnySingletonTypeTags() { return currentInfo.hasType() || currentInfo.hasTypedefType() || currentInfo.hasEnumParameterType(); }
private boolean isCheckablePrivatePropDecl(Node n) { // TODO(tbreisacher): Look for uses of the typedef/interface in type expressions; warn if there // are no uses. JSDocInfo info = NodeUtil.getBestJSDocInfo(n); return isPrivatePropDecl(n) && !info.hasTypedefType() && !info.isInterface(); }
public boolean containsTypeDefinition() { return isConstructor() || isInterface() || hasEnumParameterType() || hasTypedefType(); }
private boolean isCheckablePrivatePropDecl(Node n) { // TODO(tbreisacher): Look for uses of the typedef/interface in type expressions; warn if there // are no uses. JSDocInfo info = NodeUtil.getBestJSDocInfo(n); return isPrivatePropDecl(n) && !info.hasTypedefType() && !info.isInterface(); }
private static boolean isTypedef(Ref ref) { // If this is an annotated EXPR-GET, don't do anything. Node parent = ref.node.getParent(); if (parent.isExprResult()) { JSDocInfo info = ref.node.getJSDocInfo(); if (info != null && info.hasTypedefType()) { return true; } } return false; }
public boolean containsTypeDefinition() { return isConstructor() || isInterface() || hasEnumParameterType() || hasTypedefType(); }
private void visitExportNameDeclaration(Node declaration) { // export var Foo; // export let {a, b:[c,d]} = {}; List<Node> lhsNodes = NodeUtil.findLhsNodesInNode(declaration); for (Node lhs : lhsNodes) { checkState(lhs.isName()); String name = lhs.getString(); exportsByLocalName.put(name, new NameNodePair(name, lhs)); if (declaration.getJSDocInfo() != null && declaration.getJSDocInfo().hasTypedefType()) { typedefs.add(name); } } }
private void identifyNameNode( Node nameNode, JSDocInfo info) { if (info != null && nameNode.isQualifiedName()) { if (info.hasEnumParameterType()) { registry.identifyNonNullableName(nameNode.getQualifiedName()); } else if (info.hasTypedefType()) { registry.identifyNonNullableName(nameNode.getQualifiedName()); } } } }
static boolean hasAnnotatedType(JSDocInfo jsdoc) { if (jsdoc == null) { return false; } return jsdoc.hasType() || jsdoc.hasReturnType() || jsdoc.getParameterCount() > 0 || jsdoc.isConstructorOrInterface() || jsdoc.hasTypedefType() || jsdoc.hasThisType() || jsdoc.hasEnumParameterType(); }
/** * Handles a typedef definition for a goog.provided name. * @param n EXPR_RESULT node. */ private void handleTypedefDefinition( NodeTraversal t, Node n) { JSDocInfo info = n.getFirstChild().getJSDocInfo(); if (t.inGlobalHoistScope() && info != null && info.hasTypedefType()) { String name = n.getFirstChild().getQualifiedName(); if (name != null) { ProvidedName pn = providedNames.get(name); if (pn != null) { pn.addDefinition(n, t.getModule()); } } } }
private static boolean isTypedef(Name name) { if (name.getDeclaration() != null) { // typedefs don't have 'declarations' because you can't assign to them return false; } for (Ref ref : name.getRefs()) { // If this is an annotated EXPR-GET, don't do anything. Node parent = ref.node.getParent(); if (parent.isExprResult()) { JSDocInfo info = ref.node.getJSDocInfo(); if (info != null && info.hasTypedefType()) { return true; } } } return false; }
private void identifyNameNode( Node nameNode, JSDocInfo info) { if (info != null && nameNode.isQualifiedName()) { if (info.hasEnumParameterType()) { registry.identifyNonNullableName(nameNode.getQualifiedName()); } else if (info.hasTypedefType()) { registry.identifyNonNullableName(nameNode.getQualifiedName()); } } } }
static boolean isTypedefDecl(Node n) { if (n.isVar() || n.isName() && n.getParent().isVar() || n.isGetProp() && n.getParent().isExprResult()) { JSDocInfo jsdoc = getBestJSDocInfo(n); return jsdoc != null && jsdoc.hasTypedefType(); } return false; }
static boolean isTypedefDecl(Node n) { if (n.isVar() || (n.isName() && n.getParent().isVar()) || (n.isGetProp() && n.getParent().isExprResult())) { JSDocInfo jsdoc = getBestJSDocInfo(n); return jsdoc != null && jsdoc.hasTypedefType(); } return false; }
/** * @return Whether the given node is a @private property declaration that is not marked constant. */ private boolean isCandidatePropertyDefinition(Node n) { if (!NodeUtil.isLhsOfAssign(n)) { return false; } Node target = n.getFirstChild(); // Check whether the given property access is on 'this' or a static property on a class. if (!(target.isThis() || isConstructor(target))) { return false; } JSDocInfo info = NodeUtil.getBestJSDocInfo(n); return info != null && info.getVisibility() == Visibility.PRIVATE && !info.isConstant() && !info.hasTypedefType() && !info.hasEnumParameterType() && !info.isInterface() && !isFunctionProperty(n); }
private JSType getType(String typeName) { JSType type = registry.getType(typeEnv, typeName); if (type != null) { return type; } StaticTypedSlot slot = typeEnv.getSlot(typeName); type = slot != null ? slot.getType() : null; if (type != null) { if (type.isConstructor() || type.isInterface()) { return type.toMaybeFunctionType().getInstanceType().getRawType(); } if (type.isEnumElementType()) { return type.getEnumeratedTypeOfEnumElement(); } return type; } JSDocInfo jsdoc = slot == null ? null : slot.getJSDocInfo(); if (jsdoc != null && jsdoc.hasTypedefType()) { return this.registry.evaluateTypeExpression(jsdoc.getTypedefType(), typeEnv); } return null; }