if (!Objects.equals(jsDoc1.getParameterNames(), jsDoc2.getParameterNames())) { return false; for (String param : jsDoc1.getParameterNames()) { if (!Objects.equals(jsDoc1.getParameterType(param), jsDoc2.getParameterType(param))) { return false; if (jsDoc1.getMarkers().size() != jsDoc2.getMarkers().size()) { return false; Iterator<Marker> it1 = jsDoc1.getMarkers().iterator(); Iterator<Marker> it2 = jsDoc2.getMarkers().iterator(); while (it1.hasNext()) { if (!Marker.areEquivalent(it1.next(), it2.next())) { return Objects.equals(jsDoc1.getAuthors(), jsDoc2.getAuthors()) && Objects.equals(jsDoc1.getBaseType(), jsDoc2.getBaseType()) && Objects.equals(jsDoc1.getBlockDescription(), jsDoc2.getBlockDescription()) && Objects.equals(jsDoc1.getFileOverview(), jsDoc2.getFileOverview()) && Objects.equals(jsDoc1.getImplementedInterfaces(), jsDoc2.getImplementedInterfaces()) && Objects.equals(jsDoc1.getEnumParameterType(), jsDoc2.getEnumParameterType()) && Objects.equals(jsDoc1.getExtendedInterfaces(), jsDoc2.getExtendedInterfaces()) && Objects.equals(jsDoc1.getLendsName(), jsDoc2.getLendsName()) && Objects.equals(jsDoc1.getLicense(), jsDoc2.getLicense()) && Objects.equals(jsDoc1.getMeaning(), jsDoc2.getMeaning()) && Objects.equals(jsDoc1.getModifies(), jsDoc2.getModifies()) && Objects.equals(jsDoc1.getOriginalCommentString(), jsDoc2.getOriginalCommentString()) && (jsDoc1.getPropertyBitField() == jsDoc2.getPropertyBitField()) && Objects.equals(jsDoc1.getReferences(), jsDoc2.getReferences())
private void maybeEmitJsDoc(JSDocInfo docs, boolean ignoreParams) { if (docs == null) { return; } String desc = docs.getBlockDescription(); if (desc == null) { return; } emit("/**"); emitBreak(); for (String line : Splitter.on('\n').split(desc)) { emit(" *"); if (!line.isEmpty()) emit(line); emitBreak(); } if (!ignoreParams) { for (String name : docs.getParameterNames()) { if (docs.getDescriptionForParameter(name) == null) continue; emit(" * @param"); emit(name); emit(docs.getDescriptionForParameter(name)); emitBreak(); } } emit(" */"); emitBreak(); }
/** * Whether the current doc info has other type tags, like * {@code @param} or {@code @return} or {@code @type} or etc. */ private boolean hasAnyTypeRelatedTags() { return currentInfo.isConstructor() || currentInfo.isInterface() || currentInfo.getParameterCount() > 0 || currentInfo.hasReturnType() || currentInfo.hasBaseType() || currentInfo.getExtendedInterfacesCount() > 0 || currentInfo.getLendsName() != null || currentInfo.hasThisType() || hasAnySingletonTypeTags(); }
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(); }
/** * Determines whether the given JsDoc info declares a function type. */ static boolean isFunctionTypeDeclaration(JSDocInfo info) { return info.getParameterCount() > 0 || info.hasReturnType() || info.hasThisType() || info.isConstructor() || info.isInterface() || info.isAbstract(); }
/** * @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()); }
classInfo.getBlockDescription(), ctorInfo.getBlockDescription()); if (!blockDescription.isEmpty()) { mergedInfo.recordBlockDescription(blockDescription); suppressions.addAll(classInfo.getSuppressions()); suppressions.addAll(ctorInfo.getSuppressions()); if (!suppressions.isEmpty()) { mergedInfo.recordSuppressions(suppressions); if (classInfo.isDeprecated()) { mergedInfo.recordDeprecated(); if (classInfo.getDeprecationReason() != null) { deprecationReason = classInfo.getDeprecationReason(); mergedInfo.recordDeprecationReason(deprecationReason); Visibility visibility = classInfo.getVisibility(); if (visibility != null && visibility != JSDocInfo.Visibility.INHERITED) { mergedInfo.recordVisibility(classInfo.getVisibility()); if (classInfo.isAbstract()) { mergedInfo.recordAbstract(); if (classInfo.isConstant()) { mergedInfo.recordConstancy(); if (classInfo.isExport()) { mergedInfo.recordExport();
JSDocInfo info = n.getJSDocInfo(); if (info != null) { templateTypeNames.addAll(info.getTemplateTypeNames()); templateTypeNames.addAll(info.getTypeTransformations().keySet()); if (info.hasType()) { handleHasType(info.getType(), n); for (String param : info.getParameterNames()) { if (info.hasParameterType(param)) { visitTypeExpression(info.getParameterType(param), false); if (info.hasReturnType()) { visitTypeExpression(info.getReturnType(), false); if (info.hasEnumParameterType()) { visitTypeExpression(info.getEnumParameterType(), false); if (info.hasTypedefType()) { visitTypeExpression(info.getTypedefType(), false); if (info.hasThisType()) { visitTypeExpression(info.getThisType(), true); for (JSTypeExpression expr : info.getThrownTypes()) { visitTypeExpression(expr, false);
if (!ctorInfo.getSuppressions().isEmpty()) { newInfo.recordSuppressions(ctorInfo.getSuppressions()); for (String param : ctorInfo.getParameterNames()) { newInfo.recordParameter(param, ctorInfo.getParameterType(param)); newInfo.recordParameterDescription(param, ctorInfo.getDescriptionForParameter(param)); for (JSTypeExpression thrown : ctorInfo.getThrownTypes()) { newInfo.recordThrowType(thrown); newInfo.recordThrowDescription(thrown, ctorInfo.getThrowsDescriptionForType(thrown)); JSDocInfo.Visibility visibility = ctorInfo.getVisibility(); if (visibility != null && visibility != JSDocInfo.Visibility.INHERITED) { newInfo.recordVisibility(visibility); if (ctorInfo.isDeprecated()) { newInfo.recordDeprecated(); if (ctorInfo.getDeprecationReason() != null && !newInfo.isDeprecationReasonRecorded()) { newInfo.recordDeprecationReason(ctorInfo.getDeprecationReason()); for (String templateType : ctorInfo.getTemplateTypeNames()) { newInfo.recordTemplateTypeName(templateType);
/** * Whether the current doc info has other type tags, like * {@code @param} or {@code @return} or {@code @type} or etc. */ private boolean hasAnyTypeRelatedTags() { return currentInfo.isConstructor() || currentInfo.isInterface() || currentInfo.isAbstract() || currentInfo.getParameterCount() > 0 || currentInfo.hasReturnType() || currentInfo.hasBaseType() || currentInfo.getExtendedInterfacesCount() > 0 || currentInfo.hasLendsName() || currentInfo.hasThisType() || hasAnySingletonTypeTags(); }
JSDocInfoBuilder builder; if (oldJSDocInfo.isConstructorOrInterface() || oldJSDocInfo.hasEnumParameterType()) { Node nameNode = IR.name(name); newNode = IR.assign(getprop, nameNode); if (oldJSDocInfo.isConstructor()) { builder.recordConstructor(); if (oldJSDocInfo.isInterface()) { builder.recordInterface(); if (oldJSDocInfo.usesImplicitMatch()) { builder.recordImplicitMatch(); if (oldJSDocInfo.hasEnumParameterType()) { builder.recordEnumParameterType(oldJSDocInfo.getEnumParameterType());
/** * 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)); } } }
/** * @return Whether there is a declaration present on this {@link JSDocInfo}. */ public boolean containsDeclaration() { return (hasType() || hasReturnType() || hasEnumParameterType() || hasTypedefType() || hasThisType() || getParameterCount() > 0 || visibility != Visibility.INHERITED || getFlag(MASK_CONSTANT | MASK_CONSTRUCTOR | MASK_DEFINE | MASK_OVERRIDE | MASK_EXPORT | MASK_EXPOSE | MASK_DEPRECATED | MASK_INTERFACE | MASK_IMPLICITCAST | MASK_NOSIDEEFFECTS | MASK_RECORD)); }
protected void emitParams(StringBuilder sb) Set<String> parameterNames = getComment().getParameterNames(); for (String paramName : parameterNames) JSTypeExpression parameterType = getComment().getParameterType(paramName); String description = getComment().getDescriptionForParameter(paramName);
private String toParameterString() { if (paramNode != null) { return FunctionUtils.toParameterString(getContext(), getContext().getComment(), paramNode, outputJS); } StringBuilder sb = new StringBuilder(); sb.append("("); int len = comment.getParameterCount(); for (int i = 0; i < len; i++) { String parameterName = comment.getParameterNameAt(i); JSTypeExpression parameterType = comment.getParameterType(parameterName); sb.append(FunctionUtils.toParameter(getContext(), comment, parameterName, parameterType, outputJS)); if (i < len - 1) sb.append(", "); } sb.append(")"); return sb.toString(); }
@Nullable JSDocInfo info, @Nullable ObjectType classExtendsType) { if (info != null && info.hasBaseType()) { if (isConstructor) { ObjectType infoBaseType = info.getBaseType().evaluate(templateScope, typeRegistry).toMaybeObjectType(); if (info != null && info.getImplementedInterfaceCount() > 0) { if (isConstructor) { implementedInterfaces = new ArrayList<>(); Set<JSType> baseInterfaces = new HashSet<>(); for (JSTypeExpression t : info.getImplementedInterfaces()) { JSType maybeInterType = t.evaluate(templateScope, typeRegistry); extendedInterfaces = new ArrayList<>(); if (info != null) { for (JSTypeExpression t : info.getExtendedInterfaces()) { JSType maybeInterfaceType = t.evaluate(templateScope, typeRegistry); if (maybeInterfaceType != null &&
else sb.append(" * @constructor\n"); if (getComment().hasBaseType()) emitImplements(sb); sb.append("\n"); List<JSTypeExpression> implementedInterfaces = getComment().getImplementedInterfaces(); int len = implementedInterfaces.size(); if (len != 0) String comment = getComment().getOriginalCommentString(); int c = comment.indexOf("IArrayLike"); int c1 = comment.indexOf('<', c);
private void maybeAddJsDocUsages(NodeTraversal t, Node n) { JSDocInfo info = n.getJSDocInfo(); if (info == null) { return; } if (declaresFunctionOrClass(n)) { for (JSTypeExpression expr : info.getImplementedInterfaces()) { maybeAddUsage(t, n, expr); } if (info.getBaseType() != null) { maybeAddUsage(t, n, info.getBaseType()); } for (JSTypeExpression extendedInterface : info.getExtendedInterfaces()) { maybeAddUsage(t, n, extendedInterface); } } for (Node typeNode : info.getTypeNodes()) { maybeAddWeakUsage(t, n, typeNode); } }
/** * @param node A getter or setter node. */ @Nullable private JSTypeExpression getTypeFromGetterOrSetter(Node node) { JSDocInfo info = node.getJSDocInfo(); if (info != null) { boolean getter = node.isGetterDef() || node.getBooleanProp(Node.COMPUTED_PROP_GETTER); if (getter && info.getReturnType() != null) { return info.getReturnType(); } else { Set<String> paramNames = info.getParameterNames(); if (paramNames.size() == 1) { JSTypeExpression paramType = info.getParameterType(Iterables.getOnlyElement(info.getParameterNames())); if (paramType != null) { return paramType; } } } } return null; }
if (declInfo == null || !declInfo.hasEnumParameterType()) { return; nodeToWarn, valueEnumPrimitiveType, declInfo.getEnumParameterType().evaluate(t.getTypedScope(), typeRegistry), "incompatible enum element types");