visitClassElement method

  1. @override
void visitClassElement(
  1. ClassElement element
)
override

Implementation

@override
void visitClassElement(ClassElement element) {
  super.visitClassElement(element);

  if (!controllerChecker.hasAnnotationOf(element)) {
    return;
  }

  if (_controller != null) {
    throw Exception('Only one controller class per file is allowed');
  }

  final annotation = controllerChecker.annotationsOf(element);

  if (annotation.length > 1) {
    throw Exception('Only one controller annotation per class is allowed');
  }

  if (element.constructors.isEmpty) {
    throw Exception('No constructor found in ${element.name}');
  }

  if (element.constructors.every((e) => e.isPrivate)) {
    throw Exception('No public constructor found in ${element.name}');
  }

  _controller = element;
  _constructor = element.constructors.first;
  _params.addAll(getParams(_constructor!));

  final controller = ControllerAnnotation.fromAnnotation(annotation.first);
  _path = controller.path;

  final methodVisitor = MethodVisitor();
  element.accept(methodVisitor);

  _methods.addAll(methodVisitor.methods.values.expand((e) => e));
}