fromDartType method

TypeInfo fromDartType(
  1. DartType type, {
  2. Map<TypeParameterElement, DartType> context = const {},
})

Implementation

TypeInfo fromDartType(DartType type, {Map<TypeParameterElement, DartType> context = const {}}) {

  List<TypeInfo> typeArguments = [];
  if (type is ParameterizedType) {
    for (var arg in type.typeArguments) {
      typeArguments.add(fromDartType(arg, context:context));
    }
  }

  context.forEach((key, value) {
    //key.instantiate(nullabilitySuffix: NullabilitySuffix.none).bound.name!;
    /*output.writeLn(
      "//BOUND OF " + key.name + " " + key.instantiate(nullabilitySuffix: NullabilitySuffix.none).bound.name!
    );*/
    if (key.hashCode == type.hashCode) {
      type = value;
    }
  });

  /*String name = type.getDisplayString(withNullability: false);
  if (type.element != null) {
    if (classNames.containsKey(type.element)) {
      name = classNames[type.element]!;
    }
  }*/
  //output.writeLn('//!!!!' + type.getDisplayString(withNullability: true) + ' <=> ' + (type.element == null ? 'NULL' : type.element!.name!));

  TypeInfo ret = new TypeInfo(
      this,
      type,
      config,
      typeArguments:typeArguments
  );

  if (!allTypes.containsKey(ret.uniqueName)) {
    allTypes[ret.uniqueName] = ret;
  }
  return allTypes[ret.uniqueName]!;

  /*
  if (type is ParameterizedType) {
    for (DartType def in typeMap.allTypesByType.keys) {
      if (def is ParameterizedType) {
        if (def.typeArguments.length == type.typeArguments.length) {

          //DartType instantiated = def.instantiate(type.typeArguments);
          DartType instantiated = (def.element as ClassElement).instantiate(typeArguments: type.typeArguments, nullabilitySuffix: NullabilitySuffix.none);
          if (instantiated == type) {
            fullName = typeMap.allTypesByType[def].fullName;
          }
        }
      }
    }
  }

  //resolveToBound <<
  if (type.getDisplayString(withNullability: false).endsWith('>')) {
    for (var arg in (type as ParameterizedType).typeArguments) {
      typeArguments.add(this.fromDartType(arg, context));
    }
  }
  //}
*/
  /*TypeInfo.fromType(this.omGenerator, this.typeMap, DartType type, ) {

    fullName = type.name!;
   if (typeArgumentsMap.containsKey(type)) {
    this.type = type = typeArgumentsMap[type];
  } else {
    this.type = type;
  }
    if (typeMap.allTypesByType.containsKey(type)) {
      fullName = typeMap.allTypesByType[type]!.fullName;
      element = typeMap.allTypesByType[type]!.element;
    }
    if (type is TypeParameterType) {
    for (DartType def in typeMap.allTypesByType.keys) {
      if (def is TypeParameterType) {
        //DartType instantiated = def.instantiate(type.typeArguments);
        DartType instantiated = def.element.instantiate(nullabilitySuffix: type.nullabilitySuffix);
        if (instantiated == type) {
          fullName = typeMap.allTypesByType[def].fullName;
        }
      }
    }
  }
  */
  //return ret;
}