generateTypedef method
Future<TypedefDeclaration>
generateTypedef(
- TypedefMirror typedefMirror,
- Package package,
- String libraryUri,
- Uri sourceUri,
Generate typedef declaration with analyzer support
Implementation
Future<TypedefDeclaration> generateTypedef(mirrors.TypedefMirror typedefMirror, Package package, String libraryUri, Uri sourceUri) async {
final typedefName = mirrors.MirrorSystem.getName(typedefMirror.simpleName);
final typedefElement = await _getTypedefElement(typedefName, sourceUri);
final dartType = typedefElement?.aliasedType;
Type runtimeType = typedefMirror.hasReflectedType ? typedefMirror.reflectedType : typedefMirror.runtimeType;
if(GenericTypeParser.shouldCheckGeneric(runtimeType)) {
final annotations = await _extractAnnotations(typedefMirror.metadata, package);
final resolvedType = await _resolveTypeFromGenericAnnotation(annotations, typedefName);
if (resolvedType != null) {
runtimeType = resolvedType;
}
}
StandardTypedefDeclaration reflectedTypedef = StandardTypedefDeclaration(
name: typedefName,
type: runtimeType,
element: typedefElement,
dartType: dartType,
qualifiedName: _buildQualifiedName(typedefName, (typedefMirror.location?.sourceUri ?? Uri.parse(libraryUri)).toString()),
parentLibrary: _libraryCache[libraryUri]!,
aliasedType: await generateType(typedefMirror.referent, package, libraryUri),
isNullable: false,
isPublic: !_isInternal(typedefName),
isSynthetic: _isSynthetic(typedefName),
typeArguments: await _extractTypeArgumentsAsLinks(typedefMirror.typeVariables, typedefElement?.typeParameters, package, libraryUri),
annotations: await _extractAnnotations(typedefMirror.metadata, package),
sourceLocation: sourceUri,
);
_typeCache[runtimeType] = reflectedTypedef;
return reflectedTypedef;
}