From 35bc4354397f99bb726c97ecb5d9a57ed85235bf Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Thu, 25 Feb 2021 22:07:45 -0800 Subject: [PATCH 01/25] nullsafety --- lib/slow_coerce.dart | 51 +++++++++++++++------ lib/src/analyzer.dart | 18 ++++---- lib/src/build.dart | 15 +++--- lib/src/build_context.dart | 51 +++++++++++---------- lib/src/build_manager.dart | 8 ++-- lib/src/context.dart | 4 +- lib/src/file_system.dart | 9 ++-- lib/src/generator.dart | 11 ++--- lib/src/mirror_coerce.dart | 8 ++-- lib/src/mirror_context.dart | 12 +++-- pubspec.yaml | 20 ++++---- test/coerce_test.dart | 49 ++++++++++---------- test/context_test.dart | 2 +- test/project_analyzer_test.dart | 4 +- test/test_packages/application/pubspec.yaml | 2 +- test/test_packages/dependency/pubspec.yaml | 2 +- 16 files changed, 150 insertions(+), 116 deletions(-) diff --git a/lib/slow_coerce.dart b/lib/slow_coerce.dart index e7ce986..b664ed9 100644 --- a/lib/slow_coerce.dart +++ b/lib/slow_coerce.dart @@ -3,13 +3,16 @@ import 'package:runtime/src/exceptions.dart'; const String _listPrefix = "List<"; const String _mapPrefix = "Map(dynamic input) { - if (input == null) { - return null; - } - +T? cast(dynamic input) { try { - final typeString = T.toString(); + var typeString = T.toString(); + if (typeString.endsWith('?')) { + if (input == null) { + return null; + } else { + typeString = typeString.substring(0, typeString.length - 1); + } + } if (typeString.startsWith(_listPrefix)) { if (input is! List) { throw TypeError(); @@ -25,15 +28,29 @@ T cast(dynamic input) { return List.from(input) as T; } else if (typeString == "List") { return List.from(input) as T; + } else if (typeString == "List") { + return List.from(input) as T; + } else if (typeString == "List") { + return List.from(input) as T; + } else if (typeString == "List") { + return List.from(input) as T; + } else if (typeString == "List") { + return List.from(input) as T; + } else if (typeString == "List") { + return List.from(input) as T; } else if (typeString == "List>") { + print(typeString); final objects = >[]; - (input as List).forEach((o) { + input.forEach((o) { + objects.add(o); + }); + return objects as T; + } else { + final objects = ?>[]; + input.forEach((o) { if (o == null) { objects.add(null); } else { - if (o is! Map) { - throw TypeError(); - } objects.add(o); } }); @@ -55,13 +72,21 @@ T cast(dynamic input) { return Map.from(inputMap) as T; } else if (typeString == "Map") { return Map.from(inputMap) as T; + } else if (typeString == "Map") { + return Map.from(inputMap) as T; + } else if (typeString == "Map") { + return Map.from(inputMap) as T; + } else if (typeString == "Map") { + return Map.from(inputMap) as T; + } else if (typeString == "Map") { + return Map.from(inputMap) as T; + } else if (typeString == "Map") { + return Map.from(inputMap) as T; } } return input as T; - } on CastError { - throw TypeCoercionException(T, input.runtimeType as Type); } on TypeError { - throw TypeCoercionException(T, input.runtimeType as Type); + throw TypeCoercionException(T, input.runtimeType); } } diff --git a/lib/src/analyzer.dart b/lib/src/analyzer.dart index 87be105..bb00296 100644 --- a/lib/src/analyzer.dart +++ b/lib/src/analyzer.dart @@ -20,13 +20,13 @@ class CodeAnalyzer { return getPath(uri); } - final Uri uri; + late final Uri uri; - AnalysisContextCollection contexts; + late AnalysisContextCollection contexts; Map _resolvedAsts = {}; - Future resolveUnitAt(Uri uri) async { + Future resolveUnitAt(Uri uri) async { for (var ctx in contexts.contexts) { final path = getPath(uri); if (_resolvedAsts.containsKey(path)) { @@ -34,7 +34,7 @@ class CodeAnalyzer { } final output = await ctx.currentSession.getResolvedUnit(path); - if (output.state == ResultState.VALID) { + if (output!.state == ResultState.VALID) { _resolvedAsts[path] = output; return output; } @@ -44,11 +44,11 @@ class CodeAnalyzer { "${contexts.contexts.map((c) => c.contextRoot.root.toUri()).join(", ")})"); } - ClassDeclaration getClassFromFile(String className, Uri fileUri) { + ClassDeclaration? getClassFromFile(String className, Uri fileUri) { return _getFileAstRoot(fileUri) .declarations - .whereType() - .firstWhere((c) => c.name.name == className, orElse: () => null); + .whereType() + .firstWhere((c) => c!.name.name == className, orElse: () => null); } List getSubclassesFromFile( @@ -56,14 +56,14 @@ class CodeAnalyzer { return _getFileAstRoot(fileUri) .declarations .whereType() - .where((c) => c.extendsClause.superclass.name.name == superclassName) + .where((c) => c.extendsClause!.superclass.name.name == superclassName) .toList(); } CompilationUnit _getFileAstRoot(Uri fileUri) { final path = getPath(fileUri); if (_resolvedAsts.containsKey(path)) { - return _resolvedAsts[path].unit; + return _resolvedAsts[path]!.unit!; } final unit = contexts.contextFor(path).currentSession.getParsedUnit(path); diff --git a/lib/src/build.dart b/lib/src/build.dart index 2d0b5e4..21621e4 100644 --- a/lib/src/build.dart +++ b/lib/src/build.dart @@ -11,15 +11,16 @@ class Build { final BuildContext context; Map get packageMap => _packageMap ??= context.resolvedPackages; - Map _packageMap; + Map? _packageMap; Future execute() async { final compilers = context.context.compilers; print("Resolving ASTs..."); - final astsToResolve = Set.from(compilers.expand((c) => c.getUrisToResolve(context))); + final astsToResolve = + Set.from(compilers.expand((c) => c.getUrisToResolve(context))); await Future.forEach(astsToResolve, (astUri) async { - await context.analyzer.resolveUnitAt(context.resolveUri(astUri)); + await context.analyzer.resolveUnitAt(context.resolveUri(astUri as Uri)!); }); print("Generating runtime..."); @@ -42,7 +43,7 @@ class Build { 'environment': {'sdk': '>=2.7.0 <3.0.0'}, 'dependency_overrides': {} }; - Map overrides = pubspecMap['dependency_overrides']; + Map? overrides = pubspecMap['dependency_overrides'] as Map?; var sourcePackageIsCompiled = false; compilers.forEach((compiler) { @@ -56,7 +57,7 @@ class Build { compiler.deflectPackage(Directory.fromUri(targetDirUri)); if (packageInfo.name != nameOfPackageBeingCompiled) { - overrides[packageInfo.name] = { + overrides![packageInfo.name] = { "path": targetDirUri.toFilePath(windows: Platform.isWindows) }; } else { @@ -158,7 +159,7 @@ class Build { } _PackageInfo _getPackageInfoForCompiler(Compiler compiler) { - final compilerUri = reflect(compiler).type.location.sourceUri; + final compilerUri = reflect(compiler).type.location!.sourceUri; final parser = RegExp("package\:([^\/]+)"); final parsed = parser.firstMatch(compilerUri.toString()); if (parsed == null) { @@ -167,7 +168,7 @@ class Build { } final packageName = parsed.group(1); - return _getPackageInfoForName(packageName); + return _getPackageInfoForName(packageName!); } } diff --git a/lib/src/build_context.dart b/lib/src/build_context.dart index 5953697..c01d166 100644 --- a/lib/src/build_context.dart +++ b/lib/src/build_context.dart @@ -2,18 +2,19 @@ import 'dart:io'; import 'dart:mirrors'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:pubspec_parse/pubspec_parse.dart'; +import 'package:pubspec2/pubspec2.dart'; import 'package:runtime/src/analyzer.dart'; import 'package:runtime/src/context.dart'; import 'package:runtime/src/file_system.dart'; import 'package:runtime/src/mirror_context.dart'; import 'package:yaml/yaml.dart'; +import 'package:path/path.dart'; /// Configuration and context values used during [Build.execute]. class BuildContext { BuildContext(this.rootLibraryFileUri, this.buildDirectoryUri, this.executableUri, this.source, - {bool forTests}) + {bool? forTests}) : this.forTests = forTests ?? false { analyzer = CodeAnalyzer(sourceApplicationDirectory.uri); } @@ -35,7 +36,7 @@ class BuildContext { 'forTests': forTests }; - CodeAnalyzer analyzer; + late CodeAnalyzer analyzer; /// A [Uri] to the library file of the application to be compiled. final Uri rootLibraryFileUri; @@ -61,7 +62,7 @@ class BuildContext { .resolve("main_test.dart") : buildDirectoryUri.resolve("main.dart"); - Pubspec get sourceApplicationPubspec => Pubspec.parse( + PubSpec get sourceApplicationPubspec => PubSpec.fromYamlString( File.fromUri(sourceApplicationDirectory.uri.resolve("pubspec.yaml")) .readAsStringSync()); @@ -117,16 +118,16 @@ class BuildContext { return file; } - Uri resolveUri(Uri uri) { + Uri? resolveUri(Uri? uri) { var outputUri = uri; if (outputUri?.scheme == "package") { - final segments = outputUri.pathSegments; - outputUri = resolvedPackages[segments.first].resolve("lib/"); + final segments = outputUri!.pathSegments; + outputUri = resolvedPackages[segments.first]!.resolve("lib/"); for (var i = 1; i < segments.length; i++) { if (i < segments.length - 1) { - outputUri = outputUri.resolve("${segments[i]}/"); + outputUri = outputUri!.resolve("${segments[i]}/"); } else { - outputUri = outputUri.resolve(segments[i]); + outputUri = outputUri!.resolve(segments[i]); } } } else if (outputUri != null && !outputUri.isAbsolute) { @@ -137,7 +138,7 @@ class BuildContext { } List getImportDirectives( - {Uri uri, String source, bool alsoImportOriginalFile = false}) { + {Uri? uri, String? source, bool alsoImportOriginalFile = false}) { if (uri != null && source != null) { throw ArgumentError( "either uri or source must be non-null, but not both"); @@ -154,18 +155,20 @@ class BuildContext { } var fileUri = resolveUri(uri); - final text = source ?? File.fromUri(fileUri).readAsStringSync(); + final text = source ?? File.fromUri(fileUri!).readAsStringSync(); final importRegex = RegExp("import [\\'\\\"]([^\\'\\\"]*)[\\'\\\"];"); final imports = importRegex.allMatches(text).map((m) { - var importedUri = Uri.parse(m.group(1)); - if (importedUri.scheme != "package" && !importedUri.isAbsolute) { - throw ArgumentError( - "Cannot resolve relative URIs in file located at $uri. " - "Replace imported URIs with package or absolute URIs"); + var importedUri = Uri.parse(m.group(1)!); + if (importedUri.scheme == "package") { + return text.substring(m.start, m.end); + } else if (!importedUri.isAbsolute) { + final path = fileUri!.resolve(importedUri.path); + return 'import \'file:${absolute(path.path)}\';'; } - - return text.substring(m.start, m.end); + throw ArgumentError( + "Cannot resolve relative URIs in file located at $uri. " + "Replace imported URIs with package or absolute URIs"); }).toList(); if (alsoImportOriginalFile) { @@ -175,26 +178,26 @@ class BuildContext { return imports; } - ClassDeclaration getClassDeclarationFromType(Type type) { + ClassDeclaration? getClassDeclarationFromType(Type type) { final classMirror = reflectType(type); return analyzer.getClassFromFile( MirrorSystem.getName(classMirror.simpleName), - resolveUri(classMirror.location.sourceUri)); + resolveUri(classMirror.location!.sourceUri)!); } List getAnnotationsFromField(Type _type, String propertyName) { var type = reflectClass(_type); var field = - getClassDeclarationFromType(type.reflectedType).getField(propertyName); + getClassDeclarationFromType(type.reflectedType)!.getField(propertyName); while (field == null) { - type = type.superclass; + type = type.superclass!; if (type.reflectedType == Object) { break; } - field = getClassDeclarationFromType(type.reflectedType) + field = getClassDeclarationFromType(type.reflectedType)! .getField(propertyName); } - return (field.parent.parent as FieldDeclaration).metadata.toList(); + return (field!.parent!.parent as FieldDeclaration).metadata.toList(); } } diff --git a/lib/src/build_manager.dart b/lib/src/build_manager.dart index 0d1a441..29a6154 100644 --- a/lib/src/build_manager.dart +++ b/lib/src/build_manager.dart @@ -11,7 +11,7 @@ class BuildExecutable extends Executable { context = BuildContext.fromMap(message); } - BuildContext context; + late BuildContext context; @override Future execute() async { @@ -36,10 +36,8 @@ class BuildManager { // Here is where we need to provide a temporary copy of the script file with the main function stripped; // this is because when the RuntimeGenerator loads, it needs Mirror access to any declarations in this file var scriptSource = context.source; - final strippedScriptFile = - File.fromUri(context.targetScriptFileUri) - ..writeAsStringSync(scriptSource); - + final strippedScriptFile = File.fromUri(context.targetScriptFileUri) + ..writeAsStringSync(scriptSource); final analyzer = CodeAnalyzer(strippedScriptFile.absolute.uri); final analyzerContext = analyzer.contexts.contextFor(analyzer.path); final mainFunctions = analyzerContext.currentSession diff --git a/lib/src/context.dart b/lib/src/context.dart index 1f18609..8237cba 100644 --- a/lib/src/context.dart +++ b/lib/src/context.dart @@ -14,10 +14,10 @@ abstract class RuntimeContext { _current = runtime; } - static RuntimeContext _current; + static RuntimeContext? _current; /// The runtimes available to the executing application. - RuntimeCollection runtimes; + late RuntimeCollection runtimes; /// Gets a runtime object for [type]. /// diff --git a/lib/src/file_system.dart b/lib/src/file_system.dart index 275089f..54d247d 100644 --- a/lib/src/file_system.dart +++ b/lib/src/file_system.dart @@ -1,11 +1,9 @@ import 'dart:io'; -import 'package:meta/meta.dart'; - /// Recursively copies the contents of the directory at [src] to [dst]. /// /// Creates directory at [dst] recursively if it doesn't exist. -void copyDirectory({@required Uri src, @required Uri dst}) { +void copyDirectory({required Uri src, required Uri dst}) { final srcDir = Directory.fromUri(src); final dstDir = Directory.fromUri(dst); if (!dstDir.existsSync()) { @@ -30,7 +28,8 @@ void copyDirectory({@required Uri src, @required Uri dst}) { /// /// If locations on disk are relative Uris, they are resolved by [relativeTo]. [relativeTo] defaults /// to the CWD. -Map getResolvedPackageUris(Uri packagesFileUri, {Uri relativeTo}) { +Map getResolvedPackageUris(Uri packagesFileUri, + {Uri? relativeTo}) { relativeTo ??= Directory.current.uri; final packagesFile = File.fromUri(packagesFileUri); @@ -53,7 +52,7 @@ Map getResolvedPackageUris(Uri packagesFileUri, {Uri relativeTo}) { return MapEntry( packageName, - Directory.fromUri(relativeTo.resolveUri(uri).normalizePath()) + Directory.fromUri(relativeTo!.resolveUri(uri).normalizePath()) .parent .uri); })); diff --git a/lib/src/generator.dart b/lib/src/generator.dart index a246953..9b69225 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -1,15 +1,13 @@ import 'dart:async'; import 'dart:io'; -import 'package:meta/meta.dart'; - const String _directiveToken = "___DIRECTIVES___"; const String _assignmentToken = "___ASSIGNMENTS___"; class RuntimeGenerator { List<_RuntimeElement> _elements = []; - void addRuntime({@required String name, @required String source}) { + void addRuntime({required String name, String source = ''}) { _elements.add(_RuntimeElement(name, source)); } @@ -24,7 +22,8 @@ class RuntimeGenerator { srcDir.createSync(recursive: true); } - final libraryFile = File.fromUri(libDir.uri.resolve("generated_runtime.dart")); + final libraryFile = + File.fromUri(libDir.uri.resolve("generated_runtime.dart")); await libraryFile.writeAsString(loaderSource); final pubspecFile = File.fromUri(dir.uri.resolve("pubspec.yaml")); @@ -74,8 +73,8 @@ class GeneratedContext extends RuntimeContext { String get loaderSource { return _loaderShell - .replaceFirst(_directiveToken, _directives) - .replaceFirst(_assignmentToken, _assignments); + .replaceFirst(_directiveToken, _directives) + .replaceFirst(_assignmentToken, _assignments); } String get _directives { diff --git a/lib/src/mirror_coerce.dart b/lib/src/mirror_coerce.dart index 74e4e8e..9f86302 100644 --- a/lib/src/mirror_coerce.dart +++ b/lib/src/mirror_coerce.dart @@ -4,7 +4,7 @@ import 'package:runtime/src/exceptions.dart'; dynamic runtimeCast(dynamic object, TypeMirror intoType) { final exceptionToThrow = - TypeCoercionException(intoType.reflectedType, object.runtimeType as Type); + TypeCoercionException(intoType.reflectedType, object.runtimeType); try { final objectType = reflect(object).type; @@ -18,7 +18,7 @@ dynamic runtimeCast(dynamic object, TypeMirror intoType) { } final elementType = intoType.typeArguments.first; - final elements = (object as List).map((e) => runtimeCast(e, elementType)); + final elements = object.map((e) => runtimeCast(e, elementType)); return (intoType as ClassMirror).newInstance(#from, [elements]).reflectee; } else if (intoType.isSubtypeOf(reflectType(Map, [String, dynamic]))) { if (object is! Map) { @@ -28,15 +28,13 @@ dynamic runtimeCast(dynamic object, TypeMirror intoType) { final output = (intoType as ClassMirror) .newInstance(const Symbol(""), []).reflectee as Map; final valueType = intoType.typeArguments.last; - (object as Map).forEach((key, val) { + object.forEach((key, val) { output[key] = runtimeCast(val, valueType); }); return output; } } on TypeError { throw exceptionToThrow; - } on CastError { - throw exceptionToThrow; } on TypeCoercionException { throw exceptionToThrow; } diff --git a/lib/src/mirror_context.dart b/lib/src/mirror_context.dart index 4cd8a9b..e1f3807 100644 --- a/lib/src/mirror_context.dart +++ b/lib/src/mirror_context.dart @@ -65,9 +65,13 @@ class MirrorContext extends RuntimeContext { } } -T firstMetadataOfType(DeclarationMirror dm, {TypeMirror dynamicType}) { +T? firstMetadataOfType(DeclarationMirror dm, {TypeMirror? dynamicType}) { final tMirror = dynamicType ?? reflectType(T); - return dm.metadata - .firstWhere((im) => im.type.isSubtypeOf(tMirror), orElse: () => null) - ?.reflectee as T; + try { + return dm.metadata + .firstWhere((im) => im.type.isSubtypeOf(tMirror)) + .reflectee as T; + } finally { + return null; + } } diff --git a/pubspec.yaml b/pubspec.yaml index 4449af4..8d7c7aa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,17 +5,21 @@ author: Joe Conway homepage: https://stablekernel.com environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' dependencies: - analyzer: '>=0.32.0 <0.50.0' - args: ^1.5.0 - pubspec_parse: '>=0.1.4 <1.0.0' - isolate_executor: ^2.0.0 - meta: ^1.1.5 - yaml: ^2.1.15 + analyzer: ^1.0.0 + args: ^2.0.0 + pubspec2: + git: + url: https://github.com/bsutton/pubspec.git + ref: nullsafety + isolate_executor: + git: https://github.com/j4qfrost/dart-isolate-executor + yaml: ^3.0.0 dev_dependencies: pedantic: ^1.0.0 test: ^1.0.0 - command_line_agent: ^1.0.0-b1 \ No newline at end of file + command_line_agent: + git: https://github.com/j4qfrost/dart-test-terminal.git \ No newline at end of file diff --git a/test/coerce_test.dart b/test/coerce_test.dart index 66c0fdf..be5dcaa 100644 --- a/test/coerce_test.dart +++ b/test/coerce_test.dart @@ -15,7 +15,8 @@ void main() { return cast(input); }; - final testInvocation = (String suiteName, T Function(dynamic input) coerce) { + final testInvocation = + (String suiteName, T? Function(dynamic input) coerce) { group("($suiteName) Primitive Types (success)", () { test("dynamic", () { final x = coerce(wash("foo")); @@ -26,22 +27,22 @@ void main() { final x = coerce(wash(2)); expect(x, 2); - expect(coerce(null), null); + expect(coerce(null), null); }); test("String", () { final x = coerce(wash("string")); expect(x, "string"); - expect(coerce(null), null); + expect(coerce(null), null); }); test("bool", () { final x = coerce(wash(true)); expect(x, true); - expect(coerce(null), null); + expect(coerce(null), null); }); test("num", () { final x = coerce(wash(3.2)); expect(x, 3.2); - expect(coerce(null), null); + expect(coerce(null), null); final y = coerce(wash(3)); expect(y, 3); @@ -49,7 +50,7 @@ void main() { test("double", () { final x = coerce(wash(3.2)); expect(x, 3.2); - expect(coerce(null), null); + expect(coerce(null), null); }); }); @@ -103,50 +104,50 @@ void main() { group("($suiteName) List Types (success)", () { test("null/empty", () { - List x = coerce>(null); + List? x = coerce?>(null); expect(x, null); - x = coerce>([]); + x = coerce>([])!; expect(x, []); }); test("int", () { - List x = coerce>(wash([2, 4])); + List x = coerce>(wash([2, 4]))!; expect(x, [2, 4]); }); test("String", () { - List x = coerce>(wash(["a", "b", "c"])); + List x = coerce>(wash(["a", "b", "c"]))!; expect(x, ["a", "b", "c"]); }); test("num", () { - List x = coerce>(wash([3.0, 2])); + List x = coerce>(wash([3.0, 2]))!; expect(x, [3.0, 2]); }); test("bool", () { - List x = coerce>(wash([false, true])); + List x = coerce>(wash([false, true]))!; expect(x, [false, true]); }); - test("list of map", () { - List> x = coerce>>(wash([ + List?> x = + coerce?>>(wash([ {"a": "b"}, null, {"a": 1} - ])); + ]))!; expect(x, [ {"a": "b"}, null, {"a": 1} ]); - expect(coerce>>(null), null); - expect(coerce>>([]), >[]); + expect(coerce>?>(null), null); + expect( + coerce>>([]), >[]); }); - }); group("($suiteName) List Types (cast error)", () { @@ -199,28 +200,30 @@ void main() { group("($suiteName) Map types (success)", () { test("null", () { - Map x = coerce>(null); + Map? x = coerce?>(null); expect(x, null); }); test("string->dynamic", () { Map x = - coerce>(wash({"a": 1, "b": "c"})); + coerce>(wash({"a": 1, "b": "c"}))!; expect(x, {"a": 1, "b": "c"}); }); test("string->int", () { - Map x = coerce>(wash({"a": 1, "b": 2})); + Map x = coerce>(wash({"a": 1, "b": 2}))!; expect(x, {"a": 1, "b": 2}); }); test("string->num", () { - Map x = coerce>(wash({"a": 1, "b": 2.0})); + Map x = + coerce>(wash({"a": 1, "b": 2.0}))!; expect(x, {"a": 1, "b": 2.0}); }); test("string->string", () { - Map x = coerce>(wash({"a": "1", "b": "2.0"})); + Map x = + coerce>(wash({"a": "1", "b": "2.0"}))!; expect(x, {"a": "1", "b": "2.0"}); }); }); diff --git a/test/context_test.dart b/test/context_test.dart index f94c2cf..29cf23d 100644 --- a/test/context_test.dart +++ b/test/context_test.dart @@ -10,7 +10,7 @@ void main() { .resolve("application/") .resolve("lib/") .toFilePath(); - BuildContext ctx; + late BuildContext ctx; setUpAll(() async { final cmd = Platform.isWindows ? "pub.bat" : "pub"; diff --git a/test/project_analyzer_test.dart b/test/project_analyzer_test.dart index 2af6512..0203d14 100644 --- a/test/project_analyzer_test.dart +++ b/test/project_analyzer_test.dart @@ -18,7 +18,7 @@ void main() { final klass = p.getClassFromFile("ConsumerSubclass", terminal.libraryDirectory.absolute.uri.resolve("application.dart")); expect(klass, isNotNull); - expect(klass.name.name, "ConsumerSubclass"); - expect(klass.extendsClause.superclass.name.name, "Consumer"); + expect(klass!.name.name, "ConsumerSubclass"); + expect(klass.extendsClause!.superclass.name.name, "Consumer"); }); } diff --git a/test/test_packages/application/pubspec.yaml b/test/test_packages/application/pubspec.yaml index 11a9bca..8bfc9ee 100644 --- a/test/test_packages/application/pubspec.yaml +++ b/test/test_packages/application/pubspec.yaml @@ -3,7 +3,7 @@ description: A starting point for Dart libraries or applications. version: 1.0.0 environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' dependencies: meta: ^1.0.0 diff --git a/test/test_packages/dependency/pubspec.yaml b/test/test_packages/dependency/pubspec.yaml index 0085740..e043623 100644 --- a/test/test_packages/dependency/pubspec.yaml +++ b/test/test_packages/dependency/pubspec.yaml @@ -3,7 +3,7 @@ description: A starting point for Dart libraries or applications. version: 1.0.0 environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' dependencies: runtime: From 00027672b2558647765da1530b68dd0895a5bfb6 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Mon, 8 Mar 2021 01:45:55 -0800 Subject: [PATCH 02/25] when in doubt, ? --- lib/src/build.dart | 2 +- lib/src/context.dart | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/build.dart b/lib/src/build.dart index 21621e4..569c3e9 100644 --- a/lib/src/build.dart +++ b/lib/src/build.dart @@ -26,7 +26,7 @@ class Build { print("Generating runtime..."); final runtimeGenerator = RuntimeGenerator(); - context.context.runtimes.map.forEach((typeName, runtime) { + context.context.runtimes?.map.forEach((typeName, runtime) { if (runtime is SourceCompiler) { runtimeGenerator.addRuntime( name: typeName, source: runtime.compile(context)); diff --git a/lib/src/context.dart b/lib/src/context.dart index 8237cba..9a338e3 100644 --- a/lib/src/context.dart +++ b/lib/src/context.dart @@ -17,7 +17,7 @@ abstract class RuntimeContext { static RuntimeContext? _current; /// The runtimes available to the executing application. - late RuntimeCollection runtimes; + RuntimeCollection? runtimes; /// Gets a runtime object for [type]. /// @@ -30,7 +30,7 @@ abstract class RuntimeContext { /// In other words, if the type `Base` has a runtime and the type `Subclass` extends `Base`, /// `Subclass` must also have a runtime. The runtime objects for both `Subclass` and `Base` /// must be the same type. - dynamic operator [](Type type) => runtimes[type]; + dynamic operator [](Type type) => runtimes?[type]; T coerce(dynamic input); } From 532208b0ecb1a3b36c7e557394f6098bd44fdc1e Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Mon, 8 Mar 2021 16:15:56 -0800 Subject: [PATCH 03/25] on stateerror --- lib/src/mirror_context.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/mirror_context.dart b/lib/src/mirror_context.dart index e1f3807..0fa6ada 100644 --- a/lib/src/mirror_context.dart +++ b/lib/src/mirror_context.dart @@ -70,8 +70,8 @@ T? firstMetadataOfType(DeclarationMirror dm, {TypeMirror? dynamicType}) { try { return dm.metadata .firstWhere((im) => im.type.isSubtypeOf(tMirror)) - .reflectee as T; - } finally { + .reflectee; + } on StateError { return null; } } From c740a75f3d3da4e36c7d97716410de3ea1e61634 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Sun, 14 Mar 2021 11:32:06 -0700 Subject: [PATCH 04/25] uptick generated runtime code --- lib/src/build_context.dart | 2 +- lib/src/generator.dart | 2 +- pubspec.yaml | 8 ++++---- test/test_packages/application/pubspec.yaml | 6 +++--- test/test_packages/dependency/pubspec.yaml | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/src/build_context.dart b/lib/src/build_context.dart index c01d166..b141f03 100644 --- a/lib/src/build_context.dart +++ b/lib/src/build_context.dart @@ -160,7 +160,7 @@ class BuildContext { final imports = importRegex.allMatches(text).map((m) { var importedUri = Uri.parse(m.group(1)!); - if (importedUri.scheme == "package") { + if (importedUri.scheme == "package" || importedUri.scheme == "dart") { return text.substring(m.start, m.end); } else if (!importedUri.isAbsolute) { final path = fileUri!.resolve(importedUri.path); diff --git a/lib/src/generator.dart b/lib/src/generator.dart index 9b69225..edbf816 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -45,7 +45,7 @@ description: A runtime generated by package:runtime version: 1.0.0 environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' """; String get _loaderShell => """ diff --git a/pubspec.yaml b/pubspec.yaml index 8d7c7aa..794bcc6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: '>=2.12.0-0 <3.0.0' dependencies: - analyzer: ^1.0.0 + analyzer: ^1.1.0 args: ^2.0.0 pubspec2: git: @@ -16,10 +16,10 @@ dependencies: ref: nullsafety isolate_executor: git: https://github.com/j4qfrost/dart-isolate-executor - yaml: ^3.0.0 + yaml: ^3.1.0 dev_dependencies: - pedantic: ^1.0.0 - test: ^1.0.0 + pedantic: ^1.11.0 + test: ^1.16.5 command_line_agent: git: https://github.com/j4qfrost/dart-test-terminal.git \ No newline at end of file diff --git a/test/test_packages/application/pubspec.yaml b/test/test_packages/application/pubspec.yaml index 8bfc9ee..7cf361c 100644 --- a/test/test_packages/application/pubspec.yaml +++ b/test/test_packages/application/pubspec.yaml @@ -6,10 +6,10 @@ environment: sdk: '>=2.12.0-0 <3.0.0' dependencies: - meta: ^1.0.0 + meta: ^1.3.0 dependency: path: ../dependency/ dev_dependencies: - pedantic: ^1.0.0 - test: ^1.0.0 + pedantic: ^1.11.0 + test: ^1.16.5 diff --git a/test/test_packages/dependency/pubspec.yaml b/test/test_packages/dependency/pubspec.yaml index e043623..cff8604 100644 --- a/test/test_packages/dependency/pubspec.yaml +++ b/test/test_packages/dependency/pubspec.yaml @@ -10,5 +10,5 @@ dependencies: path: ../../.. dev_dependencies: - pedantic: ^1.0.0 - test: ^1.0.0 + pedantic: ^1.11.0 + test: ^1.16.5 From 8d79ef492ba96b66f03f32cf616d4e0adb17c05a Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Sun, 14 Mar 2021 11:37:49 -0700 Subject: [PATCH 05/25] missed one --- lib/src/build.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/build.dart b/lib/src/build.dart index 569c3e9..c7f7118 100644 --- a/lib/src/build.dart +++ b/lib/src/build.dart @@ -40,7 +40,7 @@ class Build { final pubspecMap = { 'name': 'runtime_target', 'version': '1.0.0', - 'environment': {'sdk': '>=2.7.0 <3.0.0'}, + 'environment': {'sdk': '>=2.12.0-0 <3.0.0'}, 'dependency_overrides': {} }; Map? overrides = pubspecMap['dependency_overrides'] as Map?; From e21996fbea06e64a38e555cc99b09c3b7f527f00 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Sun, 14 Mar 2021 22:37:29 -0700 Subject: [PATCH 06/25] use relative path --- lib/runtime.dart | 18 ++++++++++-------- lib/slow_coerce.dart | 2 +- lib/src/build.dart | 8 ++++++-- lib/src/build_context.dart | 8 ++++---- lib/src/build_manager.dart | 3 ++- lib/src/compiler.dart | 10 ++++------ lib/src/context.dart | 2 +- lib/src/mirror_coerce.dart | 2 +- lib/src/mirror_context.dart | 6 +++--- 9 files changed, 32 insertions(+), 27 deletions(-) diff --git a/lib/runtime.dart b/lib/runtime.dart index 5035666..b4dd175 100644 --- a/lib/runtime.dart +++ b/lib/runtime.dart @@ -2,8 +2,8 @@ library runtime; import 'dart:io'; -import 'package:runtime/src/compiler.dart'; -import 'package:runtime/src/mirror_context.dart'; +import 'src/compiler.dart'; +import 'src/mirror_context.dart'; export 'src/analyzer.dart'; export 'src/context.dart'; @@ -29,21 +29,23 @@ class RuntimePackageCompiler extends Compiler { void deflectPackage(Directory destinationDirectory) { final libraryFile = File.fromUri( destinationDirectory.uri.resolve("lib/").resolve("runtime.dart")); - libraryFile - .writeAsStringSync("library runtime;\nexport 'src/context.dart';\nexport 'src/exceptions.dart';"); + libraryFile.writeAsStringSync( + "library runtime;\nexport 'src/context.dart';\nexport 'src/exceptions.dart';"); final contextFile = File.fromUri(destinationDirectory.uri .resolve("lib/") .resolve("src/") .resolve("context.dart")); final contextFileContents = contextFile.readAsStringSync().replaceFirst( - "import 'package:runtime/src/mirror_context.dart' as context;", + "import 'mirror_context.dart' as context;", "import 'package:generated_runtime/generated_runtime.dart' as context;"); contextFile.writeAsStringSync(contextFileContents); - final pubspecFile = File.fromUri(destinationDirectory.uri.resolve("pubspec.yaml")); - final pubspecContents = pubspecFile.readAsStringSync().replaceFirst("\ndependencies:", - "\ndependencies:\n generated_runtime:\n path: ../../generated_runtime/"); + final pubspecFile = + File.fromUri(destinationDirectory.uri.resolve("pubspec.yaml")); + final pubspecContents = pubspecFile.readAsStringSync().replaceFirst( + "\ndependencies:", + "\ndependencies:\n generated_runtime:\n path: ../../generated_runtime/"); pubspecFile.writeAsStringSync(pubspecContents); } } diff --git a/lib/slow_coerce.dart b/lib/slow_coerce.dart index b664ed9..36483e8 100644 --- a/lib/slow_coerce.dart +++ b/lib/slow_coerce.dart @@ -1,4 +1,4 @@ -import 'package:runtime/src/exceptions.dart'; +import 'src/exceptions.dart'; const String _listPrefix = "List<"; const String _mapPrefix = "Map { diff --git a/lib/src/compiler.dart b/lib/src/compiler.dart index 1dbf802..23ba7f7 100644 --- a/lib/src/compiler.dart +++ b/lib/src/compiler.dart @@ -1,7 +1,7 @@ import 'dart:io'; -import 'package:runtime/runtime.dart'; -import 'package:runtime/src/mirror_context.dart'; +import 'build_context.dart'; +import 'mirror_context.dart'; abstract class Compiler { /// Modifies a package on the filesystem in order to remove dart:mirrors from the package. @@ -18,9 +18,7 @@ abstract class Compiler { /// Returns a map of runtime objects that can be used at runtime while running in mirrored mode. Map compile(MirrorContext context); - void didFinishPackageGeneration(BuildContext context) { - - } + void didFinishPackageGeneration(BuildContext context) {} List getUrisToResolve(BuildContext context) => []; } @@ -29,4 +27,4 @@ abstract class Compiler { abstract class SourceCompiler { /// The source code, including directives, that declare a class that is equivalent in behavior to this runtime. String compile(BuildContext ctx); -} \ No newline at end of file +} diff --git a/lib/src/context.dart b/lib/src/context.dart index 9a338e3..3f2ce30 100644 --- a/lib/src/context.dart +++ b/lib/src/context.dart @@ -1,4 +1,4 @@ -import 'package:runtime/src/mirror_context.dart' as context; +import 'mirror_context.dart' as context; /// Contextual values used during runtime. abstract class RuntimeContext { diff --git a/lib/src/mirror_coerce.dart b/lib/src/mirror_coerce.dart index 9f86302..e700ad9 100644 --- a/lib/src/mirror_coerce.dart +++ b/lib/src/mirror_coerce.dart @@ -1,6 +1,6 @@ import 'dart:mirrors'; -import 'package:runtime/src/exceptions.dart'; +import 'exceptions.dart'; dynamic runtimeCast(dynamic object, TypeMirror intoType) { final exceptionToThrow = diff --git a/lib/src/mirror_context.dart b/lib/src/mirror_context.dart index 0fa6ada..e21579f 100644 --- a/lib/src/mirror_context.dart +++ b/lib/src/mirror_context.dart @@ -1,8 +1,8 @@ import 'dart:mirrors'; -import 'package:runtime/src/context.dart'; -import 'package:runtime/src/compiler.dart'; -import 'package:runtime/src/mirror_coerce.dart'; +import 'context.dart'; +import 'compiler.dart'; +import 'mirror_coerce.dart'; RuntimeContext instance = MirrorContext._(); From 40992e4b17ac6e5cedc6d8f9dc985bde48eebbad Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Sun, 14 Mar 2021 22:38:08 -0700 Subject: [PATCH 07/25] whoops --- lib/src/build.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/src/build.dart b/lib/src/build.dart index 9a88a74..57305cc 100644 --- a/lib/src/build.dart +++ b/lib/src/build.dart @@ -88,8 +88,6 @@ class Build { } } - print(pubspecMap); - File.fromUri(context.buildDirectoryUri.resolve("pubspec.yaml")) .writeAsStringSync(json.encode(pubspecMap)); From 971970076aa0e6c2f27cc35beeec5bf0d4fd1606 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Mon, 15 Mar 2021 00:11:12 -0700 Subject: [PATCH 08/25] revert package naming --- lib/runtime.dart | 26 +++++++++++++------------- lib/slow_coerce.dart | 2 +- lib/src/build.dart | 8 ++++---- lib/src/build_context.dart | 8 ++++---- lib/src/build_manager.dart | 6 +++--- lib/src/compiler.dart | 4 ++-- lib/src/context.dart | 2 +- lib/src/generator.dart | 2 +- lib/src/mirror_context.dart | 6 +++--- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/runtime.dart b/lib/runtime.dart index b4dd175..742d42a 100644 --- a/lib/runtime.dart +++ b/lib/runtime.dart @@ -3,19 +3,19 @@ library runtime; import 'dart:io'; import 'src/compiler.dart'; -import 'src/mirror_context.dart'; +import 'package:runtime/src/mirror_context.dart'; -export 'src/analyzer.dart'; -export 'src/context.dart'; -export 'src/build.dart'; -export 'src/compiler.dart'; -export 'src/file_system.dart'; -export 'src/generator.dart'; -export 'src/build_context.dart'; -export 'src/build_manager.dart'; -export 'src/mirror_context.dart'; -export 'src/exceptions.dart'; -export 'src/mirror_coerce.dart'; +export 'package:runtime/src/analyzer.dart'; +export 'package:runtime/src/context.dart'; +export 'package:runtime/src/build.dart'; +export 'package:runtime/src/compiler.dart'; +export 'package:runtime/src/file_system.dart'; +export 'package:runtime/src/generator.dart'; +export 'package:runtime/src/build_context.dart'; +export 'package:runtime/src/build_manager.dart'; +export 'package:runtime/src/mirror_context.dart'; +export 'package:runtime/src/exceptions.dart'; +export 'package:runtime/src/mirror_coerce.dart'; /// Compiler for the runtime package itself. /// @@ -37,7 +37,7 @@ class RuntimePackageCompiler extends Compiler { .resolve("src/") .resolve("context.dart")); final contextFileContents = contextFile.readAsStringSync().replaceFirst( - "import 'mirror_context.dart' as context;", + "import 'package:runtime/src/mirror_context.dart' as context;", "import 'package:generated_runtime/generated_runtime.dart' as context;"); contextFile.writeAsStringSync(contextFileContents); diff --git a/lib/slow_coerce.dart b/lib/slow_coerce.dart index 36483e8..b664ed9 100644 --- a/lib/slow_coerce.dart +++ b/lib/slow_coerce.dart @@ -1,4 +1,4 @@ -import 'src/exceptions.dart'; +import 'package:runtime/src/exceptions.dart'; const String _listPrefix = "List<"; const String _mapPrefix = "Map { BuildExecutable(Map message) : super(message) { diff --git a/lib/src/compiler.dart b/lib/src/compiler.dart index 23ba7f7..ce48c1c 100644 --- a/lib/src/compiler.dart +++ b/lib/src/compiler.dart @@ -1,7 +1,7 @@ import 'dart:io'; -import 'build_context.dart'; -import 'mirror_context.dart'; +import 'package:runtime/src/build_context.dart'; +import 'package:runtime/src/mirror_context.dart'; abstract class Compiler { /// Modifies a package on the filesystem in order to remove dart:mirrors from the package. diff --git a/lib/src/context.dart b/lib/src/context.dart index 3f2ce30..9a338e3 100644 --- a/lib/src/context.dart +++ b/lib/src/context.dart @@ -1,4 +1,4 @@ -import 'mirror_context.dart' as context; +import 'package:runtime/src/mirror_context.dart' as context; /// Contextual values used during runtime. abstract class RuntimeContext { diff --git a/lib/src/generator.dart b/lib/src/generator.dart index edbf816..3bd3de6 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -7,7 +7,7 @@ const String _assignmentToken = "___ASSIGNMENTS___"; class RuntimeGenerator { List<_RuntimeElement> _elements = []; - void addRuntime({required String name, String source = ''}) { + void addRuntime({required String name, required String source}) { _elements.add(_RuntimeElement(name, source)); } diff --git a/lib/src/mirror_context.dart b/lib/src/mirror_context.dart index e21579f..0fa6ada 100644 --- a/lib/src/mirror_context.dart +++ b/lib/src/mirror_context.dart @@ -1,8 +1,8 @@ import 'dart:mirrors'; -import 'context.dart'; -import 'compiler.dart'; -import 'mirror_coerce.dart'; +import 'package:runtime/src/context.dart'; +import 'package:runtime/src/compiler.dart'; +import 'package:runtime/src/mirror_coerce.dart'; RuntimeContext instance = MirrorContext._(); From 1df9f65ee1c31a44a6d86b9e5f0cb4115cdc9823 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Mon, 15 Mar 2021 00:16:35 -0700 Subject: [PATCH 09/25] missed one --- lib/runtime.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime.dart b/lib/runtime.dart index 742d42a..ea526d0 100644 --- a/lib/runtime.dart +++ b/lib/runtime.dart @@ -2,7 +2,7 @@ library runtime; import 'dart:io'; -import 'src/compiler.dart'; +import 'package:runtime/src/compiler.dart'; import 'package:runtime/src/mirror_context.dart'; export 'package:runtime/src/analyzer.dart'; From e74680c19056b75059b9b344e19536e4b395768c Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Mon, 15 Mar 2021 00:16:58 -0700 Subject: [PATCH 10/25] missed another --- lib/src/mirror_coerce.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/mirror_coerce.dart b/lib/src/mirror_coerce.dart index e700ad9..9f86302 100644 --- a/lib/src/mirror_coerce.dart +++ b/lib/src/mirror_coerce.dart @@ -1,6 +1,6 @@ import 'dart:mirrors'; -import 'exceptions.dart'; +import 'package:runtime/src/exceptions.dart'; dynamic runtimeCast(dynamic object, TypeMirror intoType) { final exceptionToThrow = From 504a44499318db9c8ab0cf5aa275857af3271aaa Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Mon, 15 Mar 2021 02:30:25 -0700 Subject: [PATCH 11/25] git gud --- lib/runtime.dart | 24 ++++++++++++------------ lib/slow_coerce.dart | 1 - lib/src/build_context.dart | 10 ++++------ lib/src/build_manager.dart | 5 ++--- lib/src/compiler.dart | 2 +- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/lib/runtime.dart b/lib/runtime.dart index ea526d0..b407c10 100644 --- a/lib/runtime.dart +++ b/lib/runtime.dart @@ -2,20 +2,20 @@ library runtime; import 'dart:io'; -import 'package:runtime/src/compiler.dart'; +import 'src/compiler.dart'; import 'package:runtime/src/mirror_context.dart'; -export 'package:runtime/src/analyzer.dart'; -export 'package:runtime/src/context.dart'; -export 'package:runtime/src/build.dart'; -export 'package:runtime/src/compiler.dart'; -export 'package:runtime/src/file_system.dart'; -export 'package:runtime/src/generator.dart'; -export 'package:runtime/src/build_context.dart'; -export 'package:runtime/src/build_manager.dart'; -export 'package:runtime/src/mirror_context.dart'; -export 'package:runtime/src/exceptions.dart'; -export 'package:runtime/src/mirror_coerce.dart'; +export 'src/analyzer.dart'; +export 'src/context.dart'; +export 'src/build.dart'; +export 'src/compiler.dart'; +export 'src/file_system.dart'; +export 'src/generator.dart'; +export 'src/build_context.dart'; +export 'src/build_manager.dart'; +export 'src/mirror_context.dart'; +export 'src/exceptions.dart'; +export 'src/mirror_coerce.dart'; /// Compiler for the runtime package itself. /// diff --git a/lib/slow_coerce.dart b/lib/slow_coerce.dart index b664ed9..e1c250b 100644 --- a/lib/slow_coerce.dart +++ b/lib/slow_coerce.dart @@ -39,7 +39,6 @@ T? cast(dynamic input) { } else if (typeString == "List") { return List.from(input) as T; } else if (typeString == "List>") { - print(typeString); final objects = >[]; input.forEach((o) { objects.add(o); diff --git a/lib/src/build_context.dart b/lib/src/build_context.dart index b141f03..586cf9e 100644 --- a/lib/src/build_context.dart +++ b/lib/src/build_context.dart @@ -160,15 +160,13 @@ class BuildContext { final imports = importRegex.allMatches(text).map((m) { var importedUri = Uri.parse(m.group(1)!); - if (importedUri.scheme == "package" || importedUri.scheme == "dart") { - return text.substring(m.start, m.end); - } else if (!importedUri.isAbsolute) { + + if (!importedUri.isAbsolute) { final path = fileUri!.resolve(importedUri.path); return 'import \'file:${absolute(path.path)}\';'; } - throw ArgumentError( - "Cannot resolve relative URIs in file located at $uri. " - "Replace imported URIs with package or absolute URIs"); + + return text.substring(m.start, m.end); }).toList(); if (alsoImportOriginalFile) { diff --git a/lib/src/build_manager.dart b/lib/src/build_manager.dart index 942c9f7..29a6154 100644 --- a/lib/src/build_manager.dart +++ b/lib/src/build_manager.dart @@ -2,10 +2,9 @@ import 'dart:io'; import 'package:analyzer/dart/ast/ast.dart'; import 'package:isolate_executor/isolate_executor.dart'; +import 'package:runtime/runtime.dart'; -import 'package:runtime/src/analyzer.dart'; -import 'package:runtime/src/build.dart'; -import 'package:runtime/src/build_context.dart'; +import 'build_context.dart'; class BuildExecutable extends Executable { BuildExecutable(Map message) : super(message) { diff --git a/lib/src/compiler.dart b/lib/src/compiler.dart index ce48c1c..1525cd2 100644 --- a/lib/src/compiler.dart +++ b/lib/src/compiler.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:runtime/src/build_context.dart'; +import 'package:runtime/runtime.dart'; import 'package:runtime/src/mirror_context.dart'; abstract class Compiler { From 2665afb3833c3e2c5fca2ce41e3186b46509ab29 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Mon, 15 Mar 2021 03:12:36 -0700 Subject: [PATCH 12/25] pubspec dependency --- pubspec.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 794bcc6..5072abe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,12 +10,9 @@ environment: dependencies: analyzer: ^1.1.0 args: ^2.0.0 - pubspec2: - git: - url: https://github.com/bsutton/pubspec.git - ref: nullsafety + pubspec: ^2.0.1 isolate_executor: - git: https://github.com/j4qfrost/dart-isolate-executor + git: https://github.com/j4qfrost/dart-isolate-executor.git yaml: ^3.1.0 dev_dependencies: From 0ac0d860d26b59b265b4b9d86c97e8b8668e2775 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Mon, 15 Mar 2021 03:23:50 -0700 Subject: [PATCH 13/25] remove .git --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 5072abe..4db3a23 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,11 +12,11 @@ dependencies: args: ^2.0.0 pubspec: ^2.0.1 isolate_executor: - git: https://github.com/j4qfrost/dart-isolate-executor.git + git: https://github.com/j4qfrost/dart-isolate-executor yaml: ^3.1.0 dev_dependencies: pedantic: ^1.11.0 test: ^1.16.5 command_line_agent: - git: https://github.com/j4qfrost/dart-test-terminal.git \ No newline at end of file + git: https://github.com/j4qfrost/dart-test-terminal \ No newline at end of file From ba6248fe9d5bed95ecf3ed5edfc364ec5a955da4 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Mon, 15 Mar 2021 03:28:16 -0700 Subject: [PATCH 14/25] missed this --- lib/src/build_context.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/build_context.dart b/lib/src/build_context.dart index 586cf9e..932b19c 100644 --- a/lib/src/build_context.dart +++ b/lib/src/build_context.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'dart:mirrors'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:pubspec2/pubspec2.dart'; +import 'package:pubspec/pubspec.dart'; import 'package:runtime/src/analyzer.dart'; import 'package:runtime/src/context.dart'; import 'package:runtime/src/file_system.dart'; From aa8c615c0bfa147967e6ac4ae0ce08701cda97e5 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Mon, 15 Mar 2021 20:44:08 -0700 Subject: [PATCH 15/25] update analyzer --- lib/src/analyzer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/analyzer.dart b/lib/src/analyzer.dart index bb00296..89c995f 100644 --- a/lib/src/analyzer.dart +++ b/lib/src/analyzer.dart @@ -34,7 +34,7 @@ class CodeAnalyzer { } final output = await ctx.currentSession.getResolvedUnit(path); - if (output!.state == ResultState.VALID) { + if (output.state == ResultState.VALID) { _resolvedAsts[path] = output; return output; } From 068fa6445e5dd8951e9cac35ea6a8140d9cceaa2 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Tue, 16 Mar 2021 02:41:33 -0700 Subject: [PATCH 16/25] whoops --- lib/slow_coerce.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/slow_coerce.dart b/lib/slow_coerce.dart index e1c250b..6de542d 100644 --- a/lib/slow_coerce.dart +++ b/lib/slow_coerce.dart @@ -71,15 +71,15 @@ T? cast(dynamic input) { return Map.from(inputMap) as T; } else if (typeString == "Map") { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString == "Map") { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString == "Map") { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString == "Map") { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString == "Map") { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString == "Map") { return Map.from(inputMap) as T; } } From bc6975cf3766f4290bcad2d8519eb01d8afddceb Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Tue, 16 Mar 2021 02:53:20 -0700 Subject: [PATCH 17/25] cover nullable types --- lib/slow_coerce.dart | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/slow_coerce.dart b/lib/slow_coerce.dart index 6de542d..20b3631 100644 --- a/lib/slow_coerce.dart +++ b/lib/slow_coerce.dart @@ -18,27 +18,27 @@ T? cast(dynamic input) { throw TypeError(); } - if (typeString == "List") { + if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List>") { + } else if (typeString.startsWith("List>")) { final objects = >[]; input.forEach((o) { objects.add(o); @@ -61,25 +61,25 @@ T? cast(dynamic input) { } final inputMap = input as Map; - if (typeString == "Map") { + if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; } } From 6fd292311ad54da5a3a6c9f5b31a349034a473f7 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Tue, 16 Mar 2021 19:48:09 -0700 Subject: [PATCH 18/25] this took me an embarrassingly long time to catch --- lib/src/generator.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/generator.dart b/lib/src/generator.dart index 3bd3de6..0435db6 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -66,7 +66,7 @@ class GeneratedContext extends RuntimeContext { @override T coerce(dynamic input) { - return runtime_cast.cast(input); + return runtime_cast.cast(input); } } """; From 24b137a067b44185d7701e559b61f6f9af0cd7ff Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Tue, 16 Mar 2021 19:51:41 -0700 Subject: [PATCH 19/25] whoops --- lib/src/generator.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/generator.dart b/lib/src/generator.dart index 0435db6..8f703bc 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -65,7 +65,7 @@ class GeneratedContext extends RuntimeContext { } @override - T coerce(dynamic input) { + T? coerce(dynamic input) { return runtime_cast.cast(input); } } From e5a88b56589f93d23973c7b7e827eb2c400986af Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Tue, 16 Mar 2021 19:55:33 -0700 Subject: [PATCH 20/25] this should work --- lib/slow_coerce.dart | 4 ++-- lib/src/generator.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/slow_coerce.dart b/lib/slow_coerce.dart index 20b3631..fc580dc 100644 --- a/lib/slow_coerce.dart +++ b/lib/slow_coerce.dart @@ -3,12 +3,12 @@ import 'package:runtime/src/exceptions.dart'; const String _listPrefix = "List<"; const String _mapPrefix = "Map(dynamic input) { +T cast(dynamic input) { try { var typeString = T.toString(); if (typeString.endsWith('?')) { if (input == null) { - return null; + return null as T; } else { typeString = typeString.substring(0, typeString.length - 1); } diff --git a/lib/src/generator.dart b/lib/src/generator.dart index 8f703bc..0435db6 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -65,7 +65,7 @@ class GeneratedContext extends RuntimeContext { } @override - T? coerce(dynamic input) { + T coerce(dynamic input) { return runtime_cast.cast(input); } } From fbb74456321915c7c392c40cd731c434f834fa2e Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Tue, 16 Mar 2021 21:48:33 -0700 Subject: [PATCH 21/25] let List handle itself --- lib/slow_coerce.dart | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/slow_coerce.dart b/lib/slow_coerce.dart index fc580dc..ae8ee19 100644 --- a/lib/slow_coerce.dart +++ b/lib/slow_coerce.dart @@ -45,15 +45,8 @@ T cast(dynamic input) { }); return objects as T; } else { - final objects = ?>[]; - input.forEach((o) { - if (o == null) { - objects.add(null); - } else { - objects.add(o); - } - }); - return objects as T; + // cross your fingers + return input as T; } } else if (typeString.startsWith(_mapPrefix)) { if (input is! Map) { From cd4814fe891b6ba2649ba82559a62a834592c1c6 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Tue, 16 Mar 2021 21:49:20 -0700 Subject: [PATCH 22/25] this is better --- lib/slow_coerce.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/slow_coerce.dart b/lib/slow_coerce.dart index ae8ee19..fdda0c3 100644 --- a/lib/slow_coerce.dart +++ b/lib/slow_coerce.dart @@ -44,9 +44,6 @@ T cast(dynamic input) { objects.add(o); }); return objects as T; - } else { - // cross your fingers - return input as T; } } else if (typeString.startsWith(_mapPrefix)) { if (input is! Map) { From f151dd872d63a8514023b27c18aec3d43344867f Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Sun, 21 Mar 2021 16:54:52 -0700 Subject: [PATCH 23/25] upgrade analyzer and fix up tests --- lib/slow_coerce.dart | 6 ++++++ pubspec.yaml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/slow_coerce.dart b/lib/slow_coerce.dart index fdda0c3..797e0de 100644 --- a/lib/slow_coerce.dart +++ b/lib/slow_coerce.dart @@ -44,6 +44,12 @@ T cast(dynamic input) { objects.add(o); }); return objects as T; + } else if (typeString.startsWith("List?>")) { + final objects = ?>[]; + input.forEach((o) { + objects.add(o); + }); + return objects as T; } } else if (typeString.startsWith(_mapPrefix)) { if (input is! Map) { diff --git a/pubspec.yaml b/pubspec.yaml index 4db3a23..3dce2c0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: '>=2.12.0-0 <3.0.0' dependencies: - analyzer: ^1.1.0 + analyzer: ^1.2.0 args: ^2.0.0 pubspec: ^2.0.1 isolate_executor: From 51e7bc93094f20ea4f452d2e37c1aa00b198a2d4 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Sun, 21 Mar 2021 19:35:27 -0700 Subject: [PATCH 24/25] switch dep to conduit --- lib/src/build_manager.dart | 2 +- pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/build_manager.dart b/lib/src/build_manager.dart index 29a6154..fea8a8f 100644 --- a/lib/src/build_manager.dart +++ b/lib/src/build_manager.dart @@ -1,7 +1,7 @@ import 'dart:io'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:isolate_executor/isolate_executor.dart'; +import 'package:conduit_isolate_executor/isolate_executor.dart'; import 'package:runtime/runtime.dart'; import 'build_context.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 3dce2c0..b8e7f7f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: analyzer: ^1.2.0 args: ^2.0.0 pubspec: ^2.0.1 - isolate_executor: + conduit_isolate_executor: git: https://github.com/j4qfrost/dart-isolate-executor yaml: ^3.1.0 From 12d388fa328d74390cbfea6c4390384b5a807616 Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Tue, 30 Mar 2021 20:34:03 -0700 Subject: [PATCH 25/25] change isolate package --- lib/src/build_manager.dart | 2 +- pubspec.yaml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/src/build_manager.dart b/lib/src/build_manager.dart index fea8a8f..a75b1e9 100644 --- a/lib/src/build_manager.dart +++ b/lib/src/build_manager.dart @@ -1,7 +1,7 @@ import 'dart:io'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:conduit_isolate_executor/isolate_executor.dart'; +import 'package:conduit_isolate_exec/conduit_isolate_exec.dart'; import 'package:runtime/runtime.dart'; import 'build_context.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index b8e7f7f..735ac69 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,8 +11,7 @@ dependencies: analyzer: ^1.2.0 args: ^2.0.0 pubspec: ^2.0.1 - conduit_isolate_executor: - git: https://github.com/j4qfrost/dart-isolate-executor + conduit_isolate_exec: ^1.0.0-b1 yaml: ^3.1.0 dev_dependencies: