Skip to content

Commit

Permalink
Tests for codeRange and metadata for annotations.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
scheglov committed Jul 25, 2019
1 parent 800b734 commit 86dba81
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 3 deletions.
3 changes: 0 additions & 3 deletions pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3870,9 +3870,6 @@ class ExtensionDeclarationImpl extends CompilationUnitMemberImpl
_members = new NodeListImpl<ClassMember>(this, members);
}

@override
Token get beginToken => extensionKeyword;

@override
Iterable<SyntacticEntity> get childEntities => new ChildEntities()
..add(extensionKeyword)
Expand Down
22 changes: 22 additions & 0 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5013,6 +5013,28 @@ class ExtensionElementImpl extends ElementImpl
_accessors = accessors;
}

@override
int get codeLength {
if (linkedNode != null) {
return linkedContext.getCodeLength(linkedNode);
}
if (_unlinkedExtension != null) {
return _unlinkedExtension.codeRange?.length;
}
return super.codeLength;
}

@override
int get codeOffset {
if (linkedNode != null) {
return linkedContext.getCodeOffset(linkedNode);
}
if (_unlinkedExtension != null) {
return _unlinkedExtension.codeRange?.offset;
}
return super.codeOffset;
}

@override
String get displayName => name;

Expand Down
4 changes: 4 additions & 0 deletions pkg/analyzer/lib/src/summary2/linked_unit_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class LinkedUnitContext {
return LazyConstructorDeclaration.getCodeLength(this, node);
} else if (node is EnumDeclaration) {
return LazyEnumDeclaration.getCodeLength(this, node);
} else if (node is ExtensionDeclaration) {
return LazyExtensionDeclaration.getCodeLength(this, node);
} else if (node is FormalParameter) {
return LazyFormalParameter.getCodeLength(this, node);
} else if (node is FunctionDeclaration) {
Expand Down Expand Up @@ -181,6 +183,8 @@ class LinkedUnitContext {
return LazyConstructorDeclaration.getCodeOffset(this, node);
} else if (node is EnumDeclaration) {
return LazyEnumDeclaration.getCodeOffset(this, node);
} else if (node is ExtensionDeclaration) {
return LazyExtensionDeclaration.getCodeOffset(this, node);
} else if (node is FormalParameter) {
return LazyFormalParameter.getCodeOffset(this, node);
} else if (node is FunctionDeclaration) {
Expand Down
12 changes: 12 additions & 0 deletions pkg/analyzer/test/src/summary/resynthesize_ast_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class ApplyCheckElementTextReplacements {
@reflectiveTest
class ResynthesizeAstStrongTest extends ResynthesizeTestStrategyTwoPhase
with ResynthesizeTestCases, GetElementTestCases, ResynthesizeTestHelpers {
@override
@failingTest
test_codeRange_extensions() async {
await super.test_codeRange_extensions();
}

@failingTest // See dartbug.com/32290
test_const_constructor_inferred_args() =>
super.test_const_constructor_inferred_args();
Expand Down Expand Up @@ -58,6 +64,12 @@ class ResynthesizeAstStrongTest extends ResynthesizeTestStrategyTwoPhase
await super.test_infer_generic_typedef_complex();
}

@override
@failingTest
test_metadata_extensionDeclaration() async {
await super.test_metadata_extensionDeclaration();
}

@override
@failingTest
test_syntheticFunctionType_inGenericClass() async {
Expand Down
83 changes: 83 additions & 0 deletions pkg/analyzer/test/src/summary/resynthesize_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,68 @@ class C/*codeOffset=0, codeLength=462*/ {
withConstElements: false);
}

test_codeRange_extensions() async {
featureSet = enableExtensionMethods;
var library = await checkLibrary('''
class A {}
extension Raw on A {}
/// Comment 1.
/// Comment 2.
extension HasDocComment on A {}
@Object()
extension HasAnnotation on A {}
@Object()
/// Comment 1.
/// Comment 2.
extension AnnotationThenComment on A {}
/// Comment 1.
/// Comment 2.
@Object()
extension CommentThenAnnotation on A {}
/// Comment 1.
@Object()
/// Comment 2.
extension CommentAroundAnnotation on A {}
''');
checkElementText(
library,
r'''
class A/*codeOffset=0, codeLength=10*/ {
}
extension Raw/*codeOffset=12, codeLength=21*/ on A {
}
/// Comment 1.
/// Comment 2.
extension HasDocComment/*codeOffset=35, codeLength=61*/ on A {
}
@Object()
extension HasAnnotation/*codeOffset=98, codeLength=41*/ on A {
}
/// Comment 1.
/// Comment 2.
@Object()
extension AnnotationThenComment/*codeOffset=141, codeLength=79*/ on A {
}
/// Comment 1.
/// Comment 2.
@Object()
extension CommentThenAnnotation/*codeOffset=222, codeLength=79*/ on A {
}
/// Comment 2.
@Object()
extension CommentAroundAnnotation/*codeOffset=318, codeLength=66*/ on A {
}
''',
withCodeRanges: true,
withConstElements: false);
}

test_codeRange_field() async {
var library = await checkLibrary('''
class C {
Expand Down Expand Up @@ -8263,6 +8325,27 @@ const dynamic a = null;
''');
}

test_metadata_extensionDeclaration() async {
featureSet = enableExtensionMethods;
var library = await checkLibrary(r'''
const a = null;
class A {}
@a
@Object()
extension E on A {}''');
checkElementText(library, r'''
class A {
}
@
a/*location: test.dart;a?*/
@
Object/*location: dart:core;Object*/()
extension E on A {
}
const dynamic a = null;
''');
}

test_metadata_fieldDeclaration() async {
var library = await checkLibrary('const a = null; class C { @a int x; }');
checkElementText(library, r'''
Expand Down

0 comments on commit 86dba81

Please sign in to comment.