Skip to content

Commit ec893a4

Browse files
scheglovCommit Queue
authored andcommitted
Rework ElementImpl and AugmentationElementImpl hierarchies to use XyzOrAugmentationElementMixin(s).
Add ClassAugmentationElementImpl, no any tests yet because it required parsing, AST, etc. And it is also not ready yet. Change-Id: I601141545e9bf0638771f28bb9498be9de664659 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312345 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent c4cbc70 commit ec893a4

File tree

7 files changed

+314
-218
lines changed

7 files changed

+314
-218
lines changed

pkg/analysis_server/test/protocol_server_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class EnumTest {
240240
.run(convertElementKind, exceptions: {
241241
// TODO(paulberry): do any of the exceptions below constitute bugs?
242242
engine.ElementKind.AUGMENTATION_IMPORT: ElementKind.UNKNOWN,
243+
engine.ElementKind.CLASS_AUGMENTATION: ElementKind.UNKNOWN,
243244
engine.ElementKind.DYNAMIC: ElementKind.UNKNOWN,
244245
engine.ElementKind.ERROR: ElementKind.UNKNOWN,
245246
engine.ElementKind.EXPORT: ElementKind.UNKNOWN,

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

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -961,81 +961,85 @@ class ElementKind implements Comparable<ElementKind> {
961961

962962
static const ElementKind CLASS = ElementKind('CLASS', 1, "class");
963963

964+
static const ElementKind CLASS_AUGMENTATION =
965+
ElementKind('CLASS_AUGMENTATION', 2, "class augmentation");
966+
964967
static const ElementKind COMPILATION_UNIT =
965-
ElementKind('COMPILATION_UNIT', 2, "compilation unit");
968+
ElementKind('COMPILATION_UNIT', 3, "compilation unit");
966969

967970
static const ElementKind CONSTRUCTOR =
968-
ElementKind('CONSTRUCTOR', 3, "constructor");
971+
ElementKind('CONSTRUCTOR', 4, "constructor");
969972

970-
static const ElementKind DYNAMIC = ElementKind('DYNAMIC', 4, "<dynamic>");
973+
static const ElementKind DYNAMIC = ElementKind('DYNAMIC', 5, "<dynamic>");
971974

972-
static const ElementKind ENUM = ElementKind('ENUM', 5, "enum");
975+
static const ElementKind ENUM = ElementKind('ENUM', 6, "enum");
973976

974-
static const ElementKind ERROR = ElementKind('ERROR', 6, "<error>");
977+
static const ElementKind ERROR = ElementKind('ERROR', 7, "<error>");
975978

976979
static const ElementKind EXPORT =
977-
ElementKind('EXPORT', 7, "export directive");
980+
ElementKind('EXPORT', 8, "export directive");
978981

979-
static const ElementKind EXTENSION = ElementKind('EXTENSION', 8, "extension");
982+
static const ElementKind EXTENSION = ElementKind('EXTENSION', 9, "extension");
980983

981-
static const ElementKind FIELD = ElementKind('FIELD', 9, "field");
984+
static const ElementKind FIELD = ElementKind('FIELD', 10, "field");
982985

983-
static const ElementKind FUNCTION = ElementKind('FUNCTION', 10, "function");
986+
static const ElementKind FUNCTION = ElementKind('FUNCTION', 11, "function");
984987

985988
static const ElementKind GENERIC_FUNCTION_TYPE =
986-
ElementKind('GENERIC_FUNCTION_TYPE', 11, 'generic function type');
989+
ElementKind('GENERIC_FUNCTION_TYPE', 12, 'generic function type');
987990

988-
static const ElementKind GETTER = ElementKind('GETTER', 12, "getter");
991+
static const ElementKind GETTER = ElementKind('GETTER', 13, "getter");
989992

990993
static const ElementKind IMPORT =
991-
ElementKind('IMPORT', 13, "import directive");
994+
ElementKind('IMPORT', 14, "import directive");
992995

993996
static const ElementKind INLINE_CLASS =
994-
ElementKind('INLINE_CLASS', 14, "inline class");
997+
ElementKind('INLINE_CLASS', 15, "inline class");
995998

996-
static const ElementKind LABEL = ElementKind('LABEL', 15, "label");
999+
static const ElementKind LABEL = ElementKind('LABEL', 16, "label");
9971000

998-
static const ElementKind LIBRARY = ElementKind('LIBRARY', 16, "library");
1001+
static const ElementKind LIBRARY = ElementKind('LIBRARY', 17, "library");
9991002

10001003
static const ElementKind LIBRARY_AUGMENTATION =
1001-
ElementKind('LIBRARY_AUGMENTATION', 17, "library augmentation");
1004+
ElementKind('LIBRARY_AUGMENTATION', 18, "library augmentation");
10021005

10031006
static const ElementKind LOCAL_VARIABLE =
1004-
ElementKind('LOCAL_VARIABLE', 18, "local variable");
1007+
ElementKind('LOCAL_VARIABLE', 19, "local variable");
10051008

1006-
static const ElementKind METHOD = ElementKind('METHOD', 19, "method");
1009+
static const ElementKind METHOD = ElementKind('METHOD', 20, "method");
10071010

1008-
static const ElementKind NAME = ElementKind('NAME', 20, "<name>");
1011+
static const ElementKind NAME = ElementKind('NAME', 21, "<name>");
10091012

1010-
static const ElementKind NEVER = ElementKind('NEVER', 21, "<never>");
1013+
static const ElementKind NEVER = ElementKind('NEVER', 22, "<never>");
10111014

10121015
static const ElementKind PARAMETER =
1013-
ElementKind('PARAMETER', 22, "parameter");
1016+
ElementKind('PARAMETER', 23, "parameter");
10141017

1015-
static const ElementKind PART = ElementKind('PART', 23, "part");
1018+
static const ElementKind PART = ElementKind('PART', 24, "part");
10161019

1017-
static const ElementKind PREFIX = ElementKind('PREFIX', 24, "import prefix");
1020+
static const ElementKind PREFIX = ElementKind('PREFIX', 25, "import prefix");
10181021

1019-
static const ElementKind RECORD = ElementKind('RECORD', 25, "record");
1022+
static const ElementKind RECORD = ElementKind('RECORD', 26, "record");
10201023

1021-
static const ElementKind SETTER = ElementKind('SETTER', 26, "setter");
1024+
static const ElementKind SETTER = ElementKind('SETTER', 27, "setter");
10221025

10231026
static const ElementKind TOP_LEVEL_VARIABLE =
1024-
ElementKind('TOP_LEVEL_VARIABLE', 27, "top level variable");
1027+
ElementKind('TOP_LEVEL_VARIABLE', 28, "top level variable");
10251028

10261029
static const ElementKind FUNCTION_TYPE_ALIAS =
1027-
ElementKind('FUNCTION_TYPE_ALIAS', 28, "function type alias");
1030+
ElementKind('FUNCTION_TYPE_ALIAS', 29, "function type alias");
10281031

10291032
static const ElementKind TYPE_PARAMETER =
1030-
ElementKind('TYPE_PARAMETER', 29, "type parameter");
1033+
ElementKind('TYPE_PARAMETER', 30, "type parameter");
10311034

10321035
static const ElementKind TYPE_ALIAS =
1033-
ElementKind('TYPE_ALIAS', 30, "type alias");
1036+
ElementKind('TYPE_ALIAS', 31, "type alias");
10341037

1035-
static const ElementKind UNIVERSE = ElementKind('UNIVERSE', 31, "<universe>");
1038+
static const ElementKind UNIVERSE = ElementKind('UNIVERSE', 32, "<universe>");
10361039

10371040
static const List<ElementKind> values = [
10381041
CLASS,
1042+
CLASS_AUGMENTATION,
10391043
COMPILATION_UNIT,
10401044
CONSTRUCTOR,
10411045
DYNAMIC,
@@ -1124,6 +1128,8 @@ abstract class ElementLocation {
11241128
abstract class ElementVisitor<R> {
11251129
R? visitAugmentationImportElement(AugmentationImportElement element);
11261130

1131+
R? visitClassAugmentationElement(ClassAugmentationElement element);
1132+
11271133
R? visitClassElement(ClassElement element);
11281134

11291135
R? visitCompilationUnitElement(CompilationUnitElement element);
@@ -2188,7 +2194,14 @@ abstract class MultiplyInheritedExecutableElement implements ExecutableElement {
21882194
/// Clients may not extend, implement or mix-in this class.
21892195
@experimental
21902196
abstract class NamedInstanceElement
2191-
implements NamedInstanceOrAugmentationElement, InstanceElement {}
2197+
implements NamedInstanceOrAugmentationElement, InstanceElement {
2198+
/// Create the [DartType] for this element with the given [typeArguments]
2199+
/// and [nullabilitySuffix].
2200+
DartType instantiate({
2201+
required List<DartType> typeArguments,
2202+
required NullabilitySuffix nullabilitySuffix,
2203+
});
2204+
}
21922205

21932206
/// [InstanceOrAugmentationElement] with a name.
21942207
///
@@ -2203,13 +2216,6 @@ abstract class NamedInstanceOrAugmentationElement
22032216

22042217
@override
22052218
String get name;
2206-
2207-
/// Create the [DartType] for this element with the given [typeArguments]
2208-
/// and [nullabilitySuffix].
2209-
DartType instantiate({
2210-
required List<DartType> typeArguments,
2211-
required NullabilitySuffix nullabilitySuffix,
2212-
});
22132219
}
22142220

22152221
/// An object that controls how namespaces are combined.

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ class GeneralizingElementVisitor<R> implements ElementVisitor<R> {
8888
R? visitAugmentationImportElement(AugmentationImportElement element) =>
8989
visitElement(element);
9090

91+
@override
92+
R? visitClassAugmentationElement(ClassAugmentationElement element) =>
93+
visitElement(element);
94+
9195
@override
9296
R? visitClassElement(ClassElement element) => visitElement(element);
9397

@@ -228,6 +232,12 @@ class RecursiveElementVisitor<R> implements ElementVisitor<R> {
228232
return null;
229233
}
230234

235+
@override
236+
R? visitClassAugmentationElement(ClassAugmentationElement element) {
237+
element.visitChildren(this);
238+
return null;
239+
}
240+
231241
@override
232242
R? visitClassElement(ClassElement element) {
233243
element.visitChildren(this);
@@ -398,6 +408,9 @@ class SimpleElementVisitor<R> implements ElementVisitor<R> {
398408
@override
399409
R? visitAugmentationImportElement(AugmentationImportElement element) => null;
400410

411+
@override
412+
R? visitClassAugmentationElement(ClassAugmentationElement element) => null;
413+
401414
@override
402415
R? visitClassElement(ClassElement element) => null;
403416

@@ -496,6 +509,10 @@ class ThrowingElementVisitor<R> implements ElementVisitor<R> {
496509
R? visitAugmentationImportElement(AugmentationImportElement element) =>
497510
_throw(element);
498511

512+
@override
513+
R? visitClassAugmentationElement(ClassAugmentationElement element) =>
514+
_throw(element);
515+
499516
@override
500517
R? visitClassElement(ClassElement element) => _throw(element);
501518

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ import 'package:analyzer/src/utilities/uri_cache.dart';
8787
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
8888
class AnalysisDriver implements AnalysisDriverGeneric {
8989
/// The version of data format, should be incremented on every format change.
90-
static const int DATA_VERSION = 278;
90+
static const int DATA_VERSION = 279;
9191

9292
/// The number of exception contexts allowed to write. Once this field is
9393
/// zero, we stop writing any new exception contexts in this process.

0 commit comments

Comments
 (0)