toString method

  1. @override
String toString()
override

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Implementation

@override
String toString() {
  String kindName;
  switch (kind) {
    case StringInvocationKind.getter:
      kindName = 'getter';
      break;
    case StringInvocationKind.setter:
      kindName = 'setter';
      break;
    case StringInvocationKind.method:
      kindName = 'method';
      break;
    case StringInvocationKind.constructor:
      kindName = 'constructor';
      break;
    default:
      // Reaching this point is a bug, so we ought to do this:
      // `throw unreachableError('Unexpected StringInvocationKind value');`
      // but it is a bit harsh to raise an exception because of a slightly
      // imprecise diagnostic message, so we use a default instead.
      kindName = '';
  }
  var description = 'NoSuchCapabilityError: no capability to invoke the '
      '$kindName "$memberName"\n'
      'Receiver: $receiver\n'
      'Arguments: $positionalArguments\n';
  if (namedArguments != null) {
    description += 'Named arguments: $namedArguments\n';
  }
  return description;
}