staticParameterElement property

  1. @override
ParameterElement? staticParameterElement
override

If this expression is an argument to an invocation, and the AST structure has been resolved, and the function being invoked is known based on static type information, and this expression corresponds to one of the parameters of the function being invoked, then return the parameter element representing the parameter to which the value of this expression will be bound. Otherwise, return null.

Implementation

@override
ParameterElement? get staticParameterElement {
  final parent = this.parent;
  if (parent is ArgumentListImpl) {
    return parent._getStaticParameterElementFor(this);
  } else if (parent is IndexExpressionImpl) {
    if (identical(parent.index, this)) {
      return parent._staticParameterElementForIndex;
    }
  } else if (parent is BinaryExpressionImpl) {
    // TODO(scheglov) https://github.com/dart-lang/sdk/issues/49102
    if (identical(parent.rightOperand, this)) {
      var parameters = parent.staticInvokeType?.parameters;
      if (parameters != null && parameters.isNotEmpty) {
        return parameters[0];
      }
      return null;
    }
  } else if (parent is AssignmentExpressionImpl) {
    if (identical(parent.rightHandSide, this)) {
      return parent._staticParameterElementForRightHandSide;
    }
  } else if (parent is PrefixExpressionImpl) {
    // TODO(scheglov) This does not look right, there is no element for
    // the operand, for `a++` we invoke `a = a + 1`, so the parameter
    // is for `1`, not for `a`.
    return parent._staticParameterElementForOperand;
  } else if (parent is PostfixExpressionImpl) {
    // TODO(scheglov) The same as above.
    return parent._staticParameterElementForOperand;
  }
  return null;
}