Index: packages/analyzer/lib/src/generated/error.dart |
diff --git a/analyzer/lib/src/generated/error.dart b/packages/analyzer/lib/src/generated/error.dart |
similarity index 98% |
rename from analyzer/lib/src/generated/error.dart |
rename to packages/analyzer/lib/src/generated/error.dart |
index c667af7933dd43a1a5071670d9add0456b5e99ee..4e56e1045172109bd3a0e593a9da8823246af6d1 100644 |
--- a/analyzer/lib/src/generated/error.dart |
+++ b/packages/analyzer/lib/src/generated/error.dart |
@@ -28,21 +28,22 @@ class AnalysisError { |
* was found. |
*/ |
static Comparator<AnalysisError> FILE_COMPARATOR = (AnalysisError o1, |
- AnalysisError o2) => o1.source.shortName.compareTo(o2.source.shortName); |
+ AnalysisError o2) => |
+ o1.source.shortName.compareTo(o2.source.shortName); |
/** |
* A [Comparator] that sorts error codes first by their severity (errors |
* first, warnings second), and then by the the error code type. |
*/ |
- static Comparator<AnalysisError> ERROR_CODE_COMPARATOR = (AnalysisError o1, |
- AnalysisError o2) { |
+ static Comparator<AnalysisError> ERROR_CODE_COMPARATOR = |
+ (AnalysisError o1, AnalysisError o2) { |
ErrorCode errorCode1 = o1.errorCode; |
ErrorCode errorCode2 = o2.errorCode; |
ErrorSeverity errorSeverity1 = errorCode1.errorSeverity; |
ErrorSeverity errorSeverity2 = errorCode2.errorSeverity; |
- ErrorType errorType1 = errorCode1.type; |
- ErrorType errorType2 = errorCode2.type; |
if (errorSeverity1 == errorSeverity2) { |
+ ErrorType errorType1 = errorCode1.type; |
+ ErrorType errorType2 = errorCode2.type; |
return errorType1.compareTo(errorType2); |
} else { |
return errorSeverity2.compareTo(errorSeverity1); |
@@ -80,7 +81,7 @@ class AnalysisError { |
* The number of characters from the offset to the end of the source which |
* encompasses the compilation error. |
*/ |
- int _length = 0; |
+ int length = 0; |
/** |
* A flag indicating whether this error can be shown to be a non-issue because |
@@ -94,9 +95,8 @@ class AnalysisError { |
* [length]. The error will have the given [errorCode] and the list of |
* [arguments] will be used to complete the message. |
*/ |
- AnalysisError(this.source, this.offset, int length, this.errorCode, |
+ AnalysisError(this.source, this.offset, this.length, this.errorCode, |
[List<Object> arguments]) { |
- this._length = length; |
this._message = formatList(errorCode.message, arguments); |
String correctionTemplate = errorCode.correction; |
if (correctionTemplate != null) { |
@@ -141,13 +141,6 @@ class AnalysisError { |
} |
/** |
- * Return the length of the error location, that is, the number of characters |
- * from the offset to the end of the source which encompasses the compilation |
- * error. |
- */ |
- int get length => _length; |
- |
- /** |
* Return the message to be displayed for this error. The message should |
* indicate what is wrong and why it is wrong. |
*/ |
@@ -167,7 +160,7 @@ class AnalysisError { |
if (!identical(errorCode, other.errorCode)) { |
return false; |
} |
- if (offset != other.offset || _length != other._length) { |
+ if (offset != other.offset || length != other.length) { |
return false; |
} |
if (isStaticOnly != other.isStaticOnly) { |
@@ -197,7 +190,7 @@ class AnalysisError { |
buffer.write("("); |
buffer.write(offset); |
buffer.write(".."); |
- buffer.write(offset + _length - 1); |
+ buffer.write(offset + length - 1); |
buffer.write("): "); |
//buffer.write("(" + lineNumber + ":" + columnNumber + "): "); |
buffer.write(_message); |
@@ -609,7 +602,7 @@ class CompileTimeErrorCode extends ErrorCode { |
*/ |
static const CompileTimeErrorCode CONFLICTING_TYPE_VARIABLE_AND_CLASS = |
const CompileTimeErrorCode('CONFLICTING_TYPE_VARIABLE_AND_CLASS', |
- "'{0}' cannot be used to name a type varaible in a class with the same name"); |
+ "'{0}' cannot be used to name a type variable in a class with the same name"); |
/** |
* 7. Classes: It is a compile time error if a generic class declares a type |
@@ -618,7 +611,7 @@ class CompileTimeErrorCode extends ErrorCode { |
*/ |
static const CompileTimeErrorCode CONFLICTING_TYPE_VARIABLE_AND_MEMBER = |
const CompileTimeErrorCode('CONFLICTING_TYPE_VARIABLE_AND_MEMBER', |
- "'{0}' cannot be used to name a type varaible and member in this class"); |
+ "'{0}' cannot be used to name a type variable and member in this class"); |
/** |
* 12.11.2 Const: It is a compile-time error if evaluation of a constant |
@@ -1568,7 +1561,8 @@ class CompileTimeErrorCode extends ErrorCode { |
* 0: the name of the constant that is missing |
*/ |
static const CompileTimeErrorCode MISSING_ENUM_CONSTANT_IN_SWITCH = |
- const CompileTimeErrorCode('MISSING_ENUM_CONSTANT_IN_SWITCH', |
+ const CompileTimeErrorCode( |
+ 'MISSING_ENUM_CONSTANT_IN_SWITCH', |
"Missing case clause for '{0}'", |
"Add a case clause for the missing constant or add a default clause."); |
@@ -1604,7 +1598,8 @@ class CompileTimeErrorCode extends ErrorCode { |
* https://code.google.com/p/dart/issues/detail?id=15101#c4 |
*/ |
static const CompileTimeErrorCode MIXIN_HAS_NO_CONSTRUCTORS = |
- const CompileTimeErrorCode('MIXIN_HAS_NO_CONSTRUCTORS', |
+ const CompileTimeErrorCode( |
+ 'MIXIN_HAS_NO_CONSTRUCTORS', |
"This mixin application is invalid because all of the constructors " |
"in the base class '{0}' have optional parameters."); |
@@ -2361,6 +2356,62 @@ class CompileTimeErrorCode extends ErrorCode { |
} |
/** |
+ * An error listener that can be enabled or disabled while executing a function. |
+ */ |
+class DisablableErrorListener implements AnalysisErrorListener { |
+ /** |
+ * The listener to which errors will be reported if this listener is enabled. |
+ */ |
+ final AnalysisErrorListener baseListener; |
+ |
+ /** |
+ * A flag indicating whether this listener is currently enabled. |
+ */ |
+ bool enabled = true; |
+ |
+ /** |
+ * Initialize a newly created listener to report errors to the given |
+ * [baseListener]. |
+ */ |
+ DisablableErrorListener(this.baseListener); |
+ |
+ /** |
+ * Disable the processing of errors while evaluating the given [function]. |
+ * Return the value returned by the function. |
+ */ |
+ dynamic disableWhile(dynamic function()) { |
+ bool wasEnabled = enabled; |
+ try { |
+ enabled = false; |
+ return function(); |
+ } finally { |
+ enabled = wasEnabled; |
+ } |
+ } |
+ |
+ /** |
+ * Disable the processing of errors while evaluating the given [function]. |
+ * Return the value returned by the function. |
+ */ |
+ dynamic enableWhile(dynamic function()) { |
+ bool wasEnabled = enabled; |
+ try { |
+ enabled = true; |
+ return function(); |
+ } finally { |
+ enabled = wasEnabled; |
+ } |
+ } |
+ |
+ @override |
+ void onError(AnalysisError error) { |
+ if (enabled) { |
+ baseListener.onError(error); |
+ } |
+ } |
+} |
+ |
+/** |
* An error code associated with an [AnalysisError]. |
* |
* Generally, we want to provide messages that consist of three sentences. From |
@@ -2518,16 +2569,15 @@ class ErrorReporter { |
* Report an error with the given [errorCode] and [arguments]. The [element] |
* is used to compute the location of the error. |
*/ |
- void reportErrorForElement( |
- ErrorCode errorCode, Element element, List<Object> arguments) { |
- String displayName = element.displayName; |
+ void reportErrorForElement(ErrorCode errorCode, Element element, |
+ [List<Object> arguments]) { |
int length = 0; |
- if (displayName != null) { |
- length = displayName.length; |
- } else if (element is ImportElement) { |
+ if (element is ImportElement) { |
length = 6; // 'import'.length |
} else if (element is ExportElement) { |
length = 6; // 'export'.length |
+ } else { |
+ length = element.nameLength; |
} |
reportErrorForOffset(errorCode, element.nameOffset, length, arguments); |
} |
@@ -2893,7 +2943,8 @@ class HintCode extends ErrorCode { |
* Parameters: |
* 0: the name of the declared return type |
*/ |
- static const HintCode MISSING_RETURN = const HintCode('MISSING_RETURN', |
+ static const HintCode MISSING_RETURN = const HintCode( |
+ 'MISSING_RETURN', |
"This function declares a return type of '{0}', but does not end with a return statement", |
"Either add a return statement or change the return type to 'void'"); |
@@ -3045,7 +3096,7 @@ class HintCode extends ErrorCode { |
"The stack trace variable '{0}' is not used and can be removed"); |
/** |
- * Unused local variables are local varaibles which are never read. |
+ * Unused local variables are local variables which are never read. |
*/ |
static const HintCode UNUSED_LOCAL_VARIABLE = const HintCode( |
'UNUSED_LOCAL_VARIABLE', |
@@ -3736,7 +3787,8 @@ class StaticWarningCode extends ErrorCode { |
* 2: the name of the second library that the type is found |
*/ |
static const StaticWarningCode AMBIGUOUS_IMPORT = const StaticWarningCode( |
- 'AMBIGUOUS_IMPORT', "The name '{0}' is defined in the libraries {1}", |
+ 'AMBIGUOUS_IMPORT', |
+ "The name '{0}' is defined in the libraries {1}", |
"Consider using 'as prefix' for one of the import directives " |
"or hiding the name from all but one of the imports."); |
@@ -3960,18 +4012,6 @@ class StaticWarningCode extends ErrorCode { |
"The exported libraries '{0}' and '{1}' cannot have the same name '{2}'"); |
/** |
- * 14.2 Exports: It is a static warning to export two different libraries with |
- * the same name. |
- * |
- * Parameters: |
- * 0: the uri pointing to a first library |
- * 1: the uri pointing to a second library |
- */ |
- static const StaticWarningCode EXPORT_DUPLICATED_LIBRARY_UNNAMED = |
- const StaticWarningCode('EXPORT_DUPLICATED_LIBRARY_UNNAMED', |
- "The exported libraries '{0}' and '{1}' cannot both be unnamed"); |
- |
- /** |
* 12.14.2 Binding Actuals to Formals: It is a static warning if <i>m < |
* h</i> or if <i>m > n</i>. |
* |
@@ -4127,18 +4167,6 @@ class StaticWarningCode extends ErrorCode { |
"The imported libraries '{0}' and '{1}' cannot have the same name '{2}'"); |
/** |
- * 14.1 Imports: It is a static warning to import two different libraries with |
- * the same name. |
- * |
- * Parameters: |
- * 0: the uri pointing to a first library |
- * 1: the uri pointing to a second library |
- */ |
- static const StaticWarningCode IMPORT_DUPLICATED_LIBRARY_UNNAMED = |
- const StaticWarningCode('IMPORT_DUPLICATED_LIBRARY_UNNAMED', |
- "The imported libraries '{0}' and '{1}' cannot both be unnamed"); |
- |
- /** |
* 14.1 Imports: It is a static warning if the specified URI of a deferred |
* import does not refer to a library declaration. |
* |