Skip to content

Commit 9af7695

Browse files
scheglovcommit-bot@chromium.org
authored and
commit-bot@chromium.org
committed
Issue 34387. Don't report an error when a static member is referenced in a documentation comment.
Also consolidate comment reference resolution tests. R=brianwilkerson@google.com, paulberry@google.com Bug: #34387 Change-Id: I3c75c1679c7a880705e6aff9d2f5477eb81a7f11 Reviewed-on: https://dart-review.googlesource.com/c/83223 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Paul Berry <paulberry@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent 8b87e73 commit 9af7695

File tree

6 files changed

+274
-265
lines changed

6 files changed

+274
-265
lines changed

pkg/analyzer/lib/src/generated/error_verifier.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -6053,7 +6053,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
60536053
return identical(parent.constructorName, identifier);
60546054
}
60556055
if (parent is CommentReference) {
6056-
return parent.newKeyword != null;
6056+
return true;
60576057
}
60586058
if (parent is ConstructorName) {
60596059
return identical(parent.name, identifier);

pkg/analyzer/test/generated/non_error_resolver_test.dart

-228
Original file line numberDiff line numberDiff line change
@@ -972,220 +972,6 @@ class E {}''');
972972
expect(classC.documentationComment, isNotNull);
973973
}
974974

975-
test_commentReference_beforeConstructor() async {
976-
String code = r'''
977-
abstract class A {
978-
/// [p]
979-
A(int p) {}
980-
}''';
981-
Source source = addSource(code);
982-
TestAnalysisResult analysisResult = await computeAnalysisResult(source);
983-
assertNoErrors(source);
984-
verify([source]);
985-
CompilationUnit unit = analysisResult.unit;
986-
{
987-
SimpleIdentifier ref =
988-
EngineTestCase.findSimpleIdentifier(unit, code, "p]");
989-
expect(ref.staticElement, new TypeMatcher<ParameterElement>());
990-
}
991-
}
992-
993-
test_commentReference_beforeEnum() async {
994-
String code = r'''
995-
/// This is the [Samurai] kind.
996-
enum Samurai {
997-
/// Use [int].
998-
WITH_SWORD,
999-
/// Like [WITH_SWORD], but only without one.
1000-
WITHOUT_SWORD
1001-
}''';
1002-
Source source = addSource(code);
1003-
TestAnalysisResult analysisResult = await computeAnalysisResult(source);
1004-
assertNoErrors(source);
1005-
verify([source]);
1006-
CompilationUnit unit = analysisResult.unit;
1007-
{
1008-
SimpleIdentifier ref =
1009-
EngineTestCase.findSimpleIdentifier(unit, code, 'Samurai]');
1010-
ClassElement refElement = ref.staticElement;
1011-
expect(refElement, isNotNull);
1012-
expect(refElement.name, 'Samurai');
1013-
}
1014-
{
1015-
SimpleIdentifier ref =
1016-
EngineTestCase.findSimpleIdentifier(unit, code, 'int]');
1017-
ClassElement refElement = ref.staticElement;
1018-
expect(refElement, isNotNull);
1019-
expect(refElement.name, 'int');
1020-
}
1021-
{
1022-
SimpleIdentifier ref =
1023-
EngineTestCase.findSimpleIdentifier(unit, code, 'WITH_SWORD]');
1024-
PropertyAccessorElement refElement = ref.staticElement;
1025-
expect(refElement, isNotNull);
1026-
expect(refElement.name, 'WITH_SWORD');
1027-
}
1028-
}
1029-
1030-
test_commentReference_beforeFunction_blockBody() async {
1031-
String code = r'''
1032-
/// [p]
1033-
foo(int p) {
1034-
}''';
1035-
Source source = addSource(code);
1036-
TestAnalysisResult analysisResult = await computeAnalysisResult(source);
1037-
assertNoErrors(source);
1038-
verify([source]);
1039-
CompilationUnit unit = analysisResult.unit;
1040-
SimpleIdentifier ref =
1041-
EngineTestCase.findSimpleIdentifier(unit, code, 'p]');
1042-
expect(ref.staticElement, new TypeMatcher<ParameterElement>());
1043-
}
1044-
1045-
test_commentReference_beforeFunction_expressionBody() async {
1046-
String code = r'''
1047-
/// [p]
1048-
foo(int p) => null;''';
1049-
Source source = addSource(code);
1050-
TestAnalysisResult analysisResult = await computeAnalysisResult(source);
1051-
assertNoErrors(source);
1052-
verify([source]);
1053-
CompilationUnit unit = analysisResult.unit;
1054-
SimpleIdentifier ref =
1055-
EngineTestCase.findSimpleIdentifier(unit, code, 'p]');
1056-
expect(ref.staticElement, new TypeMatcher<ParameterElement>());
1057-
}
1058-
1059-
test_commentReference_beforeFunctionTypeAlias() async {
1060-
String code = r'''
1061-
/// [p]
1062-
typedef Foo(int p);
1063-
''';
1064-
Source source = addSource(code);
1065-
TestAnalysisResult analysisResult = await computeAnalysisResult(source);
1066-
assertNoErrors(source);
1067-
verify([source]);
1068-
CompilationUnit unit = analysisResult.unit;
1069-
SimpleIdentifier ref =
1070-
EngineTestCase.findSimpleIdentifier(unit, code, 'p]');
1071-
expect(ref.staticElement, new TypeMatcher<ParameterElement>());
1072-
}
1073-
1074-
test_commentReference_beforeGenericTypeAlias() async {
1075-
String code = r'''
1076-
/// Can resolve [T], [S], and [p].
1077-
typedef Foo<T> = Function<S>(int p);
1078-
''';
1079-
Source source = addSource(code);
1080-
TestAnalysisResult analysisResult = await computeAnalysisResult(source);
1081-
assertNoErrors(source);
1082-
verify([source]);
1083-
CompilationUnit unit = analysisResult.unit;
1084-
1085-
Element getElement(String search) {
1086-
return EngineTestCase.findSimpleIdentifier(unit, code, search)
1087-
.staticElement;
1088-
}
1089-
1090-
expect(getElement('T]'), new TypeMatcher<TypeParameterElement>());
1091-
expect(getElement('S]'), new TypeMatcher<TypeParameterElement>());
1092-
expect(getElement('p]'), new TypeMatcher<ParameterElement>());
1093-
}
1094-
1095-
test_commentReference_beforeGetter() async {
1096-
String code = r'''
1097-
abstract class A {
1098-
/// [int]
1099-
get g => null;
1100-
}''';
1101-
Source source = addSource(code);
1102-
TestAnalysisResult analysisResult = await computeAnalysisResult(source);
1103-
assertNoErrors(source);
1104-
verify([source]);
1105-
CompilationUnit unit = analysisResult.unit;
1106-
{
1107-
SimpleIdentifier ref =
1108-
EngineTestCase.findSimpleIdentifier(unit, code, 'int]');
1109-
expect(ref.staticElement, isNotNull);
1110-
}
1111-
}
1112-
1113-
test_commentReference_beforeMethod() async {
1114-
String code = r'''
1115-
abstract class A {
1116-
/// [p1]
1117-
ma(int p1) {}
1118-
/// [p2]
1119-
mb(int p2);
1120-
/// [p3] and [p4]
1121-
mc(int p3, p4());
1122-
/// [p5]
1123-
md(int p5, {int p6});
1124-
}''';
1125-
Source source = addSource(code);
1126-
TestAnalysisResult analysisResult = await computeAnalysisResult(source);
1127-
assertNoErrors(source);
1128-
verify([source]);
1129-
CompilationUnit unit = analysisResult.unit;
1130-
assertIsParameter(String search) {
1131-
SimpleIdentifier ref =
1132-
EngineTestCase.findSimpleIdentifier(unit, code, search);
1133-
expect(ref.staticElement, new TypeMatcher<ParameterElement>());
1134-
}
1135-
1136-
assertIsParameter('p1');
1137-
assertIsParameter('p2');
1138-
assertIsParameter('p3');
1139-
assertIsParameter('p4');
1140-
assertIsParameter('p5');
1141-
assertIsParameter('p6');
1142-
}
1143-
1144-
test_commentReference_class() async {
1145-
String code = r'''
1146-
/// [foo]
1147-
class A {
1148-
foo() {}
1149-
}''';
1150-
Source source = addSource(code);
1151-
TestAnalysisResult analysisResult = await computeAnalysisResult(source);
1152-
assertNoErrors(source);
1153-
verify([source]);
1154-
CompilationUnit unit = analysisResult.unit;
1155-
SimpleIdentifier ref =
1156-
EngineTestCase.findSimpleIdentifier(unit, code, 'foo]');
1157-
expect(ref.staticElement, new TypeMatcher<MethodElement>());
1158-
}
1159-
1160-
test_commentReference_setter() async {
1161-
String code = r'''
1162-
class A {
1163-
/// [x] in A
1164-
mA() {}
1165-
set x(value) {}
1166-
}
1167-
class B extends A {
1168-
/// [x] in B
1169-
mB() {}
1170-
}
1171-
''';
1172-
Source source = addSource(code);
1173-
TestAnalysisResult analysisResult = await computeAnalysisResult(source);
1174-
assertNoErrors(source);
1175-
verify([source]);
1176-
CompilationUnit unit = analysisResult.unit;
1177-
{
1178-
SimpleIdentifier ref =
1179-
EngineTestCase.findSimpleIdentifier(unit, code, "x] in A");
1180-
expect(ref.staticElement, new TypeMatcher<PropertyAccessorElement>());
1181-
}
1182-
{
1183-
SimpleIdentifier ref =
1184-
EngineTestCase.findSimpleIdentifier(unit, code, 'x] in B');
1185-
expect(ref.staticElement, new TypeMatcher<PropertyAccessorElement>());
1186-
}
1187-
}
1188-
1189975
test_concreteClassWithAbstractMember() async {
1190976
Source source = addSource(r'''
1191977
abstract class A {
@@ -5947,20 +5733,6 @@ class B extends A {
59475733
verify([source]);
59485734
}
59495735

5950-
test_unqualifiedReferenceToNonLocalStaticMember_fromComment_new() async {
5951-
Source source = addSource(r'''
5952-
class A {
5953-
A() {}
5954-
A.named() {}
5955-
}
5956-
/// [new A] or [new A.named]
5957-
main() {
5958-
}''');
5959-
await computeAnalysisResult(source);
5960-
assertNoErrors(source);
5961-
verify([source]);
5962-
}
5963-
59645736
test_unusedShownName_unresolved() async {
59655737
Source source = addSource(r'''
59665738
import 'dart:math' show max, FooBar;

pkg/analyzer/test/generated/simple_resolver_test.dart

-36
Original file line numberDiff line numberDiff line change
@@ -376,42 +376,6 @@ class C {}''');
376376
verify([source]);
377377
}
378378

379-
test_commentReference_class() async {
380-
Source source = addSource(r'''
381-
f() {}
382-
/** [A] [new A] [A.n] [new A.n] [m] [f] */
383-
class A {
384-
A() {}
385-
A.n() {}
386-
m() {}
387-
}''');
388-
await computeAnalysisResult(source);
389-
assertNoErrors(source);
390-
verify([source]);
391-
}
392-
393-
test_commentReference_parameter() async {
394-
Source source = addSource(r'''
395-
class A {
396-
A() {}
397-
A.n() {}
398-
/** [e] [f] */
399-
m(e, f()) {}
400-
}''');
401-
await computeAnalysisResult(source);
402-
assertNoErrors(source);
403-
verify([source]);
404-
}
405-
406-
test_commentReference_singleLine() async {
407-
Source source = addSource(r'''
408-
/// [A]
409-
class A {}''');
410-
await computeAnalysisResult(source);
411-
assertNoErrors(source);
412-
verify([source]);
413-
}
414-
415379
test_continueTarget_labeled() async {
416380
// Verify that the target of the label is correctly found and is recorded
417381
// as the unlabeled portion of the statement.

0 commit comments

Comments
 (0)