Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Unified Diff: pkg/analyzer/lib/src/generated/error.dart

Issue 628053002: Create a NullErrorReporter to use when errors don't need to be recorded. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/error.dart
diff --git a/pkg/analyzer/lib/src/generated/error.dart b/pkg/analyzer/lib/src/generated/error.dart
index 1d5beba66fd7413f8b91e4e210c83b7cb032f8de..6ce7696b77758e72867dac9c0c17afbae8fe61ce 100644
--- a/pkg/analyzer/lib/src/generated/error.dart
+++ b/pkg/analyzer/lib/src/generated/error.dart
@@ -2120,38 +2120,11 @@ class ErrorProperty extends Enum<ErrorProperty> {
* Instances of the class `ErrorReporter` wrap an error listener with utility methods used to
* create the errors being reported.
*/
-class ErrorReporter {
+abstract class ErrorReporter {
Brian Wilkerson 2014/10/06 14:10:08 I'm not sure why we needed to make this an abstrac
Paul Berry 2014/10/06 16:44:39 Since NullErrorReporter is in the same library as
/**
- * The error listener to which errors will be reported.
- */
- final AnalysisErrorListener _errorListener;
-
- /**
- * The default source to be used when reporting errors.
- */
- final Source _defaultSource;
-
- /**
- * The source to be used when reporting errors.
+ * The source used when reporting errors.
*/
- Source _source;
-
- /**
- * Initialize a newly created error reporter that will report errors to the given listener.
- *
- * @param errorListener the error listener to which errors will be reported
- * @param defaultSource the default source to be used when reporting errors
- */
- ErrorReporter(this._errorListener, this._defaultSource) {
- if (_errorListener == null) {
- throw new IllegalArgumentException("An error listener must be provided");
- } else if (_defaultSource == null) {
- throw new IllegalArgumentException("A default source must be provided");
- }
- this._source = _defaultSource;
- }
-
- Source get source => _source;
+ Source get source;
/**
* Creates an error with properties with the given error code and arguments.
@@ -2160,16 +2133,14 @@ class ErrorReporter {
* @param node the node specifying the location of the error
* @param arguments the arguments to the error, used to compose the error message
*/
- AnalysisErrorWithProperties newErrorWithProperties(ErrorCode errorCode, AstNode node, List<Object> arguments) => new AnalysisErrorWithProperties.con2(_source, node.offset, node.length, errorCode, arguments);
+ AnalysisErrorWithProperties newErrorWithProperties(ErrorCode errorCode, AstNode node, List<Object> arguments);
/**
* Report a passed error.
*
* @param error the error to report
*/
- void reportError(AnalysisError error) {
- _errorListener.onError(error);
- }
+ void reportError(AnalysisError error);
/**
* Report an error with the given error code and arguments.
@@ -2178,9 +2149,7 @@ class ErrorReporter {
* @param element the element which name should be used as the location of the error
* @param arguments the arguments to the error, used to compose the error message
*/
- void reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments) {
- reportErrorForOffset(errorCode, element.nameOffset, element.displayName.length, arguments);
- }
+ void reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments);
/**
* Report an error with the given error code and arguments.
@@ -2193,9 +2162,7 @@ class ErrorReporter {
* @param node the node specifying the location of the error
* @param arguments the arguments to the error, used to compose the error message
*/
- void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> arguments) {
- reportErrorForOffset(errorCode, node.offset, node.length, arguments);
- }
+ void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> arguments);
/**
* Report an error with the given error code and arguments.
@@ -2205,9 +2172,7 @@ class ErrorReporter {
* @param length the length of the location of the error
* @param arguments the arguments to the error, used to compose the error message
*/
- void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Object> arguments) {
- _errorListener.onError(new AnalysisError.con2(_source, offset, length, errorCode, arguments));
- }
+ void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Object> arguments);
/**
* Report an error with the given error code and arguments.
@@ -2216,9 +2181,7 @@ class ErrorReporter {
* @param token the token specifying the location of the error
* @param arguments the arguments to the error, used to compose the error message
*/
- void reportErrorForToken(ErrorCode errorCode, Token token, List<Object> arguments) {
- reportErrorForOffset(errorCode, token.offset, token.length, arguments);
- }
+ void reportErrorForToken(ErrorCode errorCode, Token token, List<Object> arguments);
/**
* Report an error with the given error code and arguments. The arguments are expected to contain
@@ -2233,10 +2196,7 @@ class ErrorReporter {
* @param node the node specifying the location of the error
* @param arguments the arguments to the error, used to compose the error message
*/
- void reportTypeErrorForNode(ErrorCode errorCode, AstNode node, List<Object> arguments) {
- _convertTypeNames(arguments);
- reportErrorForOffset(errorCode, node.offset, node.length, arguments);
- }
+ void reportTypeErrorForNode(ErrorCode errorCode, AstNode node, List<Object> arguments);
/**
* Set the source to be used when reporting errors. Setting the source to `null` will cause
@@ -2244,6 +2204,78 @@ class ErrorReporter {
*
* @param source the source to be used when reporting errors
*/
+ void set source(Source source);
+}
+
+class ErrorReporterImpl implements ErrorReporter {
+ /**
+ * The error listener to which errors will be reported.
+ */
+ final AnalysisErrorListener _errorListener;
+
+ /**
+ * The default source to be used when reporting errors.
+ */
+ final Source _defaultSource;
+
+ /**
+ * The source to be used when reporting errors.
+ */
+ Source _source;
+
+ /**
+ * Initialize a newly created error reporter that will report errors to the given listener.
+ *
+ * @param errorListener the error listener to which errors will be reported
+ * @param defaultSource the default source to be used when reporting errors
+ */
+ ErrorReporterImpl(this._errorListener, this._defaultSource) {
+ if (_errorListener == null) {
+ throw new IllegalArgumentException("An error listener must be provided");
+ } else if (_defaultSource == null) {
+ throw new IllegalArgumentException("A default source must be provided");
+ }
+ this._source = _defaultSource;
+ }
+
+ @override
+ Source get source => _source;
+
+ @override
+ AnalysisErrorWithProperties newErrorWithProperties(ErrorCode errorCode, AstNode node, List<Object> arguments) => new AnalysisErrorWithProperties.con2(_source, node.offset, node.length, errorCode, arguments);
+
+ @override
+ void reportError(AnalysisError error) {
+ _errorListener.onError(error);
+ }
+
+ @override
+ void reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments) {
+ reportErrorForOffset(errorCode, element.nameOffset, element.displayName.length, arguments);
+ }
+
+ @override
+ void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> arguments) {
+ reportErrorForOffset(errorCode, node.offset, node.length, arguments);
+ }
+
+ @override
+ void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Object> arguments) {
+ _errorListener.onError(new AnalysisError.con2(_source, offset, length, errorCode, arguments));
+ }
+
+ @override
+ void reportErrorForToken(ErrorCode errorCode, Token token, List<Object> arguments) {
+ reportErrorForOffset(errorCode, token.offset, token.length, arguments);
+ }
+
+ @override
+ void reportTypeErrorForNode(ErrorCode errorCode, AstNode node, List<Object> arguments) {
+ _convertTypeNames(arguments);
+ reportErrorForOffset(errorCode, node.offset, node.length, arguments);
+ }
+
+ @override
void set source(Source source) {
this._source = source == null ? _defaultSource : source;
}
@@ -2774,6 +2806,65 @@ class HtmlWarningCode extends Enum<HtmlWarningCode> implements ErrorCode {
String get uniqueName => "${runtimeType.toString()}.${name}";
}
+
+/**
+ * The class [NullErrorReporter] presents the same interface as [ErrorReporter]
+ * but discards all error information.
+ */
+class NullErrorReporter implements ErrorReporter {
+ /**
+ * The default source to be used when reporting errors.
+ */
+ final Source _defaultSource;
+
+ /**
+ * The source to be used when reporting errors.
+ */
+ Source _source;
+
+ NullErrorReporter(this._defaultSource) {
+ _source = _defaultSource;
+ }
+
+ @override
+ AnalysisErrorWithProperties newErrorWithProperties(ErrorCode errorCode, AstNode node, List<Object> arguments) {
+ return new AnalysisErrorWithProperties.con2(_source, node.offset, node.length, errorCode, arguments);
+ }
+
+ @override
+ void reportError(AnalysisError error) {
+ }
+
+ @override
+ void reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments) {
+ }
+
+ @override
+ void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> arguments) {
+ }
+
+ @override
+ void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Object> arguments) {
+ }
+
+ @override
+ void reportErrorForToken(ErrorCode errorCode, Token token, List<Object> arguments) {
+ }
+
+ @override
+ void reportTypeErrorForNode(ErrorCode errorCode, AstNode node, List<Object> arguments) {
+ }
+
+ @override
+ void set source(Source source) {
+ this._source = source == null ? _defaultSource : source;
+ }
+
+ @override
+ Source get source => _source;
+}
+
+
/**
* The enumeration `PolymerCode` defines Polymer specific problems.
*/
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698