visitMethodInvocation method

  1. @override
void visitMethodInvocation(
  1. MethodInvocation node
)
override

Implementation

@override
void visitMethodInvocation(MethodInvocation node) {
  final name = node.methodName.name;

  if (name == 'find' && node.target?.toSource() == 'Get') {
    // Get.find<T>()
    final type = node.typeArguments?.arguments.first.toSource() ?? 'dynamic';
    nodes.add(
      ProviderOfNode(
        consumedClass: type,
        isMethodCall: _isFollowedByMethodCall(node),
        filePath: filePath,
        offset: node.offset,
        length: node.length,
      ),
    );
  } else if (name == 'put' && node.target?.toSource() == 'Get') {
    // Get.put(MyController())
    final type =
        node.typeArguments?.arguments.first.toSource() ??
        _inferTypeFromPut(node.argumentList.arguments.first);
    if (type != null) {
      nodes.add(
        ProviderDeclarationNode(
          providerType: 'Get.put',
          providedClass: type,
          filePath: filePath,
          offset: node.offset,
          length: node.length,
        ),
      );
    }
  } else if ((name == 'lazyPut' || name == 'create') &&
      node.target?.toSource() == 'Get') {
    // Get.lazyPut<T>(() => T()) / Get.create<T>(() => T())
    final typeArgs = node.typeArguments;
    String? type;
    if (typeArgs != null && typeArgs.arguments.isNotEmpty) {
      type = typeArgs.arguments.first.toSource();
    } else if (node.argumentList.arguments.isNotEmpty) {
      type = _inferTypeFromFactory(node.argumentList.arguments.first);
    }
    if (type != null) {
      nodes.add(
        ProviderDeclarationNode(
          providerType: 'Get.$name',
          providedClass: type,
          filePath: filePath,
          offset: node.offset,
          length: node.length,
        ),
      );
    }
  } else if (name == 'Obx') {
    // Obx(() => ...) is technically a function/constructor invocation depending on implementation,
    // but often appears as a MethodInvocation if used without 'new'.
    nodes.add(
      ConsumerNode(
        consumedClass:
            'RxState', // Heuristic as Obx detects Rx usage automatically
        filePath: filePath,
        offset: node.offset,
        length: node.length,
      ),
    );
  }

  super.visitMethodInvocation(node);
}