detect static method

ServiceType detect(
  1. ClassDeclaration node
)

Returns the service type for a given class declaration.

Implementation

static ServiceType detect(ClassDeclaration node) {
  final name = node.name.lexeme.toLowerCase();

  // Check by class name suffix (most common convention)
  if (name.endsWith('service')) return ServiceType.service;
  if (name.endsWith('repository')) return ServiceType.repository;
  if (name.endsWith('repo')) return ServiceType.repository;
  if (name.endsWith('controller')) return ServiceType.controller;
  if (name.endsWith('bloc')) return ServiceType.bloc;
  if (name.endsWith('cubit')) return ServiceType.cubit;
  if (name.endsWith('notifier')) return ServiceType.controller;
  if (name.endsWith('provider')) return ServiceType.service;
  if (name.endsWith('usecase')) return ServiceType.service;
  if (name.endsWith('interactor')) return ServiceType.service;

  // Check by superclass (e.g., extends Bloc, extends Cubit)
  if (node.extendsClause != null) {
    final superName = node.extendsClause!.superclass.name2.lexeme;
    if (superName == 'Bloc') return ServiceType.bloc;
    if (superName == 'Cubit') return ServiceType.cubit;
    if (superName == 'ChangeNotifier') return ServiceType.controller;
    if (superName == 'ValueNotifier') return ServiceType.controller;
  }

  return ServiceType.none;
}