diff --git a/engine/src/flutter/tools/const_finder/lib/const_finder.dart b/engine/src/flutter/tools/const_finder/lib/const_finder.dart index b9a06ca4a2..905324d055 100644 --- a/engine/src/flutter/tools/const_finder/lib/const_finder.dart +++ b/engine/src/flutter/tools/const_finder/lib/const_finder.dart @@ -4,18 +4,14 @@ import 'dart:collection'; -import 'package:kernel/kernel.dart' hide MapEntry; -import 'package:meta/meta.dart'; +import 'package:kernel/kernel.dart'; class _ConstVisitor extends RecursiveVisitor { _ConstVisitor( this.kernelFilePath, this.classLibraryUri, this.className, - ) : assert(kernelFilePath != null), - assert(classLibraryUri != null), - assert(className != null), - _visitedInstances = {}, + ) : _visitedInstances = {}, constantInstances = >[], nonConstantLocations = >[]; @@ -35,16 +31,16 @@ class _ConstVisitor extends RecursiveVisitor { // A cache of previously evaluated classes. static Map _classHeirarchyCache = {}; bool _matches(Class node) { - assert(node != null); - final bool result = _classHeirarchyCache[node]; + final bool? result = _classHeirarchyCache[node]; if (result != null) { return result; } final bool exactMatch = node.name == className && node.enclosingLibrary.importUri.toString() == classLibraryUri; - _classHeirarchyCache[node] = exactMatch + final bool match = exactMatch || node.supers.any((Supertype supertype) => _matches(supertype.classNode)); - return _classHeirarchyCache[node]; + _classHeirarchyCache[node] = match; + return match; } // Avoid visiting the same constant more than once. @@ -64,12 +60,13 @@ class _ConstVisitor extends RecursiveVisitor { @override void visitConstructorInvocation(ConstructorInvocation node) { - final Class parentClass = node.target.parent as Class; + final Class parentClass = node.target.parent! as Class; if (_matches(parentClass)) { + final Location location = node.location!; nonConstantLocations.add({ - 'file': node.location.file.toString(), - 'line': node.location.line, - 'column': node.location.column, + 'file': location.file.toString(), + 'line': location.line, + 'column': location.column, }); } super.visitConstructorInvocation(node); @@ -82,7 +79,7 @@ class _ConstVisitor extends RecursiveVisitor { return; } final Map instance = {}; - for (MapEntry kvp in node.fieldValues.entries) { + for (final MapEntry kvp in node.fieldValues.entries) { if (kvp.value is! PrimitiveConstant) { continue; } @@ -102,9 +99,9 @@ class ConstFinder { /// /// The `kernelFilePath` is the path to a dill (kernel) file to process. ConstFinder({ - @required String kernelFilePath, - @required String classLibraryUri, - @required String className, + required String kernelFilePath, + required String classLibraryUri, + required String className, }) : _visitor = _ConstVisitor( kernelFilePath, classLibraryUri, @@ -116,7 +113,7 @@ class ConstFinder { /// Finds all instances Map findInstances() { _visitor._visitedInstances.clear(); - for (Library library in loadComponentFromBinary(_visitor.kernelFilePath).libraries) { + for (final Library library in loadComponentFromBinary(_visitor.kernelFilePath).libraries) { library.visitChildren(_visitor); } return { diff --git a/engine/src/flutter/tools/const_finder/pubspec.yaml b/engine/src/flutter/tools/const_finder/pubspec.yaml index cebd28c854..d2193a5bb1 100644 --- a/engine/src/flutter/tools/const_finder/pubspec.yaml +++ b/engine/src/flutter/tools/const_finder/pubspec.yaml @@ -6,7 +6,7 @@ name: const_finder publish_to: none environment: - sdk: ">=2.4.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" # Do not add any dependencies that require more than what is provided in # //third_party/dart/pkg or //third_party/dart/third_party/pkg. @@ -19,7 +19,6 @@ environment: dependencies: args: any collection: any - meta: any kernel: any dev_dependencies: @@ -32,7 +31,5 @@ dependency_overrides: path: ../../../third_party/dart/third_party/pkg/collection kernel: path: ../../../third_party/dart/pkg/kernel - meta: - path: ../../../third_party/dart/pkg/meta path: path: ../../../third_party/dart/third_party/pkg/path diff --git a/engine/src/flutter/tools/const_finder/test/const_finder_test.dart b/engine/src/flutter/tools/const_finder/test/const_finder_test.dart index 0a33e14069..e8ec6f12a3 100644 --- a/engine/src/flutter/tools/const_finder/test/const_finder_test.dart +++ b/engine/src/flutter/tools/const_finder/test/const_finder_test.dart @@ -155,7 +155,7 @@ void _checkNonConsts() { }, { 'file': 'file://$fixtures/pkg/package.dart', - 'line': 13, + 'line': 14, 'column': 25, } ] diff --git a/engine/src/flutter/tools/const_finder/test/fixtures/lib/consts.dart b/engine/src/flutter/tools/const_finder/test/fixtures/lib/consts.dart index f7f29e61ed..ba66e7a946 100644 --- a/engine/src/flutter/tools/const_finder/test/fixtures/lib/consts.dart +++ b/engine/src/flutter/tools/const_finder/test/fixtures/lib/consts.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// ignore_for_file: prefer_const_constructors, unused_local_variable import 'dart:core'; import 'package:const_finder_fixtures_package/package.dart'; diff --git a/engine/src/flutter/tools/const_finder/test/fixtures/lib/consts_and_non.dart b/engine/src/flutter/tools/const_finder/test/fixtures/lib/consts_and_non.dart index 3c5ebc7dac..6b85ac2687 100644 --- a/engine/src/flutter/tools/const_finder/test/fixtures/lib/consts_and_non.dart +++ b/engine/src/flutter/tools/const_finder/test/fixtures/lib/consts_and_non.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// ignore_for_file: prefer_const_constructors +// ignore_for_file: prefer_const_constructors, unused_local_variable import 'dart:core'; import 'package:const_finder_fixtures_package/package.dart'; diff --git a/engine/src/flutter/tools/const_finder/test/fixtures/pkg/package.dart b/engine/src/flutter/tools/const_finder/test/fixtures/pkg/package.dart index 7bd0ed473c..87a92bb572 100644 --- a/engine/src/flutter/tools/const_finder/test/fixtures/pkg/package.dart +++ b/engine/src/flutter/tools/const_finder/test/fixtures/pkg/package.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// ignore_for_file: prefer_const_constructors import 'package:const_finder_fixtures/target.dart'; void createTargetInPackage() {