mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:07:49 +00:00
Parse documentation for class aliases, fix for /// comments.
R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com BUG= Review-Url: https://codereview.chromium.org/2990523002 .
This commit is contained in:
parent
0d49519988
commit
2d01f1f8d9
|
@ -1405,6 +1405,54 @@ class E {
|
|||
|
||||
test_class_alias_documented() async {
|
||||
var library = await checkLibrary('''
|
||||
/**
|
||||
* Docs
|
||||
*/
|
||||
class C = D with E;
|
||||
|
||||
class D {}
|
||||
class E {}
|
||||
''');
|
||||
checkElementText(library, r'''
|
||||
/**
|
||||
* Docs
|
||||
*/
|
||||
class alias C extends D with E {
|
||||
synthetic C() = D;
|
||||
}
|
||||
class D {
|
||||
}
|
||||
class E {
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_alias_documented_tripleSlash() async {
|
||||
var library = await checkLibrary('''
|
||||
/// aaa
|
||||
/// b
|
||||
/// cc
|
||||
class C = D with E;
|
||||
|
||||
class D {}
|
||||
class E {}
|
||||
''');
|
||||
checkElementText(library, r'''
|
||||
/// aaa
|
||||
/// b
|
||||
/// cc
|
||||
class alias C extends D with E {
|
||||
synthetic C() = D;
|
||||
}
|
||||
class D {
|
||||
}
|
||||
class E {
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_alias_documented_withLeadingNonDocumentation() async {
|
||||
var library = await checkLibrary('''
|
||||
// Extra comment so doc comment offset != 0
|
||||
/**
|
||||
* Docs
|
||||
|
@ -1814,6 +1862,70 @@ class C {
|
|||
''');
|
||||
}
|
||||
|
||||
test_class_documented_mix() async {
|
||||
var library = await checkLibrary('''
|
||||
/**
|
||||
* aaa
|
||||
*/
|
||||
/**
|
||||
* bbb
|
||||
*/
|
||||
class A {}
|
||||
|
||||
/**
|
||||
* aaa
|
||||
*/
|
||||
/// bbb
|
||||
/// ccc
|
||||
class B {}
|
||||
|
||||
/// aaa
|
||||
/// bbb
|
||||
/**
|
||||
* ccc
|
||||
*/
|
||||
class C {}
|
||||
|
||||
/// aaa
|
||||
/// bbb
|
||||
/**
|
||||
* ccc
|
||||
*/
|
||||
/// ddd
|
||||
class D {}
|
||||
|
||||
/**
|
||||
* aaa
|
||||
*/
|
||||
// bbb
|
||||
class E {}
|
||||
''');
|
||||
checkElementText(library, r'''
|
||||
/**
|
||||
* bbb
|
||||
*/
|
||||
class A {
|
||||
}
|
||||
/// bbb
|
||||
/// ccc
|
||||
class B {
|
||||
}
|
||||
/**
|
||||
* ccc
|
||||
*/
|
||||
class C {
|
||||
}
|
||||
/// ddd
|
||||
class D {
|
||||
}
|
||||
/**
|
||||
* aaa
|
||||
*/
|
||||
class E {
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_documented_tripleSlash() async {
|
||||
var library = await checkLibrary('''
|
||||
/// aaa
|
||||
|
|
|
@ -112,12 +112,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
}
|
||||
|
||||
@failingTest
|
||||
test_class_alias_documented() async {
|
||||
await super.test_class_alias_documented();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
@_fastaProblem
|
||||
test_class_constructor_field_formal_multiple_matching_fields() async {
|
||||
// Fasta does not generate the class.
|
||||
// main() with a fatal error is generated instead.
|
||||
|
@ -125,17 +119,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
}
|
||||
|
||||
@failingTest
|
||||
test_class_documented_tripleSlash() async {
|
||||
await super.test_class_documented_tripleSlash();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_class_documented_withLeadingNotDocumentation() async {
|
||||
await super.test_class_documented_withLeadingNotDocumentation();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
@_fastaProblem
|
||||
test_class_interfaces_unresolved() async {
|
||||
// Fasta generates additional `#errors` top-level variable.
|
||||
await super.test_class_interfaces_unresolved();
|
||||
|
|
|
@ -271,7 +271,8 @@ class KernelLibraryBuilder
|
|||
}
|
||||
|
||||
KernelTypeBuilder applyMixins(KernelTypeBuilder type,
|
||||
{List<MetadataBuilder> metadata,
|
||||
{String documentationComment,
|
||||
List<MetadataBuilder> metadata,
|
||||
bool isSyntheticMixinImplementation: false,
|
||||
String name,
|
||||
String subclassName,
|
||||
|
@ -454,6 +455,7 @@ class KernelLibraryBuilder
|
|||
checkArguments(mixin);
|
||||
|
||||
KernelNamedTypeBuilder t = applyMixin(supertype, mixin, signature,
|
||||
documentationComment: documentationComment,
|
||||
metadata: metadata,
|
||||
name: name,
|
||||
isSyntheticMixinImplementation: isSyntheticMixinImplementation,
|
||||
|
@ -476,6 +478,7 @@ class KernelLibraryBuilder
|
|||
}
|
||||
|
||||
void addNamedMixinApplication(
|
||||
String documentationComment,
|
||||
List<MetadataBuilder> metadata,
|
||||
String name,
|
||||
List<TypeVariableBuilder> typeVariables,
|
||||
|
@ -486,6 +489,7 @@ class KernelLibraryBuilder
|
|||
// Nested declaration began in `OutlineBuilder.beginNamedMixinApplication`.
|
||||
endNestedDeclaration(name).resolveTypes(typeVariables, this);
|
||||
KernelNamedTypeBuilder supertype = applyMixins(mixinApplication,
|
||||
documentationComment: documentationComment,
|
||||
metadata: metadata,
|
||||
name: name,
|
||||
typeVariables: typeVariables,
|
||||
|
|
|
@ -285,13 +285,7 @@ class OutlineBuilder extends UnhandledListener {
|
|||
Token implementsKeyword,
|
||||
Token endToken) {
|
||||
debugEvent("endClassDeclaration");
|
||||
|
||||
String documentationComment = null;
|
||||
if (beginToken.precedingComments != null) {
|
||||
documentationComment = beginToken.precedingComments.lexeme;
|
||||
// TODO(scheglov): Add support for line comments.
|
||||
}
|
||||
|
||||
String documentationComment = _getDocumentationComment(beginToken);
|
||||
List<TypeBuilder> interfaces = popList(interfacesCount);
|
||||
TypeBuilder supertype = pop();
|
||||
List<TypeVariableBuilder> typeVariables = pop();
|
||||
|
@ -464,6 +458,7 @@ class OutlineBuilder extends UnhandledListener {
|
|||
void endNamedMixinApplication(Token beginToken, Token classKeyword,
|
||||
Token equals, Token implementsKeyword, Token endToken) {
|
||||
debugEvent("endNamedMixinApplication");
|
||||
String documentationComment = _getDocumentationComment(beginToken);
|
||||
List<TypeBuilder> interfaces = popIfNotNull(implementsKeyword);
|
||||
TypeBuilder mixinApplication = pop();
|
||||
List<TypeVariableBuilder> typeVariables = pop();
|
||||
|
@ -471,8 +466,8 @@ class OutlineBuilder extends UnhandledListener {
|
|||
String name = pop();
|
||||
int modifiers = Modifier.validate(pop());
|
||||
List<MetadataBuilder> metadata = pop();
|
||||
library.addNamedMixinApplication(metadata, name, typeVariables, modifiers,
|
||||
mixinApplication, interfaces, charOffset);
|
||||
library.addNamedMixinApplication(documentationComment, metadata, name,
|
||||
typeVariables, modifiers, mixinApplication, interfaces, charOffset);
|
||||
checkEmpty(beginToken.charOffset);
|
||||
}
|
||||
|
||||
|
@ -916,6 +911,34 @@ class OutlineBuilder extends UnhandledListener {
|
|||
return removeNativeClause(identifiers, stringExpectedAfterNative);
|
||||
}
|
||||
|
||||
/// Return the documentation comment for the entity that starts at the
|
||||
/// given [token], or `null` if there is no preceding documentation comment.
|
||||
String _getDocumentationComment(Token token) {
|
||||
Token docToken = token.precedingComments;
|
||||
if (docToken == null) return null;
|
||||
bool inSlash = false;
|
||||
var buffer = new StringBuffer();
|
||||
while (docToken != null) {
|
||||
String lexeme = docToken.lexeme;
|
||||
if (lexeme.startsWith('/**')) {
|
||||
inSlash = false;
|
||||
buffer.clear();
|
||||
buffer.write(lexeme);
|
||||
} else if (lexeme.startsWith('///')) {
|
||||
if (!inSlash) {
|
||||
inSlash = true;
|
||||
buffer.clear();
|
||||
}
|
||||
if (buffer.isNotEmpty) {
|
||||
buffer.writeln();
|
||||
}
|
||||
buffer.write(lexeme);
|
||||
}
|
||||
docToken = docToken.next;
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
void debugEvent(String name) {
|
||||
// printEvent(name);
|
||||
|
|
|
@ -207,6 +207,7 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
|
|||
int charOffset);
|
||||
|
||||
void addNamedMixinApplication(
|
||||
String documentationComment,
|
||||
List<MetadataBuilder> metadata,
|
||||
String name,
|
||||
List<TypeVariableBuilder> typeVariables,
|
||||
|
|
Loading…
Reference in a new issue