synthesize method

String synthesize({
  1. required List<VariableUsage> inputs,
  2. required List<VariableUsage> outputs,
  3. List<String> typeParameters = const [],
  4. String methodName = '_extracted',
  5. bool isAsync = false,
})

Generates a proposed function signature from analyzed inputs and outputs.

Implementation

String synthesize({
  required List<VariableUsage> inputs,
  required List<VariableUsage> outputs,
  List<String> typeParameters = const [],
  String methodName = '_extracted',
  bool isAsync = false,
}) {
  final returnType = _buildReturnType(outputs, isAsync: isAsync);
  final params = inputs.isEmpty
      ? ''
      : inputs.map((i) => '${i.type} ${i.name}').join(', ');
  final asyncSuffix = isAsync ? ' async' : '';
  final typeParamsStr = typeParameters.isNotEmpty
      ? '<${typeParameters.join(', ')}>'
      : '';

  return '$returnType $methodName$typeParamsStr($params)$asyncSuffix';
}