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

Commit 527c165

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Deprecate 'abstract' setter in elements, replace with 'isAbstract'.
I deprecated 'abstract', but I don't see any uses of it outside of analyzer, which I have fixed. So, maybe we should remove them right now? [email protected], [email protected] Change-Id: Ifd86a6b0148be49df6455672742f825ffd50f661 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103661 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent d368bb8 commit 527c165

File tree

5 files changed

+43
-21
lines changed

5 files changed

+43
-21
lines changed

pkg/analyzer/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
`featureSet` parameter.
55
* Refined the return type of the getter `TypeParameter.declaredElement`. It is
66
always guaranteed to return a `TypeParameterElement`.
7+
* Deprecated the `abstract` setter in `ClassElementImpl`, `EnumElementImpl`,
8+
`MethodElementImpl`, and `PropertyAccessorElementImpl`. `isAbstract` should
9+
be used instead.
710

811
## 0.36.3
912
* Deprecated `AstFactory.compilationUnit`. In a future analyzer release, this

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ApiElementBuilder extends _BaseElementBuilder {
8383
SimpleIdentifier className = node.name;
8484
ClassElementImpl element = new ClassElementImpl.forNode(className);
8585
className.staticElement = element;
86-
element.abstract = node.isAbstract;
86+
element.isAbstract = node.isAbstract;
8787
_fillClassElement(node, element, holder);
8888

8989
_currentHolder.addType(element);
@@ -97,7 +97,7 @@ class ApiElementBuilder extends _BaseElementBuilder {
9797
ClassElementImpl element = new ClassElementImpl.forNode(className);
9898
_setCodeRange(element, node);
9999
element.metadata = _createElementAnnotations(node.metadata);
100-
element.abstract = node.abstractKeyword != null;
100+
element.isAbstract = node.abstractKeyword != null;
101101
element.mixinApplication = true;
102102
element.typeParameters = holder.typeParameters;
103103
setElementDocumentationComment(element, node);
@@ -430,7 +430,7 @@ class ApiElementBuilder extends _BaseElementBuilder {
430430
_setCodeRange(element, node);
431431
element.metadata = _createElementAnnotations(node.metadata);
432432
setElementDocumentationComment(element, node);
433-
element.abstract = node.isAbstract;
433+
element.isAbstract = node.isAbstract;
434434
if (node.externalKeyword != null || body is NativeFunctionBody) {
435435
element.external = true;
436436
}
@@ -482,7 +482,7 @@ class ApiElementBuilder extends _BaseElementBuilder {
482482
getter.generator = true;
483483
}
484484
getter.variable = field;
485-
getter.abstract = node.isAbstract;
485+
getter.isAbstract = node.isAbstract;
486486
getter.getter = true;
487487
getter.isStatic = isStatic;
488488
field.getter = getter;
@@ -511,7 +511,7 @@ class ApiElementBuilder extends _BaseElementBuilder {
511511
setter.generator = true;
512512
}
513513
setter.variable = field;
514-
setter.abstract = node.isAbstract;
514+
setter.isAbstract = node.isAbstract;
515515
setter.setter = true;
516516
setter.isStatic = isStatic;
517517
if (node.returnType == null) {

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,9 @@ class ClassElementImpl extends AbstractClassElementImpl
479479
: super.forSerialized(enclosingUnit);
480480

481481
/// Set whether this class is abstract.
482+
@Deprecated('Use isAbstract instead')
482483
void set abstract(bool isAbstract) {
483-
_assertNotResynthesized(_unlinkedClass);
484-
setModifier(Modifier.ABSTRACT, isAbstract);
484+
this.isAbstract = isAbstract;
485485
}
486486

487487
@override
@@ -824,6 +824,12 @@ class ClassElementImpl extends AbstractClassElementImpl
824824
return hasModifier(Modifier.ABSTRACT);
825825
}
826826

827+
/// Set whether this class is abstract.
828+
void set isAbstract(bool isAbstract) {
829+
_assertNotResynthesized(_unlinkedClass);
830+
setModifier(Modifier.ABSTRACT, isAbstract);
831+
}
832+
827833
@override
828834
bool get isMixinApplication {
829835
if (linkedNode != null) {
@@ -4016,6 +4022,7 @@ class EnumElementImpl extends AbstractClassElementImpl {
40164022
: super.forSerialized(enclosingUnit);
40174023

40184024
/// Set whether this class is abstract.
4025+
@Deprecated('This setter will be removed')
40194026
void set abstract(bool isAbstract) {
40204027
_assertNotResynthesized(_unlinkedEnum);
40214028
}
@@ -7185,9 +7192,9 @@ class MethodElementImpl extends ExecutableElementImpl implements MethodElement {
71857192
: super.forSerialized(serializedExecutable, enclosingClass);
71867193

71877194
/// Set whether this method is abstract.
7195+
@Deprecated('Use isAbstract instead')
71887196
void set abstract(bool isAbstract) {
7189-
_assertNotResynthesized(serializedExecutable);
7190-
setModifier(Modifier.ABSTRACT, isAbstract);
7197+
this.isAbstract = isAbstract;
71917198
}
71927199

71937200
@override
@@ -7206,6 +7213,12 @@ class MethodElementImpl extends ExecutableElementImpl implements MethodElement {
72067213
TypeParameterizedElementMixin get enclosingTypeParameterContext =>
72077214
super.enclosingElement as ClassElementImpl;
72087215

7216+
/// Set whether this class is abstract.
7217+
void set isAbstract(bool isAbstract) {
7218+
_assertNotResynthesized(serializedExecutable);
7219+
setModifier(Modifier.ABSTRACT, isAbstract);
7220+
}
7221+
72097222
@override
72107223
bool get isOperator {
72117224
String name = displayName;
@@ -8897,9 +8910,9 @@ class PropertyAccessorElementImpl extends ExecutableElementImpl
88978910
}
88988911

88998912
/// Set whether this accessor is abstract.
8913+
@Deprecated('Use isAbstract instead')
89008914
void set abstract(bool isAbstract) {
8901-
_assertNotResynthesized(serializedExecutable);
8902-
setModifier(Modifier.ABSTRACT, isAbstract);
8915+
this.isAbstract = isAbstract;
89038916
}
89048917

89058918
@override
@@ -8946,6 +8959,12 @@ class PropertyAccessorElementImpl extends ExecutableElementImpl
89468959
return "$name$suffix";
89478960
}
89488961

8962+
/// Set whether this class is abstract.
8963+
void set isAbstract(bool isAbstract) {
8964+
_assertNotResynthesized(serializedExecutable);
8965+
setModifier(Modifier.ABSTRACT, isAbstract);
8966+
}
8967+
89498968
@override
89508969
bool get isGetter {
89518970
if (linkedNode != null) {

pkg/analyzer/test/generated/analysis_context_factory.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class AnalysisContextFactory {
245245
// Stream
246246
ClassElementImpl streamElement =
247247
ElementFactory.classElement2("Stream", ["T"]);
248-
streamElement.abstract = true;
248+
streamElement.isAbstract = true;
249249
streamElement.constructors = <ConstructorElement>[
250250
ElementFactory.constructorElement2(streamElement, null)
251251
];
@@ -365,7 +365,7 @@ class AnalysisContextFactory {
365365
TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3(
366366
"PI", true, false, provider.doubleType);
367367
ClassElementImpl randomElement = ElementFactory.classElement2("Random");
368-
randomElement.abstract = true;
368+
randomElement.isAbstract = true;
369369
ConstructorElementImpl randomConstructor =
370370
ElementFactory.constructorElement2(randomElement, null);
371371
randomConstructor.factory = true;

pkg/analyzer/test/src/dart/element/element_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class ClassElementImplTest {
238238
ClassElementImpl classA = ElementFactory.classElement2("A");
239239
String methodName = "m";
240240
MethodElementImpl method = ElementFactory.methodElement(methodName, null);
241-
method.abstract = true;
241+
method.isAbstract = true;
242242
classA.methods = <MethodElement>[method];
243243
(library.definingCompilationUnit as CompilationUnitElementImpl).types =
244244
<ClassElement>[classA];
@@ -260,7 +260,7 @@ class ClassElementImplTest {
260260
classA.methods = <MethodElement>[inheritedMethod];
261261
ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
262262
MethodElementImpl method = ElementFactory.methodElement(methodName, null);
263-
method.abstract = true;
263+
method.isAbstract = true;
264264
classB.methods = <MethodElement>[method];
265265
(library.definingCompilationUnit as CompilationUnitElementImpl).types =
266266
<ClassElement>[classA, classB];
@@ -298,11 +298,11 @@ class ClassElementImplTest {
298298
// }
299299
LibraryElementImpl library = _newLibrary();
300300
ClassElementImpl classA = ElementFactory.classElement2("A");
301-
classA.abstract = true;
301+
classA.isAbstract = true;
302302
String methodName = "m";
303303
MethodElementImpl inheritedMethod =
304304
ElementFactory.methodElement(methodName, null);
305-
inheritedMethod.abstract = true;
305+
inheritedMethod.isAbstract = true;
306306
classA.methods = <MethodElement>[inheritedMethod];
307307
ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
308308
MethodElement method = ElementFactory.methodElement(methodName, null);
@@ -485,7 +485,7 @@ class ClassElementImplTest {
485485
classA.methods = <MethodElement>[inheritedMethod];
486486
ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
487487
MethodElementImpl method = ElementFactory.methodElement(methodName, null);
488-
method.abstract = true;
488+
method.isAbstract = true;
489489
classB.methods = <MethodElement>[method];
490490
(library.definingCompilationUnit as CompilationUnitElementImpl).types =
491491
<ClassElement>[classA, classB];
@@ -524,11 +524,11 @@ class ClassElementImplTest {
524524
// }
525525
LibraryElementImpl library = _newLibrary();
526526
ClassElementImpl classA = ElementFactory.classElement2("A");
527-
classA.abstract = true;
527+
classA.isAbstract = true;
528528
String methodName = "m";
529529
MethodElementImpl inheritedMethod =
530530
ElementFactory.methodElement(methodName, null);
531-
inheritedMethod.abstract = true;
531+
inheritedMethod.isAbstract = true;
532532
classA.methods = <MethodElement>[inheritedMethod];
533533
ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
534534
MethodElement method = ElementFactory.methodElement(methodName, null);
@@ -558,7 +558,7 @@ class ClassElementImplTest {
558558
ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
559559
MethodElementImpl abstractMethod =
560560
ElementFactory.methodElement(methodName, null);
561-
abstractMethod.abstract = true;
561+
abstractMethod.isAbstract = true;
562562
classB.methods = <MethodElement>[abstractMethod];
563563
ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
564564
MethodElementImpl method = ElementFactory.methodElement(methodName, null);

0 commit comments

Comments
 (0)