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

Commit a04fa8e

Browse files
author
Dart CI
committed
Version 2.16.0-133.0.dev
Merge commit '6e27367656c263fcce5fcb91586b3ea4a85e98d3' into 'dev'
2 parents de84784 + 6e27367 commit a04fa8e

File tree

12 files changed

+345
-90
lines changed

12 files changed

+345
-90
lines changed

pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_descriptor.dart

Lines changed: 100 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -40,119 +40,135 @@ class ElementDescriptor {
4040
/// Return `true` if the described element is a constructor.
4141
bool get isConstructor => kind == ElementKind.constructorKind;
4242

43-
/// Return `true` if the given [node] appears to be consistent with this kind
44-
/// of element.
43+
/// Return `true` if the given [node] appears to be consistent with the
44+
/// element being described.
4545
bool matches(AstNode node) {
46-
// TODO(brianwilkerson) Check the resolved element if one exists for more
46+
// TODO(brianwilkerson) Check the resolved element, if one exists, for more
4747
// accurate results.
4848
switch (kind) {
4949
case ElementKind.classKind:
50-
// TODO: Handle this case.
50+
// TODO(brianwilkerson) Handle this case.
5151
return false;
5252
case ElementKind.constantKind:
53-
// TODO: Handle this case.
53+
// TODO(brianwilkerson) Handle this case.
5454
return false;
5555
case ElementKind.constructorKind:
56-
if (node is Annotation) {
57-
var className = _nameFromIdentifier(node.name);
58-
var constructorName = node.constructorName ?? '';
59-
if (components[0] == constructorName && components[1] == className) {
60-
return true;
61-
}
62-
} else if (node is InstanceCreationExpression) {
63-
var name = node.constructorName;
64-
var className = _nameFromIdentifier(name.type2.name);
65-
var constructorName = name.name?.name ?? '';
66-
if (components[0] == constructorName && components[1] == className) {
67-
return true;
68-
}
69-
} else if (node is MethodInvocation) {
70-
var target = node.target;
71-
if (target == null) {
72-
if (components[0] == '' && components[1] == node.methodName.name) {
73-
return true;
74-
}
75-
} else if (target is Identifier) {
76-
var className = _nameFromIdentifier(target);
77-
var constructorName = node.methodName.name;
78-
if (components[0] == constructorName &&
79-
components[1] == className) {
80-
return true;
81-
}
82-
}
83-
}
84-
return false;
56+
return _matchesConstructor(node);
8557
case ElementKind.enumKind:
86-
// TODO: Handle this case.
58+
// TODO(brianwilkerson) Handle this case.
8759
return false;
8860
case ElementKind.extensionKind:
89-
// TODO: Handle this case.
61+
// TODO(brianwilkerson) Handle this case.
9062
return false;
9163
case ElementKind.fieldKind:
92-
// TODO: Handle this case.
64+
// TODO(brianwilkerson) Handle this case.
9365
return false;
9466
case ElementKind.functionKind:
95-
if (node is MethodInvocation) {
96-
if (node.realTarget == null &&
97-
components[0] == node.methodName.name) {
98-
return true;
99-
}
100-
}
101-
return false;
67+
return _matchesFunction(node);
10268
case ElementKind.getterKind:
103-
// TODO: Handle this case.
69+
// TODO(brianwilkerson) Handle this case.
10470
return false;
10571
case ElementKind.methodKind:
106-
if (node is MethodInvocation) {
107-
if (components[0] == node.methodName.name) {
108-
var target = node.realTarget;
109-
if (target == null) {
110-
// TODO(brianwilkerson) If `node.target == null` then the invocation
111-
// should be in a subclass of the element's class.
112-
return true;
113-
} else {
114-
var type = target.staticType;
115-
if (type == null && target is SimpleIdentifier) {
116-
var element = target.staticElement;
117-
// TODO(brianwilkerson) Handle more than `ClassElement`.
118-
if (element is ClassElement) {
119-
type = element.thisType;
120-
}
121-
}
122-
if (type == null) {
123-
// We can't get more specific type information, so we assume
124-
// that the method might have been in the element's class.
125-
return true;
126-
}
127-
if (components[1] == type.element?.name) {
128-
return true;
129-
}
130-
if (type is InterfaceType) {
131-
for (var supertype in type.allSupertypes) {
132-
if (components[1] == supertype.element.name) {
133-
return true;
134-
}
135-
}
136-
}
137-
}
138-
}
139-
}
140-
return false;
72+
return _matchesMethod(node);
14173
case ElementKind.mixinKind:
142-
// TODO: Handle this case.
74+
// TODO(brianwilkerson) Handle this case.
14375
return false;
14476
case ElementKind.setterKind:
145-
// TODO: Handle this case.
77+
// TODO(brianwilkerson) Handle this case.
14678
return false;
14779
case ElementKind.typedefKind:
148-
// TODO: Handle this case.
80+
// TODO(brianwilkerson) Handle this case.
14981
return false;
15082
case ElementKind.variableKind:
151-
// TODO: Handle this case.
83+
// TODO(brianwilkerson) Handle this case.
15284
return false;
15385
}
15486
}
15587

88+
/// Return `true` if the given [node] appears to be consistent with the
89+
/// constructor being described.
90+
bool _matchesConstructor(AstNode node) {
91+
if (node is Annotation) {
92+
var className = _nameFromIdentifier(node.name);
93+
var constructorName = node.constructorName ?? '';
94+
if (components[0] == constructorName && components[1] == className) {
95+
return true;
96+
}
97+
} else if (node is InstanceCreationExpression) {
98+
var name = node.constructorName;
99+
var className = _nameFromIdentifier(name.type2.name);
100+
var constructorName = name.name?.name ?? '';
101+
if (components[0] == constructorName && components[1] == className) {
102+
return true;
103+
}
104+
} else if (node is MethodInvocation) {
105+
var target = node.target;
106+
if (target == null) {
107+
if (components[0] == '' && components[1] == node.methodName.name) {
108+
return true;
109+
}
110+
} else if (target is Identifier) {
111+
var className = _nameFromIdentifier(target);
112+
var constructorName = node.methodName.name;
113+
if (components[0] == constructorName && components[1] == className) {
114+
return true;
115+
}
116+
}
117+
}
118+
return false;
119+
}
120+
121+
/// Return `true` if the given [node] appears to be consistent with the
122+
/// function being described.
123+
bool _matchesFunction(AstNode node) {
124+
if (node is MethodInvocation) {
125+
if (node.realTarget == null && components[0] == node.methodName.name) {
126+
return true;
127+
}
128+
}
129+
return false;
130+
}
131+
132+
/// Return `true` if the given [node] appears to be consistent with the
133+
/// method being described.
134+
bool _matchesMethod(AstNode node) {
135+
if (node is MethodInvocation) {
136+
if (components[0] == node.methodName.name) {
137+
var target = node.realTarget;
138+
if (target == null) {
139+
// TODO(brianwilkerson) If `node.target == null` then the invocation
140+
// should be in a subclass of the element's class.
141+
return true;
142+
} else {
143+
var type = target.staticType;
144+
if (type == null && target is SimpleIdentifier) {
145+
var element = target.staticElement;
146+
// TODO(brianwilkerson) Handle more than `ClassElement`.
147+
if (element is ClassElement) {
148+
type = element.thisType;
149+
}
150+
}
151+
if (type == null) {
152+
// We can't get more specific type information, so we assume
153+
// that the method might have been in the element's class.
154+
return true;
155+
}
156+
if (components[1] == type.element?.name) {
157+
return true;
158+
}
159+
if (type is InterfaceType) {
160+
for (var supertype in type.allSupertypes) {
161+
if (components[1] == supertype.element.name) {
162+
return true;
163+
}
164+
}
165+
}
166+
}
167+
}
168+
}
169+
return false;
170+
}
171+
156172
String _nameFromIdentifier(Identifier identifier) {
157173
if (identifier is SimpleIdentifier) {
158174
return identifier.name;

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class FixInFileProcessor {
312312

313313
List<ProducerGenerator> _getGenerators(ErrorCode errorCode) {
314314
if (errorCode is LintCode) {
315-
return FixProcessor.lintProducerMap[errorCode.name] ?? [];
315+
return FixProcessor.lintProducerMap[errorCode.uniqueLintName] ?? [];
316316
} else {
317317
// todo (pq): consider support for multiGenerators
318318
return FixProcessor.nonLintProducerMap[errorCode] ?? [];
@@ -326,6 +326,12 @@ class FixProcessor extends BaseProcessor {
326326
/// used to create correction producers. The generators are then used to build
327327
/// fixes for those diagnostics. The generators used for non-lint diagnostics
328328
/// are in the [nonLintProducerMap].
329+
///
330+
/// The keys of the map are the unique names of the lint codes without the
331+
/// `LintCode.` prefix. Generally the unique name is the same as the name of
332+
/// the lint, so most of the keys are constants defined by [LintNames]. But
333+
/// when a lint produces multiple codes, each with a different unique name,
334+
/// the unique name must be used here.
329335
static final Map<String, List<ProducerGenerator>> lintProducerMap = {
330336
LintNames.always_declare_return_types: [
331337
AddReturnType.newInstance,
@@ -1355,7 +1361,7 @@ class FixProcessor extends BaseProcessor {
13551361

13561362
var errorCode = error.errorCode;
13571363
if (errorCode is LintCode) {
1358-
var generators = lintProducerMap[errorCode.name] ?? [];
1364+
var generators = lintProducerMap[errorCode.uniqueLintName] ?? [];
13591365
for (var generator in generators) {
13601366
await compute(generator());
13611367
}
@@ -1428,3 +1434,12 @@ class _NotEmptyFixState implements _FixState {
14281434
required this.fixCount,
14291435
});
14301436
}
1437+
1438+
extension on LintCode {
1439+
String get uniqueLintName {
1440+
if (uniqueName.startsWith('LintCode.')) {
1441+
return uniqueName.substring(9);
1442+
}
1443+
return uniqueName;
1444+
}
1445+
}

pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,57 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
975975
_setOrCreateMetadataElements(element, node.metadata);
976976
}
977977

978+
@override
979+
void visitSuperFormalParameter(covariant SuperFormalParameterImpl node) {
980+
SuperFormalParameterElementImpl element;
981+
if (node.parent is DefaultFormalParameter) {
982+
element = node.declaredElement as SuperFormalParameterElementImpl;
983+
} else {
984+
var nameNode = node.identifier;
985+
if (_elementWalker != null) {
986+
element =
987+
_elementWalker!.getParameter() as SuperFormalParameterElementImpl;
988+
} else {
989+
// Only for recovery, this should not happen in valid code.
990+
element = SuperFormalParameterElementImpl(
991+
name: nameNode.name,
992+
nameOffset: nameNode.offset,
993+
parameterKind: node.kind,
994+
);
995+
_elementHolder.enclose(element);
996+
element.isConst = node.isConst;
997+
element.isExplicitlyCovariant = node.covariantKeyword != null;
998+
element.isFinal = node.isFinal;
999+
_setCodeRange(element, node);
1000+
}
1001+
nameNode.staticElement = element;
1002+
}
1003+
1004+
_setOrCreateMetadataElements(element, node.metadata);
1005+
1006+
_withElementHolder(ElementHolder(element), () {
1007+
_withElementWalker(
1008+
_elementWalker != null ? ElementWalker.forParameter(element) : null,
1009+
() {
1010+
_withNameScope(() {
1011+
_buildTypeParameterElements(node.typeParameters);
1012+
node.typeParameters?.accept(this);
1013+
node.type?.accept(this);
1014+
if (_elementWalker != null) {
1015+
node.parameters?.accept(this);
1016+
} else {
1017+
// Only for recovery, this should not happen in valid code.
1018+
element.type = node.type?.type ?? _dynamicType;
1019+
_withElementWalker(null, () {
1020+
node.parameters?.accept(this);
1021+
});
1022+
}
1023+
});
1024+
},
1025+
);
1026+
});
1027+
}
1028+
9781029
@override
9791030
void visitSwitchCase(SwitchCase node) {
9801031
_buildLabelElements(node.labels, false, true);

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4159,6 +4159,15 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
41594159
return;
41604160
}
41614161

4162+
// TODO(scheglov) Restore when working on errors.
4163+
if (_currentLibrary.featureSet.isEnabled(Feature.super_parameters)) {
4164+
if (constructor.parameters.parameters.any((parameter) {
4165+
return parameter.notDefault is SuperFormalParameter;
4166+
})) {
4167+
return;
4168+
}
4169+
}
4170+
41624171
// Ignore if the constructor has either an implicit super constructor
41634172
// invocation or a redirecting constructor invocation.
41644173
for (ConstructorInitializer constructorInitializer

pkg/analyzer/lib/src/test_utilities/find_element.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,3 +636,14 @@ abstract class _FindElementBase {
636636
return class_(name).unnamedConstructor!;
637637
}
638638
}
639+
640+
extension ExecutableElementExtensions on ExecutableElement {
641+
SuperFormalParameterElement superFormalParameter(String name) {
642+
for (var parameter in parameters) {
643+
if (parameter is SuperFormalParameterElement && parameter.name == name) {
644+
return parameter;
645+
}
646+
}
647+
throw StateError('Not found: $name');
648+
}
649+
}

pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class PubPackageResolutionTest extends ContextResolutionTest {
259259
List<String> get experiments => [
260260
EnableString.constructor_tearoffs,
261261
EnableString.named_arguments_anywhere,
262+
EnableString.super_parameters,
262263
];
263264

264265
/// The path that is not in [workspaceRootPath], contains external packages.

0 commit comments

Comments
 (0)