visitInstanceCreationExpression method

  1. @override
void visitInstanceCreationExpression(
  1. InstanceCreationExpression node
)
override

Implementation

@override
void visitInstanceCreationExpression(InstanceCreationExpression node) {
  final typeName = node.constructorName.type.name.lexeme;

  if (typeName == 'GetX' || typeName == 'GetBuilder') {
    final typeArgs = node.constructorName.type.typeArguments;
    if (typeArgs != null && typeArgs.arguments.isNotEmpty) {
      final consumedType = typeArgs.arguments.first.toSource();
      nodes.add(
        ConsumerNode(
          consumedClass: consumedType,
          filePath: filePath,
          offset: node.offset,
          length: node.length,
        ),
      );
    }
  } else if (typeName == 'GetMaterialApp') {
    // GetMaterialApp is often used to provide dependencies via 'initialBinding'
    nodes.add(
      MultiProviderNode(
        filePath: filePath,
        offset: node.offset,
        length: node.length,
      ),
    );
  }

  super.visitInstanceCreationExpression(node);
}