mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:21:07 +00:00
Support accessing the documentation comment of an ExtensionElement
Change-Id: If433a7e795369a195a917653f303c71df84a4a0c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110000 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
parent
9c148623c5
commit
5e2a950685
|
@ -5019,6 +5019,19 @@ class ExtensionElementImpl extends ElementImpl
|
|||
@override
|
||||
String get displayName => name;
|
||||
|
||||
@override
|
||||
String get documentationComment {
|
||||
if (linkedNode != null) {
|
||||
var context = enclosingUnit.linkedContext;
|
||||
var comment = context.getDocumentationComment(linkedNode);
|
||||
return getCommentNodeRawText(comment);
|
||||
}
|
||||
if (_unlinkedExtension != null) {
|
||||
return _unlinkedExtension.documentationComment?.text;
|
||||
}
|
||||
return super.documentationComment;
|
||||
}
|
||||
|
||||
@override
|
||||
TypeParameterizedElementMixin get enclosingTypeParameterContext => null;
|
||||
|
||||
|
|
|
@ -256,6 +256,9 @@ class LinkedUnitContext {
|
|||
} else if (node is EnumDeclaration) {
|
||||
LazyEnumDeclaration.readDocumentationComment(this, node);
|
||||
return node.documentationComment;
|
||||
} else if (node is ExtensionDeclaration) {
|
||||
LazyExtensionDeclaration.readDocumentationComment(this, node);
|
||||
return node.documentationComment;
|
||||
} else if (node is FunctionDeclaration) {
|
||||
LazyFunctionDeclaration.readDocumentationComment(this, node);
|
||||
return node.documentationComment;
|
||||
|
|
|
@ -331,6 +331,26 @@ class _ElementWriter {
|
|||
}
|
||||
}
|
||||
|
||||
void writeExtensionElement(ExtensionElement e) {
|
||||
writeDocumentation(e);
|
||||
writeMetadata(e, '', '\n');
|
||||
|
||||
buffer.write('extension ');
|
||||
writeName(e);
|
||||
writeCodeRange(e);
|
||||
writeTypeParameterElements(e.typeParameters);
|
||||
if (e.extendedType != null) {
|
||||
buffer.write(' on ');
|
||||
writeType(e.extendedType);
|
||||
}
|
||||
|
||||
buffer.writeln(' {');
|
||||
e.fields.forEach(writePropertyInducingElement);
|
||||
e.accessors.forEach(writePropertyAccessorElement);
|
||||
e.methods.forEach(writeMethodElement);
|
||||
buffer.writeln('}');
|
||||
}
|
||||
|
||||
void writeFunctionElement(FunctionElement e) {
|
||||
writeDocumentation(e);
|
||||
writeMetadata(e, '', '\n');
|
||||
|
@ -1016,6 +1036,7 @@ class _ElementWriter {
|
|||
e.enums.forEach(writeClassElement);
|
||||
e.types.forEach(writeClassElement);
|
||||
e.mixins.forEach(writeClassElement);
|
||||
e.extensions.forEach(writeExtensionElement);
|
||||
e.topLevelVariables.forEach(writePropertyInducingElement);
|
||||
e.accessors.forEach(writePropertyAccessorElement);
|
||||
e.functions.forEach(writeFunctionElement);
|
||||
|
|
|
@ -136,6 +136,12 @@ class ResynthesizeAst2Test extends ResynthesizeTestStrategyTwoPhase
|
|||
return elementFactory.libraryOfUri('${source.uri}');
|
||||
}
|
||||
|
||||
@failingTest
|
||||
@override
|
||||
test_extension_documented_tripleSlash() async {
|
||||
await super.test_extension_documented_tripleSlash();
|
||||
}
|
||||
|
||||
void _addLibraryUnits(
|
||||
Source definingSource,
|
||||
CompilationUnit definingUnit,
|
||||
|
|
|
@ -208,6 +208,9 @@ mixin GetElementTestCases implements ResynthesizeTestHelpers {
|
|||
mixin ResynthesizeTestCases implements ResynthesizeTestHelpers {
|
||||
FeatureSet get disableNnbd => FeatureSet.forTesting(sdkVersion: '2.2.2');
|
||||
|
||||
FeatureSet get enableExtensionMethods =>
|
||||
FeatureSet.forTesting(additionalFeatures: [Feature.extension_methods]);
|
||||
|
||||
FeatureSet get enableNnbd =>
|
||||
FeatureSet.forTesting(additionalFeatures: [Feature.non_nullable]);
|
||||
|
||||
|
@ -5851,6 +5854,22 @@ class C<T> {
|
|||
''');
|
||||
}
|
||||
|
||||
test_extension_documented_tripleSlash() async {
|
||||
featureSet = enableExtensionMethods;
|
||||
var library = await checkLibrary('''
|
||||
/// aaa
|
||||
/// bbbb
|
||||
/// cc
|
||||
extension E on int {}''');
|
||||
checkElementText(library, r'''
|
||||
/// aaa
|
||||
/// bbbb
|
||||
/// cc
|
||||
extension E on int {
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_field_covariant() async {
|
||||
var library = await checkLibrary('''
|
||||
class C {
|
||||
|
@ -9580,21 +9599,6 @@ int y;
|
|||
''');
|
||||
}
|
||||
|
||||
test_type_inference_fieldFormal_depends_onField() async {
|
||||
var library = await checkLibrary('''
|
||||
class A<T> {
|
||||
var f = 0;
|
||||
A(this.f);
|
||||
}
|
||||
''');
|
||||
checkElementText(library, r'''
|
||||
class A<T> {
|
||||
int f;
|
||||
A(int this.f);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_type_inference_field_depends_onFieldFormal() async {
|
||||
var library = await checkLibrary('''
|
||||
class A<T> {
|
||||
|
@ -9618,6 +9622,21 @@ class B {
|
|||
''');
|
||||
}
|
||||
|
||||
test_type_inference_fieldFormal_depends_onField() async {
|
||||
var library = await checkLibrary('''
|
||||
class A<T> {
|
||||
var f = 0;
|
||||
A(this.f);
|
||||
}
|
||||
''');
|
||||
checkElementText(library, r'''
|
||||
class A<T> {
|
||||
int f;
|
||||
A(int this.f);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_type_inference_multiplyDefinedElement() async {
|
||||
addLibrarySource('/a.dart', 'class C {}');
|
||||
addLibrarySource('/b.dart', 'class C {}');
|
||||
|
|
Loading…
Reference in a new issue