<commit_before>import 'package:analyzer/dart/element/type.dart';

import '../../source_gen/common/url_resolver.dart';
import '../compile_metadata.dart';
import 'output_ast.dart' as o;

o.OutputType fromDartType(DartType dartType) {
  if (dartType.isVoid) return null;
  if (dartType is FunctionType) return fromFunctionType(dartType);
  final typeArguments = dartType is ParameterizedType
      ? dartType.typeArguments.map(fromDartType).toList()
      : null;
  return new o.ExternalType(
    new CompileIdentifierMetadata(
      name: dartType.name,
      moduleUrl: moduleUrl(dartType.element),
    ),
    typeArguments,
  );
}

o.FunctionType fromFunctionType(FunctionType functionType) {
  final returnType = fromDartType(functionType.returnType);
  final paramTypes = <o.OutputType>[];
  for (var parameter in functionType.parameters) {
    paramTypes.add(fromDartType(parameter.type));
  }
  return new o.FunctionType(returnType, paramTypes);
}<commit_msg>Resolves generics while converting analyzer types to output ASTs<commit_after>import 'package:analyzer/dart/element/type.dart';

import '../../source_gen/common/url_resolver.dart';
import '../compile_metadata.dart';
import 'output_ast.dart' as o;

/// Creates an AST for code generation from [dartType].
///
/// Note that private types aren't visible to generated code and will be
/// replaced with dynamic.
o.OutputType fromDartType(DartType dartType) {
  if (dartType.isVoid) return null;
  if (dartType is FunctionType) return fromFunctionType(dartType);
  if (dartType is TypeParameterType) {
    // Resolve generic type to its bound or dynamic if it has none.
    final dynamicType = dartType.element.context.typeProvider.dynamicType;
    dartType = dartType.resolveToBound(dynamicType);
  }
  if (dartType.element.isPrivate) return o.DYNAMIC_TYPE;
  final typeArguments = dartType is ParameterizedType
      ? dartType.typeArguments.map(fromDartType).toList()
      : null;
  return new o.ExternalType(
    new CompileIdentifierMetadata(
      name: dartType.name,
      moduleUrl: moduleUrl(dartType.element),
    ),
    typeArguments,
  );
}

/// Creates an AST for code generation from [functionType]
o.FunctionType fromFunctionType(FunctionType functionType) {
  final returnType = fromDartType(functionType.returnType);
  final paramTypes = <o.OutputType>[];
  for (var parameter in functionType.parameters) {
    paramTypes.add(fromDartType(parameter.type));
  }
  return new o.FunctionType(returnType, paramTypes);
}
{'fraction_non_alphanumeric': 0.10593900481540931, 'fraction_numerical': 0.0, 'mean_word_length': 4.479120879120879, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3738332', 'n_tokens_mistral': 773, 'n_tokens_neox': 758, 'n_words': 182}