Resolve enum documentation comments.

R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org//1325513004 .
This commit is contained in:
Konstantin Shcheglov 2015-08-28 14:07:13 -07:00
parent 3d1da0f320
commit 3e9645af53
4 changed files with 96 additions and 5 deletions

View file

@ -583,6 +583,18 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
return super.visitDoStatement(node);
}
@override
Object visitEnumDeclaration(EnumDeclaration node) {
ClassElement outerClass = _enclosingClass;
try {
_isInNativeClass = false;
_enclosingClass = node.element;
return super.visitEnumDeclaration(node);
} finally {
_enclosingClass = outerClass;
}
}
@override
Object visitExportDirective(ExportDirective node) {
ExportElement exportElement = node.element;

View file

@ -10757,9 +10757,21 @@ class ResolverVisitor extends ScopedVisitor {
ElementResolver.setMetadata(node.element, node);
}
//
// There is nothing else to do because everything else was resolved by the
// element builder.
// Continue the enum resolution.
//
ClassElement outerType = enclosingClass;
try {
enclosingClass = node.element;
typeAnalyzer.thisType =
enclosingClass == null ? null : enclosingClass.type;
super.visitEnumDeclaration(node);
node.accept(elementResolver);
node.accept(typeAnalyzer);
} finally {
typeAnalyzer.thisType = outerType == null ? null : outerType.type;
enclosingClass = outerType;
_enclosingClassDeclaration = null;
}
return null;
}
@ -12095,6 +12107,38 @@ abstract class ScopedVisitor extends UnifyingAstVisitor<Object> {
return null;
}
@override
Object visitEnumDeclaration(EnumDeclaration node) {
ClassElement classElement = node.element;
Scope outerScope = nameScope;
try {
if (classElement == null) {
AnalysisEngine.instance.logger.logInformation(
"Missing element for enum declaration ${node.name.name} in ${definingLibrary.source.fullName}",
new CaughtException(new AnalysisException(), null));
super.visitEnumDeclaration(node);
} else {
ClassElement outerClass = enclosingClass;
try {
enclosingClass = node.element;
nameScope = new ClassScope(nameScope, classElement);
visitEnumMembersInScope(node);
} finally {
enclosingClass = outerClass;
}
}
} finally {
nameScope = outerScope;
}
return null;
}
void visitEnumMembersInScope(EnumDeclaration node) {
safelyVisit(node.documentationComment);
node.metadata.accept(this);
node.constants.accept(this);
}
@override
Object visitForEachStatement(ForEachStatement node) {
Scope outerNameScope = nameScope;

View file

@ -10,6 +10,7 @@ import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/error.dart';
import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
import 'package:analyzer/src/generated/source_io.dart';
import 'package:unittest/unittest.dart';
import '../reflective_tests.dart';
import '../utils.dart';
@ -830,6 +831,43 @@ abstract class A {
}
}
void test_commentReference_beforeEnum() {
String code = r'''
/// This is the [Samurai] kind.
enum Samurai {
/// Use [int].
WITH_SWORD,
/// Like [WITH_SWORD], but only without one.
WITHOUT_SWORD
}''';
Source source = addSource(code);
computeLibrarySourceErrors(source);
assertNoErrors(source);
verify([source]);
CompilationUnit unit = _getResolvedLibraryUnit(source);
{
SimpleIdentifier ref = EngineTestCase.findNode(
unit, code, "Samurai]", (node) => node is SimpleIdentifier);
ClassElement refElement = ref.staticElement;
expect(refElement, isNotNull);
expect(refElement.name, 'Samurai');
}
{
SimpleIdentifier ref = EngineTestCase.findNode(
unit, code, "int]", (node) => node is SimpleIdentifier);
ClassElement refElement = ref.staticElement;
expect(refElement, isNotNull);
expect(refElement.name, 'int');
}
{
SimpleIdentifier ref = EngineTestCase.findNode(
unit, code, "WITH_SWORD]", (node) => node is SimpleIdentifier);
PropertyAccessorElement refElement = ref.staticElement;
expect(refElement, isNotNull);
expect(refElement.name, 'WITH_SWORD');
}
}
void test_commentReference_beforeFunction_blockBody() {
String code = r'''
/// [p]

View file

@ -7,9 +7,6 @@
# Runtime negative test. No static errors or warnings.
closure_call_wrong_argument_count_negative_test: skip
enum_syntax_test/02: Fail # 21649
enum_syntax_test/03: Fail # 21649
enum_syntax_test/04: Fail # 21649
enum_syntax_test/05: Fail # 21649
enum_syntax_test/06: Fail # 21649