getSourceCode method
Implementation
Future<String> getSourceCode(BuildStep step) async {
if (sourcesCache.containsKey(this.hashCode)) {
return sourcesCache[this.hashCode]!;
}
String part = '';
try {
// TODO: https://github.com/dart-lang/build/issues/2634
// find better way to get method source?
ParsedLibraryResult result = this.session!.getParsedLibraryByElement(this.library) as ParsedLibraryResult;
part = result.getElementDeclaration(this)!.node.toSource();
} on InconsistentAnalysisException {
var resolver = await step.resolver;
ResolvedLibraryResult result = await _getResolvedLibrary(this.library, resolver);
part = result.getElementDeclaration(this)!.node.toSource();
}
//named parameters can be defined
part = part.substring(part.indexOf(') {') + 3, part.length - 1);
sourcesCache[this.hashCode] = part;
//part = '//method_hash:' + this.hashCode.toString() + "\n" + part;
return part;
}