private void validateTypedefs(Node n, JSDocInfo info) { if (info != null && info.getTypedefType() != null && isClassDecl(n)) { reportMisplaced(n, "typedef", "@typedef does not make sense on a class declaration."); } }
private void visitTypedef(Node qnameNode) { Preconditions.checkState(qnameNode.isQualifiedName()); qnameNode.putBooleanProp(Node.ANALYZED_DURING_GTI, true); if (NodeUtil.getRValueOfLValue(qnameNode) != null) { warnings.add(JSError.make(qnameNode, CANNOT_INIT_TYPEDEF)); } if (currentScope.isDefined(qnameNode)) { return; } JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(qnameNode); Typedef td = Typedef.make(jsdoc.getTypedefType()); currentScope.addTypedef(qnameNode, td); }
&& Objects.equals(jsDoc1.getThisType(), jsDoc2.getThisType()) && Objects.equals(jsDoc1.getThrownTypes(), jsDoc2.getThrownTypes()) && Objects.equals(jsDoc1.getTypedefType(), jsDoc2.getTypedefType()) && Objects.equals(jsDoc1.getType(), jsDoc2.getType()) && Objects.equals(jsDoc1.getVersion(), jsDoc2.getVersion())
if (comment != null) JSType typeDefJSType = model.evaluate(comment.getTypedefType()); if (typeDefJSType.isFunctionType())
if (comment != null) JSType typeDefJSType = model.evaluate(comment.getTypedefType()); if (typeDefJSType.isFunctionType())
if (comment != null) JSType typeDefJSType = model.evaluate(comment.getTypedefType()); if (typeDefJSType.isFunctionType())
visitTypeExpression(info.getTypedefType(), false);
/** * Checks if current node contains js docs and checks all types specified in the js doc whether * they have Objects with potentially invalid keys. For example: {@code * Object<!Object, number>}. If such type is found, a warning is reported for the current node. */ private void checkJsdocInfoContainsObjectWithBadKey(NodeTraversal t, Node n) { if (n.getJSDocInfo() != null) { JSDocInfo info = n.getJSDocInfo(); checkTypeContainsObjectWithBadKey(t, n, info.getType()); checkTypeContainsObjectWithBadKey(t, n, info.getReturnType()); checkTypeContainsObjectWithBadKey(t, n, info.getTypedefType()); for (String param : info.getParameterNames()) { checkTypeContainsObjectWithBadKey(t, n, info.getParameterType(param)); } } }
/** * Checks if current node contains js docs and checks all types specified in the js doc whether * they have Objects with potentially invalid keys. For example: {@code * Object<!Object, number>}. If such type is found, a warning is reported for the current node. */ private void checkJsdocInfoContainsObjectWithBadKey(NodeTraversal t, Node n) { if (n.getJSDocInfo() != null) { JSDocInfo info = n.getJSDocInfo(); checkTypeContainsObjectWithBadKey(t, n, info.getType()); checkTypeContainsObjectWithBadKey(t, n, info.getReturnType()); checkTypeContainsObjectWithBadKey(t, n, info.getTypedefType()); for (String param : info.getParameterNames()) { checkTypeContainsObjectWithBadKey(t, n, info.getParameterType(param)); } } }
/** * Handle typedefs. * @param candidate A qualified name node. * @param info JSDoc comments. */ private void checkForTypedef(Node candidate, JSDocInfo info) { if (info == null || !info.hasTypedefType()) { return; } String typedef = candidate.getQualifiedName(); if (typedef == null) { return; } // TODO(nicksantos|user): This is a terrible, terrible hack // to bail out on recursive typedefs. We'll eventually need // to handle these properly. typeRegistry.declareType(typedef, unknownType); JSType realType = info.getTypedefType().evaluate(scope, typeRegistry); if (realType == null) { report(JSError.make(candidate, MALFORMED_TYPEDEF, typedef)); } typeRegistry.overwriteDeclaredType(typedef, realType); if (candidate.isGetProp()) { defineSlot(candidate, candidate.getParent(), getNativeType(NO_TYPE), false); } } } // end GlobalScopeBuilder
if (typeDef != null) JSTypeExpression typeDefTypeExpression = typeDef.getComment().getTypedefType(); if (typeDefTypeExpression != null)
if (typeDef != null) JSTypeExpression typeDefTypeExpression = typeDef.getComment().getTypedefType(); if (typeDefTypeExpression != null)
if (typeDef != null) JSTypeExpression typeDefTypeExpression = typeDef.getComment().getTypedefType(); if (typeDefTypeExpression != null)
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; }
JSTypeExpression expr = info.getTypedefType(); StaticTypedScope<JSType> typedefScope = getScope(scope, name); return expr.evaluate(typedefScope, typeRegistry);
JSType realType = info.getTypedefType().evaluate(currentScope, typeRegistry); if (realType == null) { report(JSError.make(candidate, MALFORMED_TYPEDEF, typedef));
&& (comment.getTypedefType() != null);
&& (comment.getTypedefType() != null); if (isConstructor)
&& (comment.getTypedefType() != null); if (isConstructor)
&& (comment.getTypedefType() != null); if (isConstructor)