check method

  1. @override
void check(
  1. DcqRegistry registry
)

Implementation

@override
void check(DcqRegistry registry) {
  registry.addMethodDeclaration((node) {
    if (!_hasOverrideAnnotation(node)) return;

    final body = node.body;
    final params = node.parameters?.parameters ?? <FormalParameter>[];

    // Check expression body: `=> super.method(args)` or `=> super.getter`
    if (body is ExpressionFunctionBody) {
      if (_isPassthroughSuperCall(
        body.expression,
        node.name.lexeme,
        params,
      )) {
        reportAtNode(node);
      }
      return;
    }

    // Check block body with single return/expression statement.
    if (body is BlockFunctionBody) {
      final statements = body.block.statements;
      if (statements.length != 1) return;

      final stmt = statements.first;
      Expression? expr;
      if (stmt is ReturnStatement) {
        expr = stmt.expression;
      } else if (stmt is ExpressionStatement) {
        expr = stmt.expression;
      }
      if (expr != null &&
          _isPassthroughSuperCall(expr, node.name.lexeme, params)) {
        reportAtNode(node);
      }
    }
  });
}