From ce75f7c5864fc0885538faf2e46b78b1b56dd899 Mon Sep 17 00:00:00 2001 From: Fodil A Date: Wed, 25 Nov 2020 19:50:10 +0100 Subject: [PATCH 1/3] Fix Bad state: NoSuchMethodError: The getter 'length' was called on null. --- lib/src/executable.dart | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/src/executable.dart b/lib/src/executable.dart index cf982d9..df64510 100644 --- a/lib/src/executable.dart +++ b/lib/src/executable.dart @@ -11,20 +11,32 @@ abstract class Executable { final SendPort _sendPort; U instanceOf(String typeName, - {List positionalArguments: const [], Map namedArguments, Symbol constructorName}) { - ClassMirror typeMirror = currentMirrorSystem().isolate.rootLibrary.declarations[new Symbol(typeName)]; + {List positionalArguments: const [], + Map namedArguments = const {}, + Symbol constructorName}) { + ClassMirror typeMirror = currentMirrorSystem() + .isolate + .rootLibrary + .declarations[new Symbol(typeName)]; if (typeMirror == null) { typeMirror = currentMirrorSystem() .libraries .values - .where((lib) => lib.uri.scheme == "package" || lib.uri.scheme == "file") + .where( + (lib) => lib.uri.scheme == "package" || lib.uri.scheme == "file") .expand((lib) => lib.declarations.values) - .firstWhere((decl) => decl is ClassMirror && MirrorSystem.getName(decl.simpleName) == typeName, - orElse: () => throw new ArgumentError("Unknown type '$typeName'. Did you forget to import it?")); + .firstWhere( + (decl) => + decl is ClassMirror && + MirrorSystem.getName(decl.simpleName) == typeName, + orElse: () => throw new ArgumentError( + "Unknown type '$typeName'. Did you forget to import it?")); } - return typeMirror.newInstance(constructorName ?? const Symbol(""), positionalArguments, namedArguments).reflectee - as U; + return typeMirror + .newInstance(constructorName ?? const Symbol(""), positionalArguments, + namedArguments) + .reflectee as U; } void send(dynamic message) { From 1f8ce5f075a48d0ae0e85147df5954157670d521 Mon Sep 17 00:00:00 2001 From: Fodil A Date: Wed, 25 Nov 2020 21:29:19 +0100 Subject: [PATCH 2/3] Fix deprecated usage of analyzer --- lib/src/source_generator.dart | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/src/source_generator.dart b/lib/src/source_generator.dart index 3793957..500561c 100644 --- a/lib/src/source_generator.dart +++ b/lib/src/source_generator.dart @@ -3,15 +3,20 @@ import 'dart:isolate'; import 'dart:mirrors'; import 'dart:async'; -import 'package:analyzer/analyzer.dart'; +import 'package:analyzer/dart/ast/ast.dart'; +import 'package:analyzer/dart/analysis/features.dart'; +import 'package:analyzer/dart/analysis/utilities.dart'; import 'package:isolate_executor/src/executable.dart'; +import 'package:pub_semver/pub_semver.dart'; class SourceGenerator { - SourceGenerator(this.executableType, {this.imports, this.additionalContents, this.additionalTypes}); + SourceGenerator(this.executableType, + {this.imports, this.additionalContents, this.additionalTypes}); Type executableType; - String get typeName => MirrorSystem.getName(reflectType(executableType).simpleName); + String get typeName => + MirrorSystem.getName(reflectType(executableType).simpleName); final List imports; final String additionalContents; final List additionalTypes; @@ -50,11 +55,15 @@ Future main (List args, Map message) async { } static Future _getClass(Type type) async { - final uri = await Isolate.resolvePackageUri(reflectClass(type).location.sourceUri); - final fileUnit = parseDartFile(uri.toFilePath(windows: Platform.isWindows)); + final uri = + await Isolate.resolvePackageUri(reflectClass(type).location.sourceUri); + final fileUnit = parseFile( + path: uri.toFilePath(windows: Platform.isWindows), + featureSet: FeatureSet.fromEnableFlags2( + flags: [], sdkLanguageVersion: Version(2, 8, 0))); final typeName = MirrorSystem.getName(reflectClass(type).simpleName); - return fileUnit.declarations + return fileUnit.unit.declarations .where((u) => u is ClassDeclaration) .map((cu) => cu as ClassDeclaration) .firstWhere((classDecl) => classDecl.name.name == typeName); From 31b74c4650d60b8f7cfc6852295c4af3e34951a0 Mon Sep 17 00:00:00 2001 From: Fodil A Date: Wed, 25 Nov 2020 21:30:41 +0100 Subject: [PATCH 3/3] bump analyzer version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index a963ba2..dd64999 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: ">=2.0.0 <3.0.0" dependencies: - analyzer: '>=0.32.0 <0.50.0' + analyzer: '>=0.40.6 <0.41.0' dev_dependencies: test: ^1.3.0