isCompatibleForAutoGeneration function

bool isCompatibleForAutoGeneration(
  1. ClassElement2 element
)

Checks if a class is compatible for auto-generation

Implementation

bool isCompatibleForAutoGeneration(ClassElement2 element) {
  // Must have at least one constructor
  if (element.constructors2.isEmpty) {
    return false;
  }

  // Check if has fromJson factory constructor OR is dart_mappable
  final hasFromJson = element.constructors2.any(
    (ctor) => ctor.isFactory && ctor.name3 == 'fromJson',
  );
  final isDartMappable = getAnnotation(dartMappableChecker, element) != null;

  if (!hasFromJson && !isDartMappable) {
    return false;
  }

  // Check if has constructor with named parameters
  final hasNamedParameters = element.constructors2.any(
    (ctor) => ctor.formalParameters.any((p) => p.isNamed),
  );

  return hasNamedParameters;
}