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

Commit 5c59a47

Browse files
author
Dart CI
committed
Version 2.11.0-234.0.dev
Merge commit 'b155af244282a612ff4f5fff4919c904a2922df5' into 'dev'
2 parents 675c716 + b155af2 commit 5c59a47

File tree

5 files changed

+102
-110
lines changed

5 files changed

+102
-110
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,14 @@ abstract class ElementAnnotation implements ConstantEvaluationTarget {
697697
@Deprecated('Use computeConstantValue() instead')
698698
DartObject get constantValue;
699699

700-
/// Return the element representing the field, variable, or const constructor
701-
/// being used as an annotation.
700+
/// Return the element referenced by this annotation.
701+
///
702+
/// In valid code this element can be a [PropertyAccessorElement] getter
703+
/// of a constant top-level variable, or a constant static field of a
704+
/// class; or a constant [ConstructorElement].
705+
///
706+
/// In invalid code this element can be `null`, or a reference to any
707+
/// other element.
702708
Element get element;
703709

704710
/// Return `true` if this annotation marks the associated function as always

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ class AnalysisDriver implements AnalysisDriverGeneric {
174174
/// The list of tasks to compute files referencing a name.
175175
final _referencingNameTasks = <_FilesReferencingNameTask>[];
176176

177+
/// The mapping from the files for which errors were requested using
178+
/// [getErrors] to the [Completer]s to report the result.
179+
final _errorsRequestedFiles = <String, List<Completer<ErrorsResult>>>{};
180+
181+
/// The requests from [_errorsRequestedFiles] for files which were found to
182+
/// be parts without known libraries, so delayed.
183+
final _errorsRequestedParts = <String, List<Completer<ErrorsResult>>>{};
184+
177185
/// The mapping from the files for which the index was requested using
178186
/// [getIndex] to the [Completer]s to report the result.
179187
final _indexRequestedFiles =
@@ -385,6 +393,9 @@ class AnalysisDriver implements AnalysisDriverGeneric {
385393
_referencingNameTasks.isNotEmpty) {
386394
return AnalysisDriverPriority.interactive;
387395
}
396+
if (_errorsRequestedFiles.isNotEmpty) {
397+
return AnalysisDriverPriority.interactive;
398+
}
388399
if (_indexRequestedFiles.isNotEmpty) {
389400
return AnalysisDriverPriority.interactive;
390401
}
@@ -416,7 +427,8 @@ class AnalysisDriver implements AnalysisDriverGeneric {
416427
if (_fileTracker.hasPendingFiles) {
417428
return AnalysisDriverPriority.general;
418429
}
419-
if (_requestedParts.isNotEmpty ||
430+
if (_errorsRequestedParts.isNotEmpty ||
431+
_requestedParts.isNotEmpty ||
420432
_partsToAnalyze.isNotEmpty ||
421433
_unitElementSignatureParts.isNotEmpty ||
422434
_unitElementRequestedParts.isNotEmpty) {
@@ -547,19 +559,12 @@ class AnalysisDriver implements AnalysisDriverGeneric {
547559
return null;
548560
}
549561

550-
// Ask the analysis result without unit, so return cached errors.
551-
// If no cached analysis result, it will be computed.
552-
ResolvedUnitResult analysisResult = _computeAnalysisResult(path);
553-
554-
// If not computed yet, because a part file without a known library,
555-
// we have to compute the full analysis result, with the unit.
556-
analysisResult ??= await getResult(path);
557-
if (analysisResult == null) {
558-
return null;
559-
}
560-
561-
return ErrorsResultImpl(currentSession, path, analysisResult.uri,
562-
analysisResult.lineInfo, analysisResult.isPart, analysisResult.errors);
562+
var completer = Completer<ErrorsResult>();
563+
_errorsRequestedFiles
564+
.putIfAbsent(path, () => <Completer<ErrorsResult>>[])
565+
.add(completer);
566+
_scheduler.notify(this);
567+
return completer.future;
563568
}
564569

565570
/// Return a [Future] that completes with the list of added files that
@@ -967,6 +972,21 @@ class AnalysisDriver implements AnalysisDriverGeneric {
967972
return;
968973
}
969974

975+
// Process an error request.
976+
if (_errorsRequestedFiles.isNotEmpty) {
977+
var path = _errorsRequestedFiles.keys.first;
978+
var completers = _errorsRequestedFiles.remove(path);
979+
var result = _computeErrors(path: path, asIsIfPartWithoutLibrary: false);
980+
if (result != null) {
981+
completers.forEach((completer) {
982+
completer.complete(result);
983+
});
984+
} else {
985+
_errorsRequestedParts.putIfAbsent(path, () => []).addAll(completers);
986+
}
987+
return;
988+
}
989+
970990
// Process an index request.
971991
if (_indexRequestedFiles.isNotEmpty) {
972992
String path = _indexRequestedFiles.keys.first;
@@ -1147,6 +1167,17 @@ class AnalysisDriver implements AnalysisDriverGeneric {
11471167
});
11481168
return;
11491169
}
1170+
1171+
// Compute errors in a part.
1172+
if (_errorsRequestedParts.isNotEmpty) {
1173+
var path = _errorsRequestedParts.keys.first;
1174+
var completers = _errorsRequestedParts.remove(path);
1175+
var result = _computeErrors(path: path, asIsIfPartWithoutLibrary: true);
1176+
completers.forEach((completer) {
1177+
completer.complete(result);
1178+
});
1179+
return;
1180+
}
11501181
}
11511182

11521183
/// Remove the file with the given [path] from the list of files to analyze.
@@ -1334,6 +1365,21 @@ class AnalysisDriver implements AnalysisDriverGeneric {
13341365
return Uint8List.fromList(bytes).buffer.asUint32List();
13351366
}
13361367

1368+
ErrorsResult _computeErrors({
1369+
@required String path,
1370+
@required bool asIsIfPartWithoutLibrary,
1371+
}) {
1372+
ResolvedUnitResult analysisResult = _computeAnalysisResult(path,
1373+
withUnit: false, asIsIfPartWithoutLibrary: asIsIfPartWithoutLibrary);
1374+
1375+
if (analysisResult == null) {
1376+
return null;
1377+
}
1378+
1379+
return ErrorsResultImpl(currentSession, path, analysisResult.uri,
1380+
analysisResult.lineInfo, analysisResult.isPart, analysisResult.errors);
1381+
}
1382+
13371383
AnalysisDriverUnitIndex _computeIndex(String path) {
13381384
AnalysisResult analysisResult = _computeAnalysisResult(path,
13391385
withUnit: false, asIsIfPartWithoutLibrary: true);

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,8 +2418,6 @@ class ElementAnnotationImpl implements ElementAnnotation {
24182418
/// visible for testing.
24192419
static const String _VISIBLE_FOR_TESTING_VARIABLE_NAME = "visibleForTesting";
24202420

2421-
/// The element representing the field, variable, or constructor being used as
2422-
/// an annotation.
24232421
@override
24242422
Element element;
24252423

@@ -3731,7 +3729,7 @@ abstract class ExecutableElementImpl extends ElementImpl
37313729
var context = enclosingUnit.linkedContext;
37323730
var containerRef = reference.getChild('@parameter');
37333731
var formalParameters = context.getFormalParameters(linkedNode);
3734-
_parameters = ParameterElementImpl.forLinkedNodeList(
3732+
return _parameters = ParameterElementImpl.forLinkedNodeList(
37353733
this,
37363734
context,
37373735
containerRef,
@@ -4537,11 +4535,11 @@ class FunctionTypeAliasElementImpl extends ElementImpl
45374535
GenericFunctionTypeElementImpl get function {
45384536
if (_function != null) return _function;
45394537

4540-
if (linkedNode != null) {
4541-
LazyAst.applyResolution(linkedNode);
4542-
if (linkedNode is GenericTypeAlias) {
4543-
var context = enclosingUnit.linkedContext;
4544-
var function = context.getGeneticTypeAliasFunction(linkedNode);
4538+
var node = linkedNode;
4539+
if (node != null) {
4540+
LazyAst.applyResolution(node);
4541+
if (node is GenericTypeAlias) {
4542+
var function = node.functionType;
45454543
if (function != null) {
45464544
return _function = GenericFunctionTypeElementImpl.forLinkedNode(
45474545
this,
@@ -4742,17 +4740,20 @@ class GenericFunctionTypeElementImpl extends ElementImpl
47424740

47434741
@override
47444742
List<ParameterElement> get parameters {
4745-
if (_parameters == null) {
4746-
if (linkedNode != null) {
4747-
var context = enclosingUnit.linkedContext;
4748-
return _parameters = ParameterElementImpl.forLinkedNodeList(
4749-
this,
4750-
context,
4751-
reference.getChild('@parameter'),
4752-
context.getFormalParameters(linkedNode),
4753-
);
4754-
}
4743+
if (_parameters != null) return _parameters;
4744+
4745+
if (linkedNode != null) {
4746+
var context = enclosingUnit.linkedContext;
4747+
var containerRef = reference.getChild('@parameter');
4748+
var formalParameters = context.getFormalParameters(linkedNode);
4749+
return _parameters = ParameterElementImpl.forLinkedNodeList(
4750+
this,
4751+
context,
4752+
containerRef,
4753+
formalParameters,
4754+
);
47554755
}
4756+
47564757
return _parameters ?? const <ParameterElement>[];
47574758
}
47584759

@@ -6569,18 +6570,14 @@ class ParameterElementImpl extends VariableElementImpl
65696570

65706571
if (linkedNode != null) {
65716572
var context = enclosingUnit.linkedContext;
6573+
var containerRef = reference.getChild('@parameter');
65726574
var formalParameters = context.getFormalParameters(linkedNode);
6573-
if (formalParameters != null) {
6574-
var containerRef = reference.getChild('@parameter');
6575-
return _parameters = ParameterElementImpl.forLinkedNodeList(
6576-
this,
6577-
context,
6578-
containerRef,
6579-
formalParameters,
6580-
);
6581-
} else {
6582-
return _parameters ??= const <ParameterElement>[];
6583-
}
6575+
return _parameters = ParameterElementImpl.forLinkedNodeList(
6576+
this,
6577+
context,
6578+
containerRef,
6579+
formalParameters,
6580+
);
65846581
}
65856582

65866583
return _parameters ??= const <ParameterElement>[];
@@ -6614,7 +6611,7 @@ class ParameterElementImpl extends VariableElementImpl
66146611
if (_typeParameters != null) return _typeParameters;
66156612

66166613
if (linkedNode != null) {
6617-
var typeParameters = linkedContext.getTypeParameters2(linkedNode);
6614+
var typeParameters = linkedContext.getTypeParameters(linkedNode);
66186615
if (typeParameters == null) {
66196616
return _typeParameters = const [];
66206617
}
@@ -7429,8 +7426,8 @@ class TypeParameterElementImpl extends ElementImpl
74297426
if (_bound != null) return _bound;
74307427

74317428
if (linkedNode != null) {
7432-
var context = enclosingUnit.linkedContext;
7433-
return _bound = context.getTypeParameterBound(linkedNode)?.type;
7429+
var node = linkedNode as TypeParameter;
7430+
return _bound = node.bound?.type;
74347431
}
74357432

74367433
return _bound;
@@ -7565,7 +7562,7 @@ mixin TypeParameterizedElementMixin
75657562

75667563
if (linkedNode != null) {
75677564
LazyAst.applyResolution(linkedNode);
7568-
var typeParameters = linkedContext.getTypeParameters2(linkedNode);
7565+
var typeParameters = linkedContext.getTypeParameters(linkedNode);
75697566
if (typeParameters == null) {
75707567
return _typeParameterElements = const [];
75717568
}

0 commit comments

Comments
 (0)