Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3bfae48

Browse files
author
Dart CI
committed
Version 2.19.0-95.0.dev
Merge commit '7d87a37d57f2b69b4e8a9ce15678aa1fe5e048d6' into 'dev'
2 parents 29d9805 + 7d87a37 commit 3bfae48

File tree

11 files changed

+128
-59
lines changed

11 files changed

+128
-59
lines changed

pkg/analysis_server/lib/src/services/refactoring/framework/refactoring_processor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ typedef ProducerGenerator = RefactoringProducer Function(RefactoringContext);
1212
class RefactoringProcessor {
1313
/// A list of the generators used to produce refactorings.
1414
static const Map<String, ProducerGenerator> generators = {
15-
// 'move_to_file': MoveTopLevelToFile.new,
15+
// MoveTopLevelToFile.commandName: MoveTopLevelToFile.new,
1616
};
1717

1818
/// The context in which the refactorings could be applied.

pkg/analysis_server/lib/src/services/refactoring/framework/refactoring_producer.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ abstract class RefactoringProducer {
1717
/// the given [_context].
1818
RefactoringProducer(this._context);
1919

20-
/// Return the command name used to apply this refactoring.
21-
String get commandName;
22-
2320
/// Return the kind of refactoring this producer produces. Subclasses should
2421
/// override this method if they produce a subtype of the type
2522
/// [CodeActionKind.Refactor], such as [CodeActionKind.RefactorExtract],

pkg/analysis_server/lib/src/services/refactoring/move_top_level_to_file.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dar
88

99
/// An object that can compute a refactoring in a Dart file.
1010
class MoveTopLevelToFile extends RefactoringProducer {
11+
/// Return the name used for this command when communicating with the client.
12+
static const String commandName = 'move_top_level_to_file';
13+
1114
@override
1215
late String title;
1316

@@ -18,9 +21,6 @@ class MoveTopLevelToFile extends RefactoringProducer {
1821
/// [context].
1922
MoveTopLevelToFile(super.context);
2023

21-
@override
22-
String get commandName => 'move_top_level_to_file';
23-
2424
@override
2525
List<CommandParameter> get parameters => [
2626
CommandParameter(

pkg/analyzer/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.7.0-dev
2+
* Add `addImplicitCallReference` to `NodeLintRegistry`.
3+
14
## 4.6.0
25
* Added `DartType.element2`, so that `InterfaceType.element2` overrides it.
36

pkg/analyzer/lib/dart/ast/ast.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4102,9 +4102,6 @@ abstract class RecordTypeAnnotationField implements AstNode {
41024102
/// The annotations associated with the field.
41034103
NodeList<Annotation> get metadata;
41044104

4105-
/// The optional name of the field.
4106-
Token? get name;
4107-
41084105
/// The type of the field.
41094106
TypeAnnotation get type;
41104107
}
@@ -4116,7 +4113,6 @@ abstract class RecordTypeAnnotationField implements AstNode {
41164113
abstract class RecordTypeAnnotationNamedField
41174114
implements RecordTypeAnnotationField {
41184115
/// The name of the field.
4119-
@override
41204116
Token get name;
41214117
}
41224118

pkg/analyzer/lib/dart/element/type.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import 'package:analyzer/dart/element/element.dart';
2323
import 'package:analyzer/dart/element/nullability_suffix.dart';
2424
import 'package:analyzer/dart/element/type_visitor.dart';
25+
import 'package:meta/meta.dart';
2526

2627
/// The type associated with elements in the element model.
2728
///
@@ -424,6 +425,45 @@ abstract class ParameterizedType implements DartType {
424425
List<DartType> get typeArguments;
425426
}
426427

428+
/// The type of a record literal or a record type annotation.
429+
///
430+
/// Clients may not extend, implement or mix-in this class.
431+
@experimental
432+
abstract class RecordType implements DartType {
433+
/// The named fields (might be empty).
434+
List<RecordTypeNamedField> get namedFields;
435+
436+
/// The positional fields (might be empty).
437+
List<RecordTypePositionalField> get positionalFields;
438+
}
439+
440+
/// A field in a [RecordType].
441+
///
442+
/// Clients may not extend, implement or mix-in this class.
443+
@experimental
444+
abstract class RecordTypeField {
445+
/// Returns metadata associated with the field.
446+
List<ElementAnnotation> get metadata;
447+
448+
/// The type of the field.
449+
DartType get type;
450+
}
451+
452+
/// A named field in a [RecordType].
453+
///
454+
/// Clients may not extend, implement or mix-in this class.
455+
@experimental
456+
abstract class RecordTypeNamedField implements RecordTypeField {
457+
/// The name of the field.
458+
String get name;
459+
}
460+
461+
/// A positional field in a [RecordType].
462+
///
463+
/// Clients may not extend, implement or mix-in this class.
464+
@experimental
465+
abstract class RecordTypePositionalField implements RecordTypeField {}
466+
427467
/// The type introduced by a type parameter.
428468
///
429469
/// Clients may not extend, implement or mix-in this class.

pkg/analyzer/lib/src/lint/linter_visitor.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,12 @@ class LinterVisitor extends RecursiveAstVisitor<void> {
402402
super.visitImplementsClause(node);
403403
}
404404

405+
@override
406+
void visitImplicitCallReference(ImplicitCallReference node) {
407+
_runSubscriptions(node, registry._forImplicitCallReference);
408+
super.visitImplicitCallReference(node);
409+
}
410+
405411
@override
406412
void visitImportDirective(ImportDirective node) {
407413
_runSubscriptions(node, registry._forImportDirective);
@@ -861,6 +867,8 @@ class NodeLintRegistry {
861867
final List<_Subscription<IfElement>> _forIfElement = [];
862868
final List<_Subscription<IfStatement>> _forIfStatement = [];
863869
final List<_Subscription<ImplementsClause>> _forImplementsClause = [];
870+
final List<_Subscription<ImplicitCallReference>> _forImplicitCallReference =
871+
[];
864872
final List<_Subscription<ImportDirective>> _forImportDirective = [];
865873
final List<_Subscription<IndexExpression>> _forIndexExpression = [];
866874
final List<_Subscription<InstanceCreationExpression>>
@@ -1215,6 +1223,11 @@ class NodeLintRegistry {
12151223
_forImplementsClause.add(_Subscription(linter, visitor, _getTimer(linter)));
12161224
}
12171225

1226+
void addImplicitCallReference(LintRule linter, AstVisitor visitor) {
1227+
_forImplicitCallReference
1228+
.add(_Subscription(linter, visitor, _getTimer(linter)));
1229+
}
1230+
12181231
void addImportDirective(LintRule linter, AstVisitor visitor) {
12191232
_forImportDirective.add(_Subscription(linter, visitor, _getTimer(linter)));
12201233
}

pkg/analyzer/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: analyzer
2-
version: 4.6.0
2+
version: 4.7.0-dev
33
description: This package provides a library that performs static analysis of Dart code.
44
repository: https://github.com/dart-lang/sdk/tree/main/pkg/analyzer
55

pkg/dart2js_info/bin/src/to_devtools_format.dart

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ class DevtoolsFormatCommand extends Command<void> with PrintUsageException {
6060
output['n'] = '';
6161
output['type'] = "web";
6262

63+
/// Adds "isDeferred" flag to each child of a treeMap using a helper stack.
64+
void addDeferredFlag(Map<String, dynamic> treeMap, bool flag) {
65+
List<dynamic> stack = [];
66+
treeMap['isDeferred'] = flag;
67+
stack.add(treeMap);
68+
while (stack.isNotEmpty) {
69+
var item = stack.removeLast();
70+
item['isDeferred'] = flag;
71+
stack.addAll(item['children'] ?? []);
72+
}
73+
}
74+
6375
if (outputUnits.length == 1) {
6476
vm.ProgramInfo programInfoTree =
6577
builder.build(allInfo, outputUnits.keys.first);
@@ -77,34 +89,18 @@ class DevtoolsFormatCommand extends Command<void> with PrintUsageException {
7789
treeMap['n'] = treemapRoots[outputUnitName];
7890
if (treeMap['n'] == 'main') {
7991
mainOutput.addAll(treeMap);
80-
treeMap['isDeferred'] = false;
81-
// recursively visit children
82-
List<dynamic> mainStack = [];
83-
mainStack.add(treeMap);
84-
while (mainStack.isNotEmpty) {
85-
var item = mainStack.removeLast();
86-
item['isDeferred'] = false;
87-
mainStack.addAll(item['children'] ?? []);
88-
}
92+
// Recursively tag each child in treeMap with "isDeferred" flag
93+
addDeferredFlag(treeMap, false);
8994
} else {
9095
Map<String, dynamic> deferredOutput = {};
9196
deferredOutput.addAll(treeMap);
92-
treeMap['isDeferred'] = true;
93-
List<dynamic> deferredStack = [];
94-
deferredStack.add(treeMap);
95-
while (deferredStack.isNotEmpty) {
96-
var item = deferredStack.removeLast();
97-
item['isDeferred'] = true;
98-
deferredStack.addAll(item['children'] ?? []);
99-
}
97+
addDeferredFlag(treeMap, true);
10098
deferredOutputs.add(deferredOutput);
10199
}
102100
treeMap['value'] = treemapSizes[outputUnitName];
103101
}
104102
output['children'].add(mainOutput);
105-
for (var deferredUnit in deferredOutputs) {
106-
output['children'].add(deferredUnit);
107-
}
103+
output['children'].addAll(deferredOutputs);
108104
}
109105
if (outputPath == null) {
110106
print(jsonEncode(output));
@@ -119,7 +115,7 @@ class DevtoolsFormatCommand extends Command<void> with PrintUsageException {
119115
/// The [vm.ProgramInfoNode] tree has a similar structure to the [AllInfo] tree
120116
/// except that the root has packages, libraries, constants, and typedefs as
121117
/// immediate children.
122-
class ProgramInfoBuilder extends VMProgramInfoVisitor<vm.ProgramInfoNode> {
118+
class ProgramInfoBuilder extends VMProgramInfoVisitor<vm.ProgramInfoNode?> {
123119
final AllInfo info;
124120

125121
final program = vm.ProgramInfo();
@@ -141,9 +137,12 @@ class ProgramInfoBuilder extends VMProgramInfoVisitor<vm.ProgramInfoNode> {
141137
String compositeName(String name, String outputUnitName) =>
142138
"$name/$outputUnitName";
143139

140+
/// Mapping between the name of an OutputUnitInfo and the OutputUnitInfo object.
141+
Map<String, OutputUnitInfo> outputUnitInfos = {};
142+
144143
/// Mapping between the composite name of a package and the corresponding
145-
/// [vm.ProgramInfoNode] objects of [vm.NodeType.packageNode].
146-
final Map<String, dynamic> packageInfoNodes = {};
144+
/// [PackageInfo] objects.
145+
final Map<String, PackageInfo> packageInfos = {};
147146

148147
/// Mapping between an <unnamed> [LibraryInfo] object and the name of the
149148
/// corresponding [vm.ProgramInfoNode] object.
@@ -159,25 +158,42 @@ class ProgramInfoBuilder extends VMProgramInfoVisitor<vm.ProgramInfoNode> {
159158
libraryName = longName(libraryInfo, useLibraryUri: true, forId: true);
160159
}
161160
String packageName = libraryGroupName(libraryInfo) ?? libraryName;
162-
vm.ProgramInfoNode? packageInfoNode = packageInfoNodes[packageName];
161+
String compositePackageName = compositeName(packageName, outputUnitName);
162+
vm.ProgramInfoNode? packageInfoNode = infoNodesByName[compositePackageName];
163163
if (packageInfoNode == null) {
164-
String compositePackageName = compositeName(packageName, outputUnitName);
165164
vm.ProgramInfoNode newPackage = outputUnit.makeNode(
166-
name: compositePackageName,
165+
name: packageName,
167166
parent: outputUnit.root,
168167
type: vm.NodeType.packageNode);
169-
newPackage.size = libraryInfo.size;
170-
packageInfoNodes[compositePackageName] = newPackage;
168+
newPackage.size = 0;
171169
outputUnit.root.children[compositePackageName] = newPackage;
172170
var packageNode = infoNodesByName[compositePackageName];
173171
assert(packageNode == null,
174172
"encountered package with duplicated name: $compositePackageName");
175173
infoNodesByName[compositePackageName] = newPackage;
176-
} else {
177-
packageInfoNode.size = (packageInfoNode.size ?? 0) + libraryInfo.size;
174+
175+
/// Add the corresponding [PackageInfo] node in the [AllInfo] tree.
176+
OutputUnitInfo packageUnit = outputUnitInfos[outputUnitName]!;
177+
PackageInfo newPackageInfo =
178+
PackageInfo(packageName, packageUnit, newPackage.size!);
179+
newPackageInfo.libraries.add(libraryInfo);
180+
info.packages.add(newPackageInfo);
178181
}
179182
}
180183

184+
/// Aggregates the size of a library [vm.ProgramInfoNode] from the sizes of
185+
/// its top level children in the same output unit.
186+
int collectSizesForOutputUnit(
187+
Iterable<BasicInfo> infos, String outputUnitName) {
188+
int sizes = 0;
189+
for (var info in infos) {
190+
if (info.outputUnit!.filename == outputUnitName) {
191+
sizes += info.size;
192+
}
193+
}
194+
return sizes;
195+
}
196+
181197
void makeLibrary(LibraryInfo libraryInfo, String outputUnitName) {
182198
vm.ProgramInfo outputUnit = outputUnits[outputUnitName]!;
183199
String libraryName = libraryInfo.name;
@@ -190,11 +206,18 @@ class ProgramInfoBuilder extends VMProgramInfoVisitor<vm.ProgramInfoNode> {
190206
vm.ProgramInfoNode parentNode = infoNodesByName[compositePackageName]!;
191207
String compositeLibraryName = compositeName(libraryName, outputUnitName);
192208
vm.ProgramInfoNode newLibrary = outputUnit.makeNode(
193-
name: compositeLibraryName,
194-
parent: parentNode,
195-
type: vm.NodeType.libraryNode);
196-
newLibrary.size = libraryInfo.size;
209+
name: libraryName, parent: parentNode, type: vm.NodeType.libraryNode);
210+
newLibrary.size = 0;
211+
newLibrary.size = (newLibrary.size ?? 0) +
212+
collectSizesForOutputUnit(
213+
libraryInfo.topLevelFunctions, outputUnitName) +
214+
collectSizesForOutputUnit(
215+
libraryInfo.topLevelVariables, outputUnitName) +
216+
collectSizesForOutputUnit(libraryInfo.classes, outputUnitName) +
217+
collectSizesForOutputUnit(libraryInfo.classTypes, outputUnitName) +
218+
collectSizesForOutputUnit(libraryInfo.typedefs, outputUnitName);
197219
parentNode.children[newLibrary.name] = newLibrary;
220+
parentNode.size = (parentNode.size ?? 0) + newLibrary.size!;
198221
vm.ProgramInfoNode? libraryNode = infoNodesByName[compositeLibraryName];
199222
assert(libraryNode == null,
200223
"encountered library with duplicated name: $compositeLibraryName");
@@ -268,7 +291,7 @@ class ProgramInfoBuilder extends VMProgramInfoVisitor<vm.ProgramInfoNode> {
268291
///
269292
/// Note: we might want to create a separate [vm.NodeType.fieldNode] to
270293
/// differentiate fields from other miscellaneous nodes for constructing
271-
/// the call graph.
294+
/// the call graph in the future.
272295
void makeField(FieldInfo fieldInfo) {
273296
Info? parent = fieldInfo.parent;
274297
String outputUnitName = fieldInfo.outputUnit!.filename;
@@ -387,6 +410,7 @@ class ProgramInfoBuilder extends VMProgramInfoVisitor<vm.ProgramInfoNode> {
387410
@override
388411
vm.ProgramInfoNode visitOutput(OutputUnitInfo info) {
389412
vm.ProgramInfo? outputUnit = outputUnits[info.filename];
413+
outputUnitInfos[info.filename] = info;
390414
assert(outputUnit == null, "encountered outputUnit with duplicated name");
391415
var newUnit = vm.ProgramInfo();
392416
outputUnits[info.filename] = newUnit;
@@ -399,9 +423,6 @@ class ProgramInfoBuilder extends VMProgramInfoVisitor<vm.ProgramInfoNode> {
399423
for (var package in info.packages) {
400424
visitPackage(package, outputUnitName);
401425
}
402-
for (var library in info.libraries) {
403-
visitLibrary(library, outputUnitName);
404-
}
405426
info.constants.forEach(makeConstant);
406427
info.constants.forEach(visitConstant);
407428
return outputUnits[outputUnitName]!.root;
@@ -422,7 +443,7 @@ class ProgramInfoBuilder extends VMProgramInfoVisitor<vm.ProgramInfoNode> {
422443
}
423444

424445
@override
425-
vm.ProgramInfoNode visitLibrary(LibraryInfo info, String outputUnitName) {
446+
vm.ProgramInfoNode? visitLibrary(LibraryInfo info, String outputUnitName) {
426447
info.topLevelFunctions.forEach(makeFunction);
427448
info.topLevelFunctions.forEach(visitFunction);
428449
info.topLevelVariables.forEach(makeField);
@@ -433,9 +454,11 @@ class ProgramInfoBuilder extends VMProgramInfoVisitor<vm.ProgramInfoNode> {
433454
info.classTypes.forEach(visitClassType);
434455
info.typedefs.forEach(makeTypedef);
435456
info.typedefs.forEach(visitTypedef);
436-
return infoNodesByName[compositeName(info.name, outputUnitName)] ??
437-
infoNodesByName[
438-
compositeName(unnamedLibraries[info]!, outputUnitName)]!;
457+
vm.ProgramInfoNode currentLibrary =
458+
infoNodesByName[compositeName(info.name, outputUnitName)] ??
459+
infoNodesByName[
460+
compositeName(unnamedLibraries[info]!, outputUnitName)]!;
461+
return currentLibrary;
439462
}
440463

441464
@override

pkg/dart2js_info/lib/info.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,10 @@ class ProgramInfo {
193193
/// Note that PackageInfo is only used for converting dart2js info to
194194
/// vm_snapshot_analysis ProgramInfo and is not expected for --dump-info output.
195195
class PackageInfo extends BasicInfo {
196-
/// Canonical uri that identifies the package
197-
late final Uri uri;
198-
199196
/// All libraries defined within the package
200197
List<LibraryInfo> libraries = <LibraryInfo>[];
201198

202-
PackageInfo(String name, this.uri, OutputUnitInfo outputUnit, int size)
199+
PackageInfo(String name, OutputUnitInfo outputUnit, int size)
203200
: super(InfoKind.package, name, outputUnit, size, null);
204201

205202
@override

0 commit comments

Comments
 (0)