documentationOfParameter function

Future<String> documentationOfParameter(
  1. ParameterElement parameter,
  2. BuildStep buildStep
)

Implementation

Future<String> documentationOfParameter(
  ParameterElement parameter,
  BuildStep buildStep,
) async {
  final doc = getDescription(parameter, parameter.documentationComment);
  if (doc != null) {
    return doc;
  }

  try {
    final builder = StringBuffer();
    final astNode = await tryGetAstNodeForElement(parameter, buildStep);

    for (Token? token = astNode.beginToken.precedingComments;
        token != null;
        token = token.next) {
      builder.writeln(token);
    }
    final comm = builder.toString();
    if (comm.trim().isNotEmpty) return _cleanDocComment(comm);
  } catch (_) {}

  final parent = parameter.enclosingElement;
  if (parent is ConstructorElement) {
    final field = parent.enclosingElement.getField(parameter.name);
    if (field != null && field.documentationComment != null) {
      return _cleanDocComment(field.documentationComment!);
    }
  }
  return '';
}