|
|
@ -13,6 +13,7 @@ sealed class TypeResult { |
|
|
|
this.className, { |
|
|
|
this.className, { |
|
|
|
this.generics = const [], |
|
|
|
this.generics = const [], |
|
|
|
this.nullable = false, |
|
|
|
this.nullable = false, |
|
|
|
|
|
|
|
this.isTypeDef = false, |
|
|
|
}) : assert(!className.contains('<'), 'Specify generics in the generics parameter.'), |
|
|
|
}) : assert(!className.contains('<'), 'Specify generics in the generics parameter.'), |
|
|
|
assert(!className.contains('?'), 'Nullability should not be specified in the type.'); |
|
|
|
assert(!className.contains('?'), 'Nullability should not be specified in the type.'); |
|
|
|
|
|
|
|
|
|
|
@ -20,6 +21,9 @@ sealed class TypeResult { |
|
|
|
final List<TypeResult> generics; |
|
|
|
final List<TypeResult> generics; |
|
|
|
final bool nullable; |
|
|
|
final bool nullable; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Whether this type should be represented as a typedef. |
|
|
|
|
|
|
|
final bool isTypeDef; |
|
|
|
|
|
|
|
|
|
|
|
String get name { |
|
|
|
String get name { |
|
|
|
if (generics.isNotEmpty) { |
|
|
|
if (generics.isNotEmpty) { |
|
|
|
final buffer = StringBuffer('$className<') |
|
|
|
final buffer = StringBuffer('$className<') |
|
|
@ -44,6 +48,10 @@ sealed class TypeResult { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Iterable<String> get serializers sync* { |
|
|
|
Iterable<String> get serializers sync* { |
|
|
|
|
|
|
|
if (isTypeDef) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (final class_ in generics) { |
|
|
|
for (final class_ in generics) { |
|
|
|
yield* class_.serializers; |
|
|
|
yield* class_.serializers; |
|
|
|
} |
|
|
|
} |
|
|
@ -104,6 +112,44 @@ sealed class TypeResult { |
|
|
|
// ignore: avoid_returning_this |
|
|
|
// ignore: avoid_returning_this |
|
|
|
TypeResult get dartType => this; |
|
|
|
TypeResult get dartType => this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns `this` with a `true` value for [isTypeDef]. |
|
|
|
|
|
|
|
TypeResult get asTypeDef { |
|
|
|
|
|
|
|
final $this = this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We need to preserve the original runtime type. |
|
|
|
|
|
|
|
return switch ($this) { |
|
|
|
|
|
|
|
TypeResultBase() => TypeResultBase( |
|
|
|
|
|
|
|
className, |
|
|
|
|
|
|
|
nullable: nullable, |
|
|
|
|
|
|
|
isTypeDef: true, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
TypeResultEnum() => TypeResultEnum( |
|
|
|
|
|
|
|
className, |
|
|
|
|
|
|
|
$this.subType, |
|
|
|
|
|
|
|
nullable: nullable, |
|
|
|
|
|
|
|
isTypeDef: true, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
TypeResultList() => TypeResultList( |
|
|
|
|
|
|
|
className, |
|
|
|
|
|
|
|
$this.subType, |
|
|
|
|
|
|
|
nullable: nullable, |
|
|
|
|
|
|
|
isTypeDef: true, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
TypeResultMap() => TypeResultMap( |
|
|
|
|
|
|
|
className, |
|
|
|
|
|
|
|
$this.subType, |
|
|
|
|
|
|
|
nullable: nullable, |
|
|
|
|
|
|
|
isTypeDef: true, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
TypeResultObject() => TypeResultObject( |
|
|
|
|
|
|
|
className, |
|
|
|
|
|
|
|
generics: generics, |
|
|
|
|
|
|
|
nullable: nullable, |
|
|
|
|
|
|
|
isTypeDef: true, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
bool operator ==(final Object other) => |
|
|
|
bool operator ==(final Object other) => |
|
|
|
other is TypeResult && other.className == className && other.generics == generics; |
|
|
|
other is TypeResult && other.className == className && other.generics == generics; |
|
|
|