CQ. ErrorReporter, use atElement() instead of reportErrorForElement()
Change-Id: Ife5f6d04ee7c15e7703db3ad81eb7707c7f00ceb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352053
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/error/listener.dart b/pkg/analyzer/lib/error/listener.dart
index 5603f13..68caab2 100644
--- a/pkg/analyzer/lib/error/listener.dart
+++ b/pkg/analyzer/lib/error/listener.dart
@@ -66,6 +66,26 @@
Source get source => _source;
/// Report an error with the given [errorCode] and [arguments].
+ /// The [element] is used to compute the location of the error.
+ void atElement(
+ Element element,
+ ErrorCode errorCode, {
+ List<Object>? arguments,
+ List<DiagnosticMessage>? contextMessages,
+ Object? data,
+ }) {
+ var nonSynthetic = element.nonSynthetic;
+ atOffset(
+ errorCode: errorCode,
+ offset: nonSynthetic.nameOffset,
+ length: nonSynthetic.nameLength,
+ arguments: arguments,
+ contextMessages: contextMessages,
+ data: data,
+ );
+ }
+
+ /// Report an error with the given [errorCode] and [arguments].
/// The [node] is used to compute the location of the error.
void atNode(
AstNode node,
@@ -140,11 +160,15 @@
/// Report an error with the given [errorCode] and [arguments]. The [element]
/// is used to compute the location of the error.
+ @Deprecated('Use atElement() instead')
void reportErrorForElement(ErrorCode errorCode, Element element,
[List<Object>? arguments, List<DiagnosticMessage>? messages]) {
- var nonSynthetic = element.nonSynthetic;
- reportErrorForOffset(errorCode, nonSynthetic.nameOffset,
- nonSynthetic.nameLength, arguments, messages);
+ atElement(
+ element,
+ errorCode,
+ arguments: arguments,
+ contextMessages: messages,
+ );
}
/// Report a diagnostic with the given [code] and [arguments]. The
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index 6ba655b..61cb894 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -413,8 +413,10 @@
// TODO(paulberry): It would be really nice if we could extract enough
// information from the 'cycle' argument to provide the user with a
// description of the cycle.
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, constant, []);
+ errorReporter.atElement(
+ constant,
+ CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT,
+ );
(constant as VariableElementImpl).evaluationResult =
InvalidConstant.forElement(
constant, CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT);
diff --git a/pkg/analyzer/lib/src/dart/resolver/shared_type_analyzer.dart b/pkg/analyzer/lib/src/dart/resolver/shared_type_analyzer.dart
index 3c5546b..f66e62f 100644
--- a/pkg/analyzer/lib/src/dart/resolver/shared_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/shared_type_analyzer.dart
@@ -109,10 +109,10 @@
required PromotableElement variable,
required PromotableElement component,
}) {
- _errorReporter.reportErrorForElement(
- CompileTimeErrorCode.INCONSISTENT_PATTERN_VARIABLE_LOGICAL_OR,
+ _errorReporter.atElement(
component,
- [variable.name],
+ CompileTimeErrorCode.INCONSISTENT_PATTERN_VARIABLE_LOGICAL_OR,
+ arguments: [variable.name],
);
}
diff --git a/pkg/analyzer/lib/src/error/base_or_final_type_verifier.dart b/pkg/analyzer/lib/src/error/base_or_final_type_verifier.dart
index 48a3aa1..047ac425 100644
--- a/pkg/analyzer/lib/src/error/base_or_final_type_verifier.dart
+++ b/pkg/analyzer/lib/src/error/base_or_final_type_verifier.dart
@@ -241,22 +241,30 @@
? CompileTimeErrorCode.MIXIN_SUBTYPE_OF_FINAL_IS_NOT_BASE
: CompileTimeErrorCode
.SUBTYPE_OF_FINAL_IS_NOT_BASE_FINAL_OR_SEALED;
- _errorReporter.reportErrorForElement(
- errorCode,
- element,
- [element.displayName, baseOrFinalSuperElement.displayName],
- superElement.isSealed ? contextMessages : null);
+ _errorReporter.atElement(
+ element,
+ errorCode,
+ arguments: [
+ element.displayName,
+ baseOrFinalSuperElement.displayName,
+ ],
+ contextMessages: superElement.isSealed ? contextMessages : null,
+ );
return true;
} else if (baseOrFinalSuperElement.isBase) {
final errorCode = element is MixinElement
? CompileTimeErrorCode.MIXIN_SUBTYPE_OF_BASE_IS_NOT_BASE
: CompileTimeErrorCode
.SUBTYPE_OF_BASE_IS_NOT_BASE_FINAL_OR_SEALED;
- _errorReporter.reportErrorForElement(
- errorCode,
- element,
- [element.displayName, baseOrFinalSuperElement.displayName],
- superElement.isSealed ? contextMessages : null);
+ _errorReporter.atElement(
+ element,
+ errorCode,
+ arguments: [
+ element.displayName,
+ baseOrFinalSuperElement.displayName,
+ ],
+ contextMessages: superElement.isSealed ? contextMessages : null,
+ );
return true;
}
}
diff --git a/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart b/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart
index 49aa727..3caf731 100644
--- a/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart
+++ b/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart
@@ -137,19 +137,19 @@
if (accessor.isStatic) {
var instance = _getInterfaceMember(enumElement, baseName);
if (instance != null && baseName != 'values') {
- _errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE,
+ _errorReporter.atElement(
accessor,
- [enumName, baseName, enumName],
+ CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE,
+ arguments: [enumName, baseName, enumName],
);
}
} else {
var inherited = _getInheritedMember(enumElement, baseName);
if (inherited is MethodElement) {
- _errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD,
+ _errorReporter.atElement(
accessor,
- [
+ CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD,
+ arguments: [
enumElement.displayName,
baseName,
inherited.enclosingElement.displayName,
@@ -164,19 +164,19 @@
if (method.isStatic) {
var instance = _getInterfaceMember(enumElement, baseName);
if (instance != null) {
- _errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE,
+ _errorReporter.atElement(
method,
- [enumName, baseName, enumName],
+ CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE,
+ arguments: [enumName, baseName, enumName],
);
}
} else {
var inherited = _getInheritedMember(enumElement, baseName);
if (inherited is PropertyAccessorElement) {
- _errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD,
+ _errorReporter.atElement(
method,
- [
+ CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD,
+ arguments: [
enumElement.displayName,
baseName,
inherited.enclosingElement.displayName,
@@ -514,12 +514,16 @@
errorCode =
CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_SETTER;
}
- _errorReporter.reportErrorForElement(errorCode, constructor, [name]);
- } else if (staticMember is MethodElement) {
- _errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_METHOD,
+ _errorReporter.atElement(
constructor,
- [name],
+ errorCode,
+ arguments: [name],
+ );
+ } else if (staticMember is MethodElement) {
+ _errorReporter.atElement(
+ constructor,
+ CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_METHOD,
+ arguments: [name],
);
}
}
diff --git a/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart b/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart
index 8d9aa1e..d5da2fe 100644
--- a/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart
+++ b/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart
@@ -74,10 +74,10 @@
setterName = '$setterClassName.$setterName';
}
- _errorReporter.reportErrorForElement(
- CompileTimeErrorCode.GETTER_NOT_SUBTYPE_SETTER_TYPES,
+ _errorReporter.atElement(
errorElement,
- [getterName, getterType, setterType, setterName],
+ CompileTimeErrorCode.GETTER_NOT_SUBTYPE_SETTER_TYPES,
+ arguments: [getterName, getterType, setterType, setterName],
);
}
}
@@ -102,10 +102,10 @@
if (setterType != null) {
if (!_typeSystem.isSubtypeOf(getterType, setterType)) {
var name = getter.name;
- _errorReporter.reportErrorForElement(
- CompileTimeErrorCode.GETTER_NOT_SUBTYPE_SETTER_TYPES,
+ _errorReporter.atElement(
getter,
- [name, getterType, setterType, name],
+ CompileTimeErrorCode.GETTER_NOT_SUBTYPE_SETTER_TYPES,
+ arguments: [name, getterType, setterType, name],
);
}
}
diff --git a/pkg/analyzer/lib/src/error/inheritance_override.dart b/pkg/analyzer/lib/src/error/inheritance_override.dart
index b1aa5ab..a802a40 100644
--- a/pkg/analyzer/lib/src/error/inheritance_override.dart
+++ b/pkg/analyzer/lib/src/error/inheritance_override.dart
@@ -529,18 +529,22 @@
buffer.write(separator);
}
buffer.write(element.displayName);
- reporter.reportErrorForElement(
- CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
- classElement,
- [className, buffer.toString()]);
+ reporter.atElement(
+ classElement,
+ CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
+ arguments: [className, buffer.toString()],
+ );
return true;
} else {
// RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS or
// RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or
// RECURSIVE_INTERFACE_INHERITANCE_ON or
// RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH
- reporter.reportErrorForElement(
- _getRecursiveErrorCode(element), classElement, [className]);
+ reporter.atElement(
+ classElement,
+ _getRecursiveErrorCode(element),
+ arguments: [className],
+ );
return true;
}
}
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 376806d..1b19f5a 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -2015,12 +2015,15 @@
if (method.isStatic) {
void reportStaticConflict(ExecutableElement inherited) {
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, method, [
- enclosingClass.displayName,
- name,
- inherited.enclosingElement.displayName,
- ]);
+ errorReporter.atElement(
+ method,
+ CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE,
+ arguments: [
+ enclosingClass.displayName,
+ name,
+ inherited.enclosingElement.displayName,
+ ],
+ );
}
if (getter != null) {
@@ -2040,12 +2043,15 @@
}
void reportFieldConflict(PropertyAccessorElement inherited) {
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD, method, [
- enclosingClass.displayName,
- name,
- inherited.enclosingElement.displayName
- ]);
+ errorReporter.atElement(
+ method,
+ CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD,
+ arguments: [
+ enclosingClass.displayName,
+ name,
+ inherited.enclosingElement.displayName
+ ],
+ );
}
if (getter is PropertyAccessorElement) {
@@ -2070,24 +2076,30 @@
enclosingClass, Name(libraryUri, '$name='));
if (accessor.isStatic && inherited != null) {
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, accessor, [
- enclosingClass.displayName,
- name,
- inherited.enclosingElement.displayName,
- ]);
+ errorReporter.atElement(
+ accessor,
+ CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE,
+ arguments: [
+ enclosingClass.displayName,
+ name,
+ inherited.enclosingElement.displayName,
+ ],
+ );
conflictingDeclaredNames.add(name);
} else if (inherited is MethodElement) {
// Extension type accessors preclude inherited accessors/methods.
if (enclosingClass is ExtensionTypeElement) {
continue;
}
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD, accessor, [
- enclosingClass.displayName,
- name,
- inherited.enclosingElement.displayName
- ]);
+ errorReporter.atElement(
+ accessor,
+ CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD,
+ arguments: [
+ enclosingClass.displayName,
+ name,
+ inherited.enclosingElement.displayName
+ ],
+ );
conflictingDeclaredNames.add(name);
}
}
@@ -2104,15 +2116,15 @@
final setterName = methodName.forSetter;
final setter = inherited[setterName];
if (setter is PropertyAccessorElement) {
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_INHERITED_METHOD_AND_SETTER,
+ errorReporter.atElement(
enclosingClass,
- [
+ CompileTimeErrorCode.CONFLICTING_INHERITED_METHOD_AND_SETTER,
+ arguments: [
enclosingClass.kind.displayName,
enclosingClass.displayName,
methodName.name,
],
- [
+ contextMessages: [
DiagnosticMessageImpl(
filePath: method.source.fullName,
message: formatList(
@@ -2156,7 +2168,11 @@
var code = enclosingClass is MixinElement
? CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MIXIN
: CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS;
- errorReporter.reportErrorForElement(code, typeParameter, [name]);
+ errorReporter.atElement(
+ typeParameter,
+ code,
+ arguments: [name],
+ );
}
// check members
if (enclosingClass.getNamedConstructor(name) != null ||
@@ -2166,7 +2182,11 @@
var code = enclosingClass is MixinElement
? CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER_MIXIN
: CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER_CLASS;
- errorReporter.reportErrorForElement(code, typeParameter, [name]);
+ errorReporter.atElement(
+ typeParameter,
+ code,
+ arguments: [name],
+ );
}
}
}
@@ -2178,20 +2198,20 @@
var name = typeParameter.name;
// name is same as the name of the enclosing enum
if (element.name == name) {
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_ENUM,
+ errorReporter.atElement(
typeParameter,
- [name],
+ CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_ENUM,
+ arguments: [name],
);
}
// check members
if (element.getMethod(name) != null ||
element.getGetter(name) != null ||
element.getSetter(name) != null) {
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER_ENUM,
+ errorReporter.atElement(
typeParameter,
- [name],
+ CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER_ENUM,
+ arguments: [name],
);
}
}
@@ -2204,21 +2224,23 @@
var name = typeParameter.name;
// name is same as the name of the enclosing class
if (element.name == name) {
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_EXTENSION_TYPE,
- typeParameter,
- [name]);
+ errorReporter.atElement(
+ typeParameter,
+ CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_EXTENSION_TYPE,
+ arguments: [name],
+ );
}
// check members
if (element.getNamedConstructor(name) != null ||
element.getMethod(name) != null ||
element.getGetter(name) != null ||
element.getSetter(name) != null) {
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode
- .CONFLICTING_TYPE_VARIABLE_AND_MEMBER_EXTENSION_TYPE,
- typeParameter,
- [name]);
+ errorReporter.atElement(
+ typeParameter,
+ CompileTimeErrorCode
+ .CONFLICTING_TYPE_VARIABLE_AND_MEMBER_EXTENSION_TYPE,
+ arguments: [name],
+ );
}
}
}
@@ -2233,19 +2255,21 @@
String name = typeParameter.name;
// name is same as the name of the enclosing class
if (_enclosingExtension!.name == name) {
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_EXTENSION,
- typeParameter,
- [name]);
+ errorReporter.atElement(
+ typeParameter,
+ CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_EXTENSION,
+ arguments: [name],
+ );
}
// check members
if (_enclosingExtension!.getMethod(name) != null ||
_enclosingExtension!.getGetter(name) != null ||
_enclosingExtension!.getSetter(name) != null) {
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER_EXTENSION,
- typeParameter,
- [name]);
+ errorReporter.atElement(
+ typeParameter,
+ CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER_EXTENSION,
+ arguments: [name],
+ );
}
}
}
@@ -4239,10 +4263,14 @@
var superUnnamedConstructor = superElement.unnamedConstructor;
if (superUnnamedConstructor != null) {
if (superUnnamedConstructor.isFactory) {
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.NON_GENERATIVE_IMPLICIT_CONSTRUCTOR,
+ errorReporter.atElement(
element,
- [superElement.name, element.name, superUnnamedConstructor],
+ CompileTimeErrorCode.NON_GENERATIVE_IMPLICIT_CONSTRUCTOR,
+ arguments: [
+ superElement.name,
+ element.name,
+ superUnnamedConstructor,
+ ],
);
return;
}
@@ -4254,10 +4282,10 @@
if (!_typeProvider.isNonSubtypableClass(superType.element)) {
// Don't report this diagnostic for non-subtypable classes because the
// real problem was already reported.
- errorReporter.reportErrorForElement(
- CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT,
+ errorReporter.atElement(
element,
- [superType, element.displayName],
+ CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT,
+ arguments: [superType, element.displayName],
);
}
}
@@ -5518,23 +5546,23 @@
if (!superVariance
.greaterThanOrEqual(typeParameterElementImpl.variance)) {
if (!typeParameterElementImpl.isLegacyCovariant) {
- errorReporter.reportErrorForElement(
+ errorReporter.atElement(
+ typeParameter,
CompileTimeErrorCode
.WRONG_EXPLICIT_TYPE_PARAMETER_VARIANCE_IN_SUPERINTERFACE,
- typeParameter,
- [
+ arguments: [
typeParameter.name,
typeParameterElementImpl.variance.toKeywordString(),
superVariance.toKeywordString(),
- superInterface
+ superInterface,
],
);
} else {
- errorReporter.reportErrorForElement(
+ errorReporter.atElement(
+ typeParameter,
CompileTimeErrorCode
.WRONG_TYPE_PARAMETER_VARIANCE_IN_SUPERINTERFACE,
- typeParameter,
- [typeParameter.name, superInterface],
+ arguments: [typeParameter.name, superInterface],
);
}
}
@@ -6191,11 +6219,11 @@
contextMessages: _convertMessages(diagnostic),
);
case ElementMacroDiagnosticTarget():
- errorReporter.reportErrorForElement(
- errorCode,
+ errorReporter.atElement(
target.element,
- [diagnostic.message.message],
- _convertMessages(diagnostic),
+ errorCode,
+ arguments: [diagnostic.message.message],
+ contextMessages: _convertMessages(diagnostic),
);
case TypeAnnotationMacroDiagnosticTarget():
var nodeLocation = _MacroTypeAnnotationLocationConverter(
diff --git a/pkg/analyzer/test/error/error_reporter_test.dart b/pkg/analyzer/test/error/error_reporter_test.dart
index fd96eac..9fd68f5 100644
--- a/pkg/analyzer/test/error/error_reporter_test.dart
+++ b/pkg/analyzer/test/error/error_reporter_test.dart
@@ -22,27 +22,21 @@
class ErrorReporterTest extends PubPackageResolutionTest {
var listener = GatheringErrorListener();
- test_creation() async {
- var source = TestSource();
- var reporter = ErrorReporter(listener, source);
- expect(reporter, isNotNull);
- }
-
- test_reportErrorForElement_named() async {
+ test_atElement_named() async {
await resolveTestCode('class A {}');
var element = findElement.class_('A');
var reporter = ErrorReporter(listener, element.source);
- reporter.reportErrorForElement(
- CompileTimeErrorCode.CAST_TO_NON_TYPE,
+ reporter.atElement(
element,
- ['A'],
+ CompileTimeErrorCode.CAST_TO_NON_TYPE,
+ arguments: ['A'],
);
var error = listener.errors[0];
expect(error.offset, element.nameOffset);
}
- test_reportErrorForElement_unnamed() async {
+ test_atElement_unnamed() async {
await resolveTestCode(r'''
import 'dart:async';
import 'dart:math';
@@ -50,17 +44,17 @@
var element = findElement.import('dart:math');
var reporter = ErrorReporter(listener, element.source);
- reporter.reportErrorForElement(
- CompileTimeErrorCode.CAST_TO_NON_TYPE,
+ reporter.atElement(
element,
- ['A'],
+ CompileTimeErrorCode.CAST_TO_NON_TYPE,
+ arguments: ['A'],
);
var error = listener.errors[0];
expect(error.offset, element.nameOffset);
}
- test_reportErrorForNode_types_differentNames() async {
+ test_atNode_types_differentNames() async {
newFile('$testPackageLibPath/a.dart', 'class A {}');
newFile('$testPackageLibPath/b.dart', 'class B {}');
await resolveTestCode(r'''
@@ -95,7 +89,7 @@
expect(error.message, isNot(contains('(')));
}
- test_reportErrorForNode_types_sameName() async {
+ test_atNode_types_sameName() async {
newFile('$testPackageLibPath/a.dart', 'class A {}');
newFile('$testPackageLibPath/b.dart', 'class A {}');
await resolveTestCode(r'''
@@ -129,7 +123,7 @@
expect(error.message, contains('('));
}
- test_reportErrorForNode_types_sameName_functionType() async {
+ test_atNode_types_sameName_functionType() async {
newFile('$testPackageLibPath/a.dart', 'class A{}');
newFile('$testPackageLibPath/b.dart', 'class A{}');
await resolveTestCode(r'''
@@ -159,7 +153,7 @@
expect(error.message, contains('b.dart'));
}
- test_reportErrorForNode_types_sameName_nested() async {
+ test_atNode_types_sameName_nested() async {
newFile('$testPackageLibPath/a.dart', 'class A{}');
newFile('$testPackageLibPath/b.dart', 'class A{}');
await resolveTestCode(r'''
@@ -190,6 +184,12 @@
expect(error.message, contains('b.dart'));
}
+ test_creation() async {
+ var source = TestSource();
+ var reporter = ErrorReporter(listener, source);
+ expect(reporter, isNotNull);
+ }
+
test_reportErrorForSpan() async {
var source = TestSource();
var reporter = ErrorReporter(listener, source);
diff --git a/pkg/analyzer/test/src/lint/lint_rule_test.dart b/pkg/analyzer/test/src/lint/lint_rule_test.dart
index 734344c..ee16635 100644
--- a/pkg/analyzer/test/src/lint/lint_rule_test.dart
+++ b/pkg/analyzer/test/src/lint/lint_rule_test.dart
@@ -76,6 +76,17 @@
CollectingReporter(super.listener, super.source);
@override
+ void atElement(
+ Element element,
+ ErrorCode errorCode, {
+ List<Object>? arguments,
+ List<DiagnosticMessage>? contextMessages,
+ Object? data,
+ }) {
+ code = errorCode;
+ }
+
+ @override
void atNode(
AstNode node,
ErrorCode errorCode, {
@@ -97,12 +108,6 @@
code = errorCode;
}
- @override
- void reportErrorForElement(ErrorCode errorCode, Element element,
- [List<Object?>? arguments, List<DiagnosticMessage>? messages]) {
- code = errorCode;
- }
-
@Deprecated('Use atNode() instead')
@override
void reportErrorForNode(