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

Commit 86dba81

Browse files
committed
Tests for codeRange and metadata for annotations.
Implementation for summary2. [email protected], [email protected] Change-Id: I7d092688a35702e12509a4450cbda8f5069abcef Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110583 Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 800b734 commit 86dba81

File tree

5 files changed

+121
-3
lines changed

5 files changed

+121
-3
lines changed

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3870,9 +3870,6 @@ class ExtensionDeclarationImpl extends CompilationUnitMemberImpl
38703870
_members = new NodeListImpl<ClassMember>(this, members);
38713871
}
38723872

3873-
@override
3874-
Token get beginToken => extensionKeyword;
3875-
38763873
@override
38773874
Iterable<SyntacticEntity> get childEntities => new ChildEntities()
38783875
..add(extensionKeyword)

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5013,6 +5013,28 @@ class ExtensionElementImpl extends ElementImpl
50135013
_accessors = accessors;
50145014
}
50155015

5016+
@override
5017+
int get codeLength {
5018+
if (linkedNode != null) {
5019+
return linkedContext.getCodeLength(linkedNode);
5020+
}
5021+
if (_unlinkedExtension != null) {
5022+
return _unlinkedExtension.codeRange?.length;
5023+
}
5024+
return super.codeLength;
5025+
}
5026+
5027+
@override
5028+
int get codeOffset {
5029+
if (linkedNode != null) {
5030+
return linkedContext.getCodeOffset(linkedNode);
5031+
}
5032+
if (_unlinkedExtension != null) {
5033+
return _unlinkedExtension.codeRange?.offset;
5034+
}
5035+
return super.codeOffset;
5036+
}
5037+
50165038
@override
50175039
String get displayName => name;
50185040

pkg/analyzer/lib/src/summary2/linked_unit_context.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ class LinkedUnitContext {
150150
return LazyConstructorDeclaration.getCodeLength(this, node);
151151
} else if (node is EnumDeclaration) {
152152
return LazyEnumDeclaration.getCodeLength(this, node);
153+
} else if (node is ExtensionDeclaration) {
154+
return LazyExtensionDeclaration.getCodeLength(this, node);
153155
} else if (node is FormalParameter) {
154156
return LazyFormalParameter.getCodeLength(this, node);
155157
} else if (node is FunctionDeclaration) {
@@ -181,6 +183,8 @@ class LinkedUnitContext {
181183
return LazyConstructorDeclaration.getCodeOffset(this, node);
182184
} else if (node is EnumDeclaration) {
183185
return LazyEnumDeclaration.getCodeOffset(this, node);
186+
} else if (node is ExtensionDeclaration) {
187+
return LazyExtensionDeclaration.getCodeOffset(this, node);
184188
} else if (node is FormalParameter) {
185189
return LazyFormalParameter.getCodeOffset(this, node);
186190
} else if (node is FunctionDeclaration) {

pkg/analyzer/test/src/summary/resynthesize_ast_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ class ApplyCheckElementTextReplacements {
2727
@reflectiveTest
2828
class ResynthesizeAstStrongTest extends ResynthesizeTestStrategyTwoPhase
2929
with ResynthesizeTestCases, GetElementTestCases, ResynthesizeTestHelpers {
30+
@override
31+
@failingTest
32+
test_codeRange_extensions() async {
33+
await super.test_codeRange_extensions();
34+
}
35+
3036
@failingTest // See dartbug.com/32290
3137
test_const_constructor_inferred_args() =>
3238
super.test_const_constructor_inferred_args();
@@ -58,6 +64,12 @@ class ResynthesizeAstStrongTest extends ResynthesizeTestStrategyTwoPhase
5864
await super.test_infer_generic_typedef_complex();
5965
}
6066

67+
@override
68+
@failingTest
69+
test_metadata_extensionDeclaration() async {
70+
await super.test_metadata_extensionDeclaration();
71+
}
72+
6173
@override
6274
@failingTest
6375
test_syntheticFunctionType_inGenericClass() async {

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,68 @@ class C/*codeOffset=0, codeLength=462*/ {
20222022
withConstElements: false);
20232023
}
20242024

2025+
test_codeRange_extensions() async {
2026+
featureSet = enableExtensionMethods;
2027+
var library = await checkLibrary('''
2028+
class A {}
2029+
2030+
extension Raw on A {}
2031+
2032+
/// Comment 1.
2033+
/// Comment 2.
2034+
extension HasDocComment on A {}
2035+
2036+
@Object()
2037+
extension HasAnnotation on A {}
2038+
2039+
@Object()
2040+
/// Comment 1.
2041+
/// Comment 2.
2042+
extension AnnotationThenComment on A {}
2043+
2044+
/// Comment 1.
2045+
/// Comment 2.
2046+
@Object()
2047+
extension CommentThenAnnotation on A {}
2048+
2049+
/// Comment 1.
2050+
@Object()
2051+
/// Comment 2.
2052+
extension CommentAroundAnnotation on A {}
2053+
''');
2054+
checkElementText(
2055+
library,
2056+
r'''
2057+
class A/*codeOffset=0, codeLength=10*/ {
2058+
}
2059+
extension Raw/*codeOffset=12, codeLength=21*/ on A {
2060+
}
2061+
/// Comment 1.
2062+
/// Comment 2.
2063+
extension HasDocComment/*codeOffset=35, codeLength=61*/ on A {
2064+
}
2065+
@Object()
2066+
extension HasAnnotation/*codeOffset=98, codeLength=41*/ on A {
2067+
}
2068+
/// Comment 1.
2069+
/// Comment 2.
2070+
@Object()
2071+
extension AnnotationThenComment/*codeOffset=141, codeLength=79*/ on A {
2072+
}
2073+
/// Comment 1.
2074+
/// Comment 2.
2075+
@Object()
2076+
extension CommentThenAnnotation/*codeOffset=222, codeLength=79*/ on A {
2077+
}
2078+
/// Comment 2.
2079+
@Object()
2080+
extension CommentAroundAnnotation/*codeOffset=318, codeLength=66*/ on A {
2081+
}
2082+
''',
2083+
withCodeRanges: true,
2084+
withConstElements: false);
2085+
}
2086+
20252087
test_codeRange_field() async {
20262088
var library = await checkLibrary('''
20272089
class C {
@@ -8263,6 +8325,27 @@ const dynamic a = null;
82638325
''');
82648326
}
82658327

8328+
test_metadata_extensionDeclaration() async {
8329+
featureSet = enableExtensionMethods;
8330+
var library = await checkLibrary(r'''
8331+
const a = null;
8332+
class A {}
8333+
@a
8334+
@Object()
8335+
extension E on A {}''');
8336+
checkElementText(library, r'''
8337+
class A {
8338+
}
8339+
@
8340+
a/*location: test.dart;a?*/
8341+
@
8342+
Object/*location: dart:core;Object*/()
8343+
extension E on A {
8344+
}
8345+
const dynamic a = null;
8346+
''');
8347+
}
8348+
82668349
test_metadata_fieldDeclaration() async {
82678350
var library = await checkLibrary('const a = null; class C { @a int x; }');
82688351
checkElementText(library, r'''

0 commit comments

Comments
 (0)