Skip to content

Commit 627b5e8

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Make InterfaceElement2.name nullable.
Change-Id: I7dbbc3197507da2e8f5642e142e994583f5c0c10 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390781 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 8cda83f commit 627b5e8

File tree

8 files changed

+41
-22
lines changed

8 files changed

+41
-22
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class AddMissingEnumLikeCaseClauses extends ResolvedCorrectionProducer {
3535
}
3636
var classElement = expressionType.element3;
3737
var className = classElement.name;
38+
if (className == null) {
39+
return;
40+
}
41+
3842
var caseNames = _caseNames(node);
3943
var missingNames = _constantNames(classElement)
4044
..removeWhere((e) => caseNames.contains(e));

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ class ChangeToStaticAccess extends ResolvedCorrectionProducer {
5353
var declaringElement = invokedElement.enclosingElement2;
5454

5555
if (declaringElement is InterfaceElement2) {
56-
_className = declaringElement.name;
57-
await builder.addDartFileEdit(file, (builder) {
58-
builder.addReplacement(range.node(target_final), (builder) {
59-
builder.writeReference2(declaringElement);
56+
var declaringElementName = declaringElement.name;
57+
if (declaringElementName != null) {
58+
_className = declaringElementName;
59+
await builder.addDartFileEdit(file, (builder) {
60+
builder.addReplacement(range.node(target_final), (builder) {
61+
builder.writeReference2(declaringElement);
62+
});
6063
});
61-
});
64+
}
6265
} else if (declaringElement is ExtensionElement2) {
6366
var extensionName = declaringElement.name;
6467
if (extensionName != null) {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,15 @@ class CreateConstructor extends ResolvedCorrectionProducer {
159159
return;
160160
}
161161

162-
// prepare target ClassDeclaration
163162
var targetElement = constructorElement.enclosingElement2;
164163
var targetFragment = (targetElement as ClassElement2).firstFragment;
164+
165+
var targetElementName = targetElement.name;
166+
if (targetElementName == null) {
167+
return;
168+
}
169+
170+
// prepare target ClassDeclaration
165171
var targetResult =
166172
await sessionHelper.getElementDeclaration2(targetFragment);
167173
if (targetResult == null) {
@@ -181,7 +187,7 @@ class CreateConstructor extends ResolvedCorrectionProducer {
181187
var targetFile = targetSource.fullName;
182188
await builder.addDartFileEdit(targetFile, (builder) {
183189
builder.insertConstructor(targetNode, (builder) {
184-
builder.writeConstructorDeclaration(targetElement.name,
190+
builder.writeConstructorDeclaration(targetElementName,
185191
argumentList: instanceCreation.argumentList);
186192
});
187193
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ List<String> getVariableNameSuggestionsForExpression(DartType? expectedType,
6868
_addSingleCharacterName(excluded, res, 0x73);
6969
} else if (expectedType is InterfaceType) {
7070
var className = expectedType.element3.name;
71-
_addAll(excluded, res, getCamelWordCombinations(className));
71+
if (className != null) {
72+
_addAll(excluded, res, getCamelWordCombinations(className));
73+
}
7274
}
7375
}
7476
// done

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,9 +1125,6 @@ abstract class InterfaceElement2 implements InstanceElement2 {
11251125
/// guard against infinite loops.
11261126
List<InterfaceType> get mixins;
11271127

1128-
@override
1129-
String get name;
1130-
11311128
/// The superclass of this element.
11321129
///
11331130
/// For [ClassElement] returns `null` only if this class is `Object`. If the

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ abstract class AugmentedInterfaceElementImpl
166166

167167
@override
168168
List<ConstructorElement> constructors = [];
169-
170-
@override
171-
String get name => super.name!;
172169
}
173170

174171
class AugmentedMixinElementImpl extends AugmentedInterfaceElementImpl
@@ -8589,9 +8586,6 @@ abstract class NotAugmentedInterfaceElementImpl
85898586
return element.mixins;
85908587
}
85918588

8592-
@override
8593-
String get name => element.name;
8594-
85958589
@override
85968590
ConstructorElement? get unnamedConstructor {
85978591
return element.unnamedConstructor;

pkg/linter/lib/src/rules/implicit_reopen.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,14 @@ class _Visitor extends SimpleAstVisitor<void> {
7373
required InterfaceElement2 other,
7474
required String reason,
7575
}) {
76-
rule.reportLintForToken(member.name,
77-
arguments: [type, target.name, other.name, reason]);
76+
var targetName = target.name;
77+
var otherName = other.name;
78+
if (targetName != null && otherName != null) {
79+
rule.reportLintForToken(
80+
member.name,
81+
arguments: [type, targetName, otherName, reason],
82+
);
83+
}
7884
}
7985

8086
@override

pkg/linter/lib/src/rules/null_closures.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,20 @@ class _Visitor extends SimpleAstVisitor<void> {
233233
var element = type.element3;
234234
if (element.isSynthetic) return null;
235235

236-
var method = getMethod(element.library2.name, element.name);
236+
var elementName = element.name;
237+
if (elementName == null) {
238+
return null;
239+
}
240+
241+
var method = getMethod(element.library2.name, elementName);
237242
if (method != null) return method;
238243

239244
for (var supertype in element.allSupertypes) {
240245
var superElement = supertype.element3;
241-
method = getMethod(superElement.library2.name, superElement.name);
242-
if (method != null) return method;
246+
if (superElement.name case var superElementName?) {
247+
method = getMethod(superElement.library2.name, superElementName);
248+
if (method != null) return method;
249+
}
243250
}
244251
return null;
245252
}

0 commit comments

Comments
 (0)