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

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

Issue 259773005: New analyzer snapshot. Sorted unit members. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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/element.dart ('k') | pkg/analyzer/lib/src/generated/html.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 d030164a15291ce0acb81ebe30e50ad3279ed8e9..705d2649caef301732dc8166a0ffe720a9b5b83f 100644
--- a/pkg/analyzer/lib/src/generated/error.dart
+++ b/pkg/analyzer/lib/src/generated/error.dart
@@ -14,129 +14,368 @@ import 'ast.dart' show AstNode;
import 'element.dart' show Element;
/**
- * The enumeration `PubSuggestionCode` defines the suggestions used for reporting deviations
- * from pub best practices. The convention for this class is for the name of the bad practice to
- * indicate the problem that caused the suggestion to be generated and for the message to explain
- * what is wrong and, when appropriate, how the situation can be corrected.
+ * Instances of the class `AnalysisError` represent an error discovered during the analysis of
+ * some Dart code.
+ *
+ * @see AnalysisErrorListener
*/
-class PubSuggestionCode extends Enum<PubSuggestionCode> implements ErrorCode {
+class AnalysisError {
/**
- * It is a bad practice for a source file in a package "lib" directory hierarchy to traverse
- * outside that directory hierarchy. For example, a source file in the "lib" directory should not
- * contain a directive such as `import '../web/some.dart'` which references a file outside
- * the lib directory.
+ * An empty array of errors used when no errors are expected.
*/
- static const PubSuggestionCode FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE = const PubSuggestionCode.con1('FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE', 0, "A file in the 'lib' directory hierarchy should not reference a file outside that hierarchy");
+ static List<AnalysisError> NO_ERRORS = new List<AnalysisError>(0);
/**
- * It is a bad practice for a source file ouside a package "lib" directory hierarchy to traverse
- * into that directory hierarchy. For example, a source file in the "web" directory should not
- * contain a directive such as `import '../lib/some.dart'` which references a file inside
- * the lib directory.
+ * A [Comparator] that sorts by the name of the file that the [AnalysisError] was
+ * found.
*/
- static const PubSuggestionCode FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE = const PubSuggestionCode.con1('FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE', 1, "A file outside the 'lib' directory hierarchy should not reference a file inside that hierarchy. Use a package: reference instead.");
+ static Comparator<AnalysisError> FILE_COMPARATOR = (AnalysisError o1, AnalysisError o2) => o1.source.shortName.compareTo(o2.source.shortName);
/**
- * It is a bad practice for a package import to reference anything outside the given package, or
- * more generally, it is bad practice for a package import to contain a "..". For example, a
- * source file should not contain a directive such as `import 'package:foo/../some.dart'`.
+ * A [Comparator] that sorts error codes first by their severity (errors first, warnings
+ * second), and then by the the error code type.
*/
- static const PubSuggestionCode PACKAGE_IMPORT_CONTAINS_DOT_DOT = const PubSuggestionCode.con1('PACKAGE_IMPORT_CONTAINS_DOT_DOT', 2, "A package import should not contain '..'");
+ 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) {
+ return errorType1.compareTo(errorType2);
+ } else {
+ return errorSeverity2.compareTo(errorSeverity1);
+ }
+ };
- static const List<PubSuggestionCode> values = const [
- FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE,
- FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE,
- PACKAGE_IMPORT_CONTAINS_DOT_DOT];
+ /**
+ * The error code associated with the error.
+ */
+ final ErrorCode errorCode;
/**
- * The template used to create the message to be displayed for this error.
+ * The localized error message.
*/
- final String message;
+ String _message;
/**
- * The template used to create the correction to be displayed for this error, or `null` if
- * there is no correction information for this error.
+ * The correction to be displayed for this error, or `null` if there is no correction
+ * information for this error.
*/
- final String correction;
+ String _correction;
/**
- * Initialize a newly created error code to have the given message.
+ * The source in which the error occurred, or `null` if unknown.
+ */
+ Source source;
+
+ /**
+ * The character offset from the beginning of the source (zero based) where the error occurred.
+ */
+ int _offset = 0;
+
+ /**
+ * The number of characters from the offset to the end of the source which encompasses the
+ * compilation error.
+ */
+ int _length = 0;
+
+ /**
+ * A flag indicating whether this error can be shown to be a non-issue because of the result of
+ * type propagation.
+ */
+ bool isStaticOnly = false;
+
+ /**
+ * Initialize a newly created analysis error for the specified source. The error has no location
+ * information.
*
- * @param message the message template used to create the message to be displayed for the error
+ * @param source the source for which the exception occurred
+ * @param errorCode the error code to be associated with this error
+ * @param arguments the arguments used to build the error message
*/
- const PubSuggestionCode.con1(String name, int ordinal, String message) : this.con2(name, ordinal, message, null);
+ AnalysisError.con1(this.source, this.errorCode, List<Object> arguments) {
+ this._message = JavaString.format(errorCode.message, arguments);
+ }
/**
- * Initialize a newly created error code to have the given message and correction.
+ * Initialize a newly created analysis error for the specified source at the given location.
*
- * @param message the template used to create the message to be displayed for the error
- * @param correction the template used to create the correction to be displayed for the error
+ * @param source the source for which the exception occurred
+ * @param offset the offset of the location of the error
+ * @param length the length of the location of the error
+ * @param errorCode the error code to be associated with this error
+ * @param arguments the arguments used to build the error message
*/
- const PubSuggestionCode.con2(String name, int ordinal, this.message, this.correction) : super(name, ordinal);
+ AnalysisError.con2(this.source, int offset, int length, this.errorCode, List<Object> arguments) {
+ this._offset = offset;
+ this._length = length;
+ this._message = JavaString.format(errorCode.message, arguments);
+ String correctionTemplate = errorCode.correction;
+ if (correctionTemplate != null) {
+ this._correction = JavaString.format(correctionTemplate, arguments);
+ }
+ }
@override
- ErrorSeverity get errorSeverity => ErrorType.PUB_SUGGESTION.severity;
+ bool operator ==(Object obj) {
+ if (identical(obj, this)) {
+ return true;
+ }
+ // prepare other AnalysisError
+ if (obj is! AnalysisError) {
+ return false;
+ }
+ AnalysisError other = obj as AnalysisError;
+ // Quick checks.
+ if (!identical(errorCode, other.errorCode)) {
+ return false;
+ }
+ if (_offset != other._offset || _length != other._length) {
+ return false;
+ }
+ if (isStaticOnly != other.isStaticOnly) {
+ return false;
+ }
+ // Deep checks.
+ if (_message != other._message) {
+ return false;
+ }
+ if (source != other.source) {
+ return false;
+ }
+ // OK
+ return true;
+ }
+
+ /**
+ * Return the correction to be displayed for this error, or `null` if there is no correction
+ * information for this error. The correction should indicate how the user can fix the error.
+ *
+ * @return the template used to create the correction to be displayed for this error
+ */
+ String get correction => _correction;
+
+ /**
+ * Return the number of characters from the offset to the end of the source which encompasses the
+ * compilation error.
+ *
+ * @return the length of the error location
+ */
+ 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.
+ *
+ * @return the message to be displayed for this error
+ */
+ String get message => _message;
+
+ /**
+ * Return the character offset from the beginning of the source (zero based) where the error
+ * occurred.
+ *
+ * @return the offset to the start of the error location
+ */
+ int get offset => _offset;
+
+ /**
+ * Return the value of the given property, or `null` if the given property is not defined
+ * for this error.
+ *
+ * @param property the property whose value is to be returned
+ * @return the value of the given property
+ */
+ Object getProperty(ErrorProperty property) => null;
@override
- ErrorType get type => ErrorType.PUB_SUGGESTION;
+ int get hashCode {
+ int hashCode = _offset;
+ hashCode ^= (_message != null) ? _message.hashCode : 0;
+ hashCode ^= (source != null) ? source.hashCode : 0;
+ return hashCode;
+ }
+
+ @override
+ String toString() {
+ JavaStringBuilder builder = new JavaStringBuilder();
+ builder.append((source != null) ? source.fullName : "<unknown source>");
+ builder.append("(");
+ builder.append(_offset);
+ builder.append("..");
+ builder.append(_offset + _length - 1);
+ builder.append("): ");
+ //builder.append("(" + lineNumber + ":" + columnNumber + "): ");
+ builder.append(_message);
+ return builder.toString();
+ }
}
/**
- * The enumeration `HtmlWarningCode` defines the error codes used for warnings in HTML files.
- * The convention for this class is for the name of the error code to indicate the problem that
- * caused the error to be generated and for the error message to explain what is wrong and, when
- * appropriate, how the problem can be corrected.
+ * The interface `AnalysisErrorListener` defines the behavior of objects that listen for
+ * [AnalysisError] being produced by the analysis engine.
*/
-class HtmlWarningCode extends Enum<HtmlWarningCode> implements ErrorCode {
+abstract class AnalysisErrorListener {
/**
- * An error code indicating that the value of the 'src' attribute of a Dart script tag is not a
- * valid URI.
+ * An error listener that ignores errors that are reported to it.
+ */
+ static final AnalysisErrorListener NULL_LISTENER = new AnalysisErrorListener_NULL_LISTENER();
+
+ /**
+ * This method is invoked when an error has been found by the analysis engine.
*
- * @param uri the URI that is invalid
+ * @param error the error that was just found (not `null`)
*/
- static const HtmlWarningCode INVALID_URI = const HtmlWarningCode.con1('INVALID_URI', 0, "Invalid URI syntax: '%s'");
+ void onError(AnalysisError error);
+}
+
+class AnalysisErrorListener_NULL_LISTENER implements AnalysisErrorListener {
+ @override
+ void onError(AnalysisError event) {
+ }
+}
+
+/**
+ * Instances of the class `AnalysisErrorWithProperties`
+ */
+class AnalysisErrorWithProperties extends AnalysisError {
+ /**
+ * The properties associated with this error.
+ */
+ Map<ErrorProperty, Object> _propertyMap = new Map<ErrorProperty, Object>();
/**
- * An error code indicating that the value of the 'src' attribute of a Dart script tag references
- * a file that does not exist.
+ * Initialize a newly created analysis error for the specified source. The error has no location
+ * information.
*
- * @param uri the URI pointing to a non-existent file
+ * @param source the source for which the exception occurred
+ * @param errorCode the error code to be associated with this error
+ * @param arguments the arguments used to build the error message
*/
- static const HtmlWarningCode URI_DOES_NOT_EXIST = const HtmlWarningCode.con1('URI_DOES_NOT_EXIST', 1, "Target of URI does not exist: '%s'");
+ AnalysisErrorWithProperties.con1(Source source, ErrorCode errorCode, List<Object> arguments) : super.con1(source, errorCode, arguments);
- static const List<HtmlWarningCode> values = const [INVALID_URI, URI_DOES_NOT_EXIST];
+ /**
+ * Initialize a newly created analysis error for the specified source at the given location.
+ *
+ * @param source the source for which the exception occurred
+ * @param offset the offset of the location of the error
+ * @param length the length of the location of the error
+ * @param errorCode the error code to be associated with this error
+ * @param arguments the arguments used to build the error message
+ */
+ AnalysisErrorWithProperties.con2(Source source, int offset, int length, ErrorCode errorCode, List<Object> arguments) : super.con2(source, offset, length, errorCode, arguments);
+
+ @override
+ Object getProperty(ErrorProperty property) => _propertyMap[property];
+
+ /**
+ * Set the value of the given property to the given value. Using a value of `null` will
+ * effectively remove the property from this error.
+ *
+ * @param property the property whose value is to be returned
+ * @param value the new value of the given property
+ */
+ void setProperty(ErrorProperty property, Object value) {
+ _propertyMap[property] = value;
+ }
+}
+
+/**
+ * The enumeration `AngularCode` defines Angular specific problems.
+ */
+class AngularCode extends Enum<AngularCode> implements ErrorCode {
+ static const AngularCode CANNOT_PARSE_SELECTOR = const AngularCode('CANNOT_PARSE_SELECTOR', 0, "The selector '%s' cannot be parsed");
+
+ static const AngularCode INVALID_FORMATTER_NAME = const AngularCode('INVALID_FORMATTER_NAME', 1, "Formatter name must be a simple identifier");
+
+ static const AngularCode INVALID_PROPERTY_KIND = const AngularCode('INVALID_PROPERTY_KIND', 2, "Unknown property binding kind '%s', use one of the '@', '=>', '=>!' or '<=>'");
+
+ static const AngularCode INVALID_PROPERTY_FIELD = const AngularCode('INVALID_PROPERTY_FIELD', 3, "Unknown property field '%s'");
+
+ static const AngularCode INVALID_PROPERTY_MAP = const AngularCode('INVALID_PROPERTY_MAP', 4, "Argument 'map' must be a constant map literal");
+
+ static const AngularCode INVALID_PROPERTY_NAME = const AngularCode('INVALID_PROPERTY_NAME', 5, "Property name must be a string literal");
+
+ static const AngularCode INVALID_PROPERTY_SPEC = const AngularCode('INVALID_PROPERTY_SPEC', 6, "Property binding specification must be a string literal");
+
+ static const AngularCode INVALID_REPEAT_SYNTAX = const AngularCode('INVALID_REPEAT_SYNTAX', 7, "Expected statement in form '_item_ in _collection_ [tracked by _id_]'");
+
+ static const AngularCode INVALID_REPEAT_ITEM_SYNTAX = const AngularCode('INVALID_REPEAT_ITEM_SYNTAX', 8, "Item must by identifier or in '(_key_, _value_)' pair.");
+
+ static const AngularCode INVALID_URI = const AngularCode('INVALID_URI', 9, "Invalid URI syntax: '%s'");
+
+ static const AngularCode MISSING_FORMATTER_COLON = const AngularCode('MISSING_FORMATTER_COLON', 10, "Missing ':' before formatter argument");
+
+ static const AngularCode MISSING_NAME = const AngularCode('MISSING_NAME', 11, "Argument 'name' must be provided");
+
+ static const AngularCode MISSING_PUBLISH_AS = const AngularCode('MISSING_PUBLISH_AS', 12, "Argument 'publishAs' must be provided");
+
+ static const AngularCode MISSING_SELECTOR = const AngularCode('MISSING_SELECTOR', 13, "Argument 'selector' must be provided");
+
+ static const AngularCode URI_DOES_NOT_EXIST = const AngularCode('URI_DOES_NOT_EXIST', 14, "Target of URI does not exist: '%s'");
+
+ static const List<AngularCode> values = const [
+ CANNOT_PARSE_SELECTOR,
+ INVALID_FORMATTER_NAME,
+ INVALID_PROPERTY_KIND,
+ INVALID_PROPERTY_FIELD,
+ INVALID_PROPERTY_MAP,
+ INVALID_PROPERTY_NAME,
+ INVALID_PROPERTY_SPEC,
+ INVALID_REPEAT_SYNTAX,
+ INVALID_REPEAT_ITEM_SYNTAX,
+ INVALID_URI,
+ MISSING_FORMATTER_COLON,
+ MISSING_NAME,
+ MISSING_PUBLISH_AS,
+ MISSING_SELECTOR,
+ URI_DOES_NOT_EXIST];
/**
* The template used to create the message to be displayed for this error.
*/
final String message;
- /**
- * The template used to create the correction to be displayed for this error, or `null` if
- * there is no correction information for this error.
- */
- final String correction;
+ /**
+ * Initialize a newly created error code to have the given message.
+ *
+ * @param message the message template used to create the message to be displayed for the error
+ */
+ const AngularCode(String name, int ordinal, this.message) : super(name, ordinal);
+
+ @override
+ String get correction => null;
+
+ @override
+ ErrorSeverity get errorSeverity => ErrorSeverity.INFO;
+
+ @override
+ ErrorType get type => ErrorType.ANGULAR;
+}
+/**
+ * Instances of the class `BooleanErrorListener` implement a listener that keeps track of
+ * whether an error has been reported to it.
+ */
+class BooleanErrorListener implements AnalysisErrorListener {
/**
- * Initialize a newly created error code to have the given message.
- *
- * @param message the message template used to create the message to be displayed for the error
+ * A flag indicating whether an error has been reported to this listener.
*/
- const HtmlWarningCode.con1(String name, int ordinal, String message) : this.con2(name, ordinal, message, null);
+ bool _errorReported = false;
/**
- * Initialize a newly created error code to have the given message and correction.
+ * Return `true` if an error has been reported to this listener.
*
- * @param message the template used to create the message to be displayed for the error
- * @param correction the template used to create the correction to be displayed for the error
+ * @return `true` if an error has been reported to this listener
*/
- const HtmlWarningCode.con2(String name, int ordinal, this.message, this.correction) : super(name, ordinal);
-
- @override
- ErrorSeverity get errorSeverity => ErrorSeverity.WARNING;
+ bool get errorReported => _errorReported;
@override
- ErrorType get type => ErrorType.STATIC_WARNING;
+ void onError(AnalysisError error) {
+ _errorReported = true;
+ }
}
/**
@@ -1525,447 +1764,225 @@ class CompileTimeErrorCode extends Enum<CompileTimeErrorCode> implements ErrorCo
}
/**
- * The enumeration `TodoCode` defines the single TODO `ErrorCode`.
- */
-class TodoCode extends Enum<TodoCode> implements ErrorCode {
- /**
- * The single enum of TodoCode.
- */
- static const TodoCode TODO = const TodoCode('TODO', 0);
-
- static const List<TodoCode> values = const [TODO];
-
- /**
- * This matches the two common Dart task styles
- *
- * * TODO:
- * * TODO(username):
- *
- * As well as
- * * TODO
- *
- * But not
- * * todo
- * * TODOS
- */
- static RegExp TODO_REGEX = new RegExp("([\\s/\\*])((TODO[^\\w\\d][^\\r\\n]*)|(TODO:?\$))");
-
- const TodoCode(String name, int ordinal) : super(name, ordinal);
-
- @override
- String get correction => null;
-
- @override
- ErrorSeverity get errorSeverity => ErrorSeverity.INFO;
-
- @override
- String get message => "%s";
-
- @override
- ErrorType get type => ErrorType.TODO;
-}
-
-/**
- * Instances of the class `ErrorReporter` wrap an error listener with utility methods used to
- * create the errors being reported.
+ * The interface `ErrorCode` defines the behavior common to objects representing error codes
+ * associated with [AnalysisError].
+ *
+ * Generally, we want to provide messages that consist of three sentences: 1. what is wrong, 2. why
+ * is it wrong, and 3. how do I fix it. However, we combine the first two in the result of
+ * [getMessage] and the last in the result of [getCorrection].
*/
-class 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
- */
- 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;
- }
-
- /**
- * Creates an error with properties with the given error code and arguments.
- *
- * @param errorCode the error code of the error to be reported
- * @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);
-
- /**
- * Report a passed error.
- *
- * @param error the error to report
- */
- void reportError(AnalysisError error) {
- _errorListener.onError(error);
- }
-
- /**
- * Report an error with the given error code and arguments.
- *
- * @param errorCode the error code of the error to be reported
- * @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);
- }
-
- /**
- * Report an error with the given error code and arguments.
- *
- * @param errorCode the error code of the error to be reported
- * @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);
- }
-
+abstract class ErrorCode {
/**
- * Report an error with the given error code and arguments.
+ * Return the template used to create the correction to be displayed for this error, or
+ * `null` if there is no correction information for this error. The correction should
+ * indicate how the user can fix the error.
*
- * @param errorCode the error code of the error to be reported
- * @param offset the offset of the location of the error
- * @param length the length of the location of the error
- * @param arguments the arguments to the error, used to compose the error message
+ * @return the template used to create the correction to be displayed for this error
*/
- void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Object> arguments) {
- _errorListener.onError(new AnalysisError.con2(_source, offset, length, errorCode, arguments));
- }
+ String get correction;
/**
- * Report an error with the given error code and arguments.
+ * Return the severity of this error.
*
- * @param errorCode the error code of the error to be reported
- * @param token the token specifying the location of the error
- * @param arguments the arguments to the error, used to compose the error message
+ * @return the severity of this error
*/
- void reportErrorForToken(ErrorCode errorCode, Token token, List<Object> arguments) {
- reportErrorForOffset(errorCode, token.offset, token.length, arguments);
- }
+ ErrorSeverity get errorSeverity;
/**
- * Set the source to be used when reporting errors. Setting the source to `null` will cause
- * the default source to be used.
+ * Return the template used to create the message to be displayed for this error. The message
+ * should indicate what is wrong and why it is wrong.
*
- * @param source the source to be used when reporting errors
- */
- void set source(Source source) {
- this._source = source == null ? _defaultSource : source;
- }
-}
-
-/**
- * The enumeration `PolymerCode` defines Polymer specific problems.
- */
-class PolymerCode extends Enum<PolymerCode> implements ErrorCode {
- static const PolymerCode ATTRIBUTE_FIELD_NOT_PUBLISHED = const PolymerCode('ATTRIBUTE_FIELD_NOT_PUBLISHED', 0, "Field '%s' in '%s' must be @published");
-
- static const PolymerCode DUPLICATE_ATTRIBUTE_DEFINITION = const PolymerCode('DUPLICATE_ATTRIBUTE_DEFINITION', 1, "The attribute '%s' is already defined");
-
- static const PolymerCode EMPTY_ATTRIBUTES = const PolymerCode('EMPTY_ATTRIBUTES', 2, "Empty 'attributes' attribute is useless");
-
- static const PolymerCode INVALID_ATTRIBUTE_NAME = const PolymerCode('INVALID_ATTRIBUTE_NAME', 3, "'%s' is not a valid name for a custom element attribute");
-
- static const PolymerCode INVALID_TAG_NAME = const PolymerCode('INVALID_TAG_NAME', 4, "'%s' is not a valid name for a custom element");
-
- static const PolymerCode MISSING_TAG_NAME = const PolymerCode('MISSING_TAG_NAME', 5, "Missing tag name of the custom element. Please include an attribute like name='your-tag-name'");
-
- static const PolymerCode UNDEFINED_ATTRIBUTE_FIELD = const PolymerCode('UNDEFINED_ATTRIBUTE_FIELD', 6, "There is no such field '%s' in '%s'");
-
- static const List<PolymerCode> values = const [
- ATTRIBUTE_FIELD_NOT_PUBLISHED,
- DUPLICATE_ATTRIBUTE_DEFINITION,
- EMPTY_ATTRIBUTES,
- INVALID_ATTRIBUTE_NAME,
- INVALID_TAG_NAME,
- MISSING_TAG_NAME,
- UNDEFINED_ATTRIBUTE_FIELD];
-
- /**
- * The template used to create the message to be displayed for this error.
+ * @return the template used to create the message to be displayed for this error
*/
- final String message;
+ String get message;
/**
- * Initialize a newly created error code to have the given message.
+ * Return the type of the error.
*
- * @param message the message template used to create the message to be displayed for the error
+ * @return the type of the error
*/
- const PolymerCode(String name, int ordinal, this.message) : super(name, ordinal);
-
- @override
- String get correction => null;
-
- @override
- ErrorSeverity get errorSeverity => ErrorSeverity.INFO;
-
- @override
- ErrorType get type => ErrorType.POLYMER;
+ ErrorType get type;
}
/**
- * Instances of the class `AnalysisError` represent an error discovered during the analysis of
- * some Dart code.
- *
- * @see AnalysisErrorListener
- */
-class AnalysisError {
- /**
- * An empty array of errors used when no errors are expected.
- */
- static List<AnalysisError> NO_ERRORS = new List<AnalysisError>(0);
-
- /**
- * A [Comparator] that sorts by the name of the file that the [AnalysisError] was
- * found.
- */
- static Comparator<AnalysisError> FILE_COMPARATOR = (AnalysisError o1, AnalysisError o2) => o1.source.shortName.compareTo(o2.source.shortName);
-
+ * The enumeration `ErrorProperty` defines the properties that can be associated with an
+ * [AnalysisError].
+ */
+class ErrorProperty extends Enum<ErrorProperty> {
/**
- * A [Comparator] that sorts error codes first by their severity (errors first, warnings
- * second), and then by the the error code type.
+ * A property whose value is an array of [ExecutableElement] that should
+ * be but are not implemented by a concrete class.
*/
- 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) {
- return errorType1.compareTo(errorType2);
- } else {
- return errorSeverity2.compareTo(errorSeverity1);
- }
- };
+ static const ErrorProperty UNIMPLEMENTED_METHODS = const ErrorProperty('UNIMPLEMENTED_METHODS', 0);
+
+ static const List<ErrorProperty> values = const [UNIMPLEMENTED_METHODS];
+
+ const ErrorProperty(String name, int ordinal) : super(name, ordinal);
+}
+/**
+ * Instances of the class `ErrorReporter` wrap an error listener with utility methods used to
+ * create the errors being reported.
+ */
+class ErrorReporter {
/**
- * The error code associated with the error.
+ * The error listener to which errors will be reported.
*/
- final ErrorCode errorCode;
+ final AnalysisErrorListener _errorListener;
/**
- * The localized error message.
+ * The default source to be used when reporting errors.
*/
- String _message;
+ final Source _defaultSource;
/**
- * The correction to be displayed for this error, or `null` if there is no correction
- * information for this error.
+ * The source to be used when reporting errors.
*/
- String _correction;
+ Source _source;
/**
- * The source in which the error occurred, or `null` if unknown.
+ * 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
*/
- Source source;
+ 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;
+ }
/**
- * The character offset from the beginning of the source (zero based) where the error occurred.
+ * Creates an error with properties with the given error code and arguments.
+ *
+ * @param errorCode the error code of the error to be reported
+ * @param node the node specifying the location of the error
+ * @param arguments the arguments to the error, used to compose the error message
*/
- int _offset = 0;
+ AnalysisErrorWithProperties newErrorWithProperties(ErrorCode errorCode, AstNode node, List<Object> arguments) => new AnalysisErrorWithProperties.con2(_source, node.offset, node.length, errorCode, arguments);
/**
- * The number of characters from the offset to the end of the source which encompasses the
- * compilation error.
+ * Report a passed error.
+ *
+ * @param error the error to report
*/
- int _length = 0;
+ void reportError(AnalysisError error) {
+ _errorListener.onError(error);
+ }
/**
- * A flag indicating whether this error can be shown to be a non-issue because of the result of
- * type propagation.
+ * Report an error with the given error code and arguments.
+ *
+ * @param errorCode the error code of the error to be reported
+ * @param node the node specifying the location of the error
+ * @param arguments the arguments to the error, used to compose the error message
*/
- bool isStaticOnly = false;
+ void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> arguments) {
+ reportErrorForOffset(errorCode, node.offset, node.length, arguments);
+ }
/**
- * Initialize a newly created analysis error for the specified source. The error has no location
- * information.
+ * Report an error with the given error code and arguments.
*
- * @param source the source for which the exception occurred
- * @param errorCode the error code to be associated with this error
- * @param arguments the arguments used to build the error message
+ * @param errorCode the error code of the error to be reported
+ * @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
*/
- AnalysisError.con1(this.source, this.errorCode, List<Object> arguments) {
- this._message = JavaString.format(errorCode.message, arguments);
+ void reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments) {
+ reportErrorForOffset(errorCode, element.nameOffset, element.displayName.length, arguments);
}
/**
- * Initialize a newly created analysis error for the specified source at the given location.
+ * Report an error with the given error code and arguments.
*
- * @param source the source for which the exception occurred
+ * @param errorCode the error code of the error to be reported
* @param offset the offset of the location of the error
* @param length the length of the location of the error
- * @param errorCode the error code to be associated with this error
- * @param arguments the arguments used to build the error message
+ * @param arguments the arguments to the error, used to compose the error message
*/
- AnalysisError.con2(this.source, int offset, int length, this.errorCode, List<Object> arguments) {
- this._offset = offset;
- this._length = length;
- this._message = JavaString.format(errorCode.message, arguments);
- String correctionTemplate = errorCode.correction;
- if (correctionTemplate != null) {
- this._correction = JavaString.format(correctionTemplate, arguments);
- }
- }
-
- @override
- bool operator ==(Object obj) {
- if (identical(obj, this)) {
- return true;
- }
- // prepare other AnalysisError
- if (obj is! AnalysisError) {
- return false;
- }
- AnalysisError other = obj as AnalysisError;
- // Quick checks.
- if (!identical(errorCode, other.errorCode)) {
- return false;
- }
- if (_offset != other._offset || _length != other._length) {
- return false;
- }
- if (isStaticOnly != other.isStaticOnly) {
- return false;
- }
- // Deep checks.
- if (_message != other._message) {
- return false;
- }
- if (source != other.source) {
- return false;
- }
- // OK
- return true;
+ void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Object> arguments) {
+ _errorListener.onError(new AnalysisError.con2(_source, offset, length, errorCode, arguments));
}
/**
- * Return the correction to be displayed for this error, or `null` if there is no correction
- * information for this error. The correction should indicate how the user can fix the error.
+ * Report an error with the given error code and arguments.
*
- * @return the template used to create the correction to be displayed for this error
+ * @param errorCode the error code of the error to be reported
+ * @param token the token specifying the location of the error
+ * @param arguments the arguments to the error, used to compose the error message
*/
- String get correction => _correction;
+ void reportErrorForToken(ErrorCode errorCode, Token token, List<Object> arguments) {
+ reportErrorForOffset(errorCode, token.offset, token.length, arguments);
+ }
/**
- * Return the number of characters from the offset to the end of the source which encompasses the
- * compilation error.
+ * Set the source to be used when reporting errors. Setting the source to `null` will cause
+ * the default source to be used.
*
- * @return the length of the error location
+ * @param source the source to be used when reporting errors
*/
- int get length => _length;
+ void set source(Source source) {
+ this._source = source == null ? _defaultSource : source;
+ }
+}
+/**
+ * Instances of the enumeration `ErrorSeverity` represent the severity of an [ErrorCode]
+ * .
+ */
+class ErrorSeverity extends Enum<ErrorSeverity> {
/**
- * Return the message to be displayed for this error. The message should indicate what is wrong
- * and why it is wrong.
- *
- * @return the message to be displayed for this error
+ * The severity representing a non-error. This is never used for any error code, but is useful for
+ * clients.
*/
- String get message => _message;
+ static const ErrorSeverity NONE = const ErrorSeverity('NONE', 0, " ", "none");
/**
- * Return the character offset from the beginning of the source (zero based) where the error
- * occurred.
- *
- * @return the offset to the start of the error location
+ * The severity representing an informational level analysis issue.
*/
- int get offset => _offset;
+ static const ErrorSeverity INFO = const ErrorSeverity('INFO', 1, "I", "info");
/**
- * Return the value of the given property, or `null` if the given property is not defined
- * for this error.
- *
- * @param property the property whose value is to be returned
- * @return the value of the given property
+ * The severity representing a warning. Warnings can become errors if the `-Werror` command
+ * line flag is specified.
*/
- Object getProperty(ErrorProperty property) => null;
+ static const ErrorSeverity WARNING = const ErrorSeverity('WARNING', 2, "W", "warning");
- @override
- int get hashCode {
- int hashCode = _offset;
- hashCode ^= (_message != null) ? _message.hashCode : 0;
- hashCode ^= (source != null) ? source.hashCode : 0;
- return hashCode;
- }
+ /**
+ * The severity representing an error.
+ */
+ static const ErrorSeverity ERROR = const ErrorSeverity('ERROR', 3, "E", "error");
- @override
- String toString() {
- JavaStringBuilder builder = new JavaStringBuilder();
- builder.append((source != null) ? source.fullName : "<unknown source>");
- builder.append("(");
- builder.append(_offset);
- builder.append("..");
- builder.append(_offset + _length - 1);
- builder.append("): ");
- //builder.append("(" + lineNumber + ":" + columnNumber + "): ");
- builder.append(_message);
- return builder.toString();
- }
-}
+ static const List<ErrorSeverity> values = const [NONE, INFO, WARNING, ERROR];
-/**
- * Instances of the class `AnalysisErrorWithProperties`
- */
-class AnalysisErrorWithProperties extends AnalysisError {
/**
- * The properties associated with this error.
+ * The name of the severity used when producing machine output.
*/
- Map<ErrorProperty, Object> _propertyMap = new Map<ErrorProperty, Object>();
+ final String machineCode;
/**
- * Initialize a newly created analysis error for the specified source. The error has no location
- * information.
- *
- * @param source the source for which the exception occurred
- * @param errorCode the error code to be associated with this error
- * @param arguments the arguments used to build the error message
+ * The name of the severity used when producing readable output.
*/
- AnalysisErrorWithProperties.con1(Source source, ErrorCode errorCode, List<Object> arguments) : super.con1(source, errorCode, arguments);
+ final String displayName;
/**
- * Initialize a newly created analysis error for the specified source at the given location.
+ * Initialize a newly created severity with the given names.
*
- * @param source the source for which the exception occurred
- * @param offset the offset of the location of the error
- * @param length the length of the location of the error
- * @param errorCode the error code to be associated with this error
- * @param arguments the arguments used to build the error message
+ * @param machineCode the name of the severity used when producing machine output
+ * @param displayName the name of the severity used when producing readable output
*/
- AnalysisErrorWithProperties.con2(Source source, int offset, int length, ErrorCode errorCode, List<Object> arguments) : super.con2(source, offset, length, errorCode, arguments);
-
- @override
- Object getProperty(ErrorProperty property) => _propertyMap[property];
+ const ErrorSeverity(String name, int ordinal, this.machineCode, this.displayName) : super(name, ordinal);
/**
- * Set the value of the given property to the given value. Using a value of `null` will
- * effectively remove the property from this error.
+ * Return the severity constant that represents the greatest severity.
*
- * @param property the property whose value is to be returned
- * @param value the new value of the given property
+ * @param severity the severity being compared against
+ * @return the most sever of this or the given severity
*/
- void setProperty(ErrorProperty property, Object value) {
- _propertyMap[property] = value;
- }
+ ErrorSeverity max(ErrorSeverity severity) => this.ordinal >= severity.ordinal ? this : severity;
}
/**
@@ -2049,430 +2066,231 @@ class ErrorType extends Enum<ErrorType> {
}
/**
- * The interface `ErrorCode` defines the behavior common to objects representing error codes
- * associated with [AnalysisError].
- *
- * Generally, we want to provide messages that consist of three sentences: 1. what is wrong, 2. why
- * is it wrong, and 3. how do I fix it. However, we combine the first two in the result of
- * [getMessage] and the last in the result of [getCorrection].
+ * The enumeration `HintCode` defines the hints and coding recommendations for best practices
+ * which are not mentioned in the Dart Language Specification.
*/
-abstract class ErrorCode {
- /**
- * Return the template used to create the correction to be displayed for this error, or
- * `null` if there is no correction information for this error. The correction should
- * indicate how the user can fix the error.
- *
- * @return the template used to create the correction to be displayed for this error
- */
- String get correction;
-
- /**
- * Return the severity of this error.
- *
- * @return the severity of this error
- */
- ErrorSeverity get errorSeverity;
-
- /**
- * Return the template used to create the message to be displayed for this error. The message
- * should indicate what is wrong and why it is wrong.
- *
- * @return the template used to create the message to be displayed for this error
- */
- String get message;
-
+class HintCode extends Enum<HintCode> implements ErrorCode {
/**
- * Return the type of the error.
+ * This hint is generated anywhere where the
+ * [StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE] would have been generated, if we used
+ * propagated information for the warnings.
*
- * @return the type of the error
- */
- ErrorType get type;
-}
-
-/**
- * Instances of the enumeration `ErrorSeverity` represent the severity of an [ErrorCode]
- * .
- */
-class ErrorSeverity extends Enum<ErrorSeverity> {
- /**
- * The severity representing a non-error. This is never used for any error code, but is useful for
- * clients.
- */
- static const ErrorSeverity NONE = const ErrorSeverity('NONE', 0, " ", "none");
-
- /**
- * The severity representing an informational level analysis issue.
- */
- static const ErrorSeverity INFO = const ErrorSeverity('INFO', 1, "I", "info");
-
- /**
- * The severity representing a warning. Warnings can become errors if the `-Werror` command
- * line flag is specified.
- */
- static const ErrorSeverity WARNING = const ErrorSeverity('WARNING', 2, "W", "warning");
-
- /**
- * The severity representing an error.
+ * @param actualType the name of the actual argument type
+ * @param expectedType the name of the expected type
+ * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
*/
- static const ErrorSeverity ERROR = const ErrorSeverity('ERROR', 3, "E", "error");
-
- static const List<ErrorSeverity> values = const [NONE, INFO, WARNING, ERROR];
+ static const HintCode ARGUMENT_TYPE_NOT_ASSIGNABLE = const HintCode.con1('ARGUMENT_TYPE_NOT_ASSIGNABLE', 0, "The argument type '%s' cannot be assigned to the parameter type '%s'");
/**
- * The name of the severity used when producing machine output.
+ * Dead code is code that is never reached, this can happen for instance if a statement follows a
+ * return statement.
*/
- final String machineCode;
+ static const HintCode DEAD_CODE = const HintCode.con1('DEAD_CODE', 1, "Dead code");
/**
- * The name of the severity used when producing readable output.
+ * Dead code is code that is never reached. This case covers cases where the user has catch
+ * clauses after `catch (e)` or `on Object catch (e)`.
*/
- final String displayName;
+ static const HintCode DEAD_CODE_CATCH_FOLLOWING_CATCH = const HintCode.con1('DEAD_CODE_CATCH_FOLLOWING_CATCH', 2, "Dead code, catch clauses after a 'catch (e)' or an 'on Object catch (e)' are never reached");
/**
- * Initialize a newly created severity with the given names.
+ * Dead code is code that is never reached. This case covers cases where the user has an on-catch
+ * clause such as `on A catch (e)`, where a supertype of `A` was already caught.
*
- * @param machineCode the name of the severity used when producing machine output
- * @param displayName the name of the severity used when producing readable output
+ * @param subtypeName name of the subtype
+ * @param supertypeName name of the supertype
*/
- const ErrorSeverity(String name, int ordinal, this.machineCode, this.displayName) : super(name, ordinal);
+ static const HintCode DEAD_CODE_ON_CATCH_SUBTYPE = const HintCode.con1('DEAD_CODE_ON_CATCH_SUBTYPE', 3, "Dead code, this on-catch block will never be executed since '%s' is a subtype of '%s'");
/**
- * Return the severity constant that represents the greatest severity.
+ * Deprecated members should not be invoked or used.
*
- * @param severity the severity being compared against
- * @return the most sever of this or the given severity
- */
- ErrorSeverity max(ErrorSeverity severity) => this.ordinal >= severity.ordinal ? this : severity;
-}
-
-/**
- * The interface `AnalysisErrorListener` defines the behavior of objects that listen for
- * [AnalysisError] being produced by the analysis engine.
- */
-abstract class AnalysisErrorListener {
- /**
- * An error listener that ignores errors that are reported to it.
+ * @param memberName the name of the member
*/
- static final AnalysisErrorListener NULL_LISTENER = new AnalysisErrorListener_NULL_LISTENER();
+ static const HintCode DEPRECATED_MEMBER_USE = const HintCode.con1('DEPRECATED_MEMBER_USE', 4, "'%s' is deprecated");
/**
- * This method is invoked when an error has been found by the analysis engine.
- *
- * @param error the error that was just found (not `null`)
+ * Duplicate imports.
*/
- void onError(AnalysisError error);
-}
-
-class AnalysisErrorListener_NULL_LISTENER implements AnalysisErrorListener {
- @override
- void onError(AnalysisError event) {
- }
-}
+ static const HintCode DUPLICATE_IMPORT = const HintCode.con1('DUPLICATE_IMPORT', 5, "Duplicate import");
-/**
- * The enumeration `StaticTypeWarningCode` defines the error codes used for static type
- * warnings. The convention for this class is for the name of the error code to indicate the problem
- * that caused the error to be generated and for the error message to explain what is wrong and,
- * when appropriate, how the problem can be corrected.
- */
-class StaticTypeWarningCode extends Enum<StaticTypeWarningCode> implements ErrorCode {
/**
- * 12.7 Lists: A fresh instance (7.6.1) <i>a</i>, of size <i>n</i>, whose class implements the
- * built-in class <i>List&lt;E></i> is allocated.
- *
- * @param numTypeArgument the number of provided type arguments
+ * Hint to use the ~/ operator.
*/
- static const StaticTypeWarningCode EXPECTED_ONE_LIST_TYPE_ARGUMENTS = const StaticTypeWarningCode.con1('EXPECTED_ONE_LIST_TYPE_ARGUMENTS', 0, "List literal requires exactly one type arguments or none, but %d found");
+ static const HintCode DIVISION_OPTIMIZATION = const HintCode.con1('DIVISION_OPTIMIZATION', 6, "The operator x ~/ y is more efficient than (x / y).toInt()");
/**
- * 12.8 Maps: A fresh instance (7.6.1) <i>m</i>, of size <i>n</i>, whose class implements the
- * built-in class <i>Map&lt;K, V></i> is allocated.
- *
- * @param numTypeArgument the number of provided type arguments
+ * Hint for the `x is double` type checks.
*/
- static const StaticTypeWarningCode EXPECTED_TWO_MAP_TYPE_ARGUMENTS = const StaticTypeWarningCode.con1('EXPECTED_TWO_MAP_TYPE_ARGUMENTS', 1, "Map literal requires exactly two type arguments or none, but %d found");
+ static const HintCode IS_DOUBLE = const HintCode.con1('IS_DOUBLE', 7, "When compiled to JS, this test might return true when the left hand side is an int");
/**
- * 12.18 Assignment: Let <i>T</i> be the static type of <i>e<sub>1</sub></i>. It is a static type
- * warning if <i>T</i> does not have an accessible instance setter named <i>v=</i>.
- *
- * @see #UNDEFINED_SETTER
+ * Hint for the `x is int` type checks.
*/
- static const StaticTypeWarningCode INACCESSIBLE_SETTER = const StaticTypeWarningCode.con1('INACCESSIBLE_SETTER', 2, "");
+ static const HintCode IS_INT = const HintCode.con1('IS_INT', 8, "When compiled to JS, this test might return true when the left hand side is a double");
/**
- * 8.1.1 Inheritance and Overriding: However, if the above rules would cause multiple members
- * <i>m<sub>1</sub>, &hellip;, m<sub>k</sub></i> with the same name <i>n</i> that would be
- * inherited (because identically named members existed in several superinterfaces) then at most
- * one member is inherited.
- *
- * If the static types <i>T<sub>1</sub>, &hellip;, T<sub>k</sub></i> of the members
- * <i>m<sub>1</sub>, &hellip;, m<sub>k</sub></i> are not identical, then there must be a member
- * <i>m<sub>x</sub></i> such that <i>T<sub>x</sub> &lt;: T<sub>i</sub>, 1 &lt;= x &lt;= k</i> for
- * all <i>i, 1 &lt;= i &lt;= k</i>, or a static type warning occurs. The member that is inherited
- * is <i>m<sub>x</sub></i>, if it exists; otherwise:
- * * Let <i>numberOfPositionals</i>(<i>f</i>) denote the number of positional parameters of a
- * function <i>f</i>, and let <i>numberOfRequiredParams</i>(<i>f</i>) denote the number of
- * required parameters of a function <i>f</i>. Furthermore, let <i>s</i> denote the set of all
- * named parameters of the <i>m<sub>1</sub>, &hellip;, m<sub>k</sub></i>. Then let
- * * <i>h = max(numberOfPositionals(m<sub>i</sub>)),</i>
- * * <i>r = min(numberOfRequiredParams(m<sub>i</sub>)), for all <i>i</i>, 1 <= i <= k.</i>
- * If <i>r <= h</i> then <i>I</i> has a method named <i>n</i>, with <i>r</i> required parameters
- * of type <b>dynamic</b>, <i>h</i> positional parameters of type <b>dynamic</b>, named parameters
- * <i>s</i> of type <b>dynamic</b> and return type <b>dynamic</b>.
- * * Otherwise none of the members <i>m<sub>1</sub>, &hellip;, m<sub>k</sub></i> is inherited.
+ * Hint for the `x is! double` type checks.
*/
- static const StaticTypeWarningCode INCONSISTENT_METHOD_INHERITANCE = const StaticTypeWarningCode.con1('INCONSISTENT_METHOD_INHERITANCE', 3, "'%s' is inherited by at least two interfaces inconsistently, from %s");
+ static const HintCode IS_NOT_DOUBLE = const HintCode.con1('IS_NOT_DOUBLE', 9, "When compiled to JS, this test might return false when the left hand side is an int");
/**
- * 12.15.1 Ordinary Invocation: It is a static type warning if <i>T</i> does not have an
- * accessible (3.2) instance member named <i>m</i>.
- *
- * @param memberName the name of the static member
- * @see UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
+ * Hint for the `x is! int` type checks.
*/
- static const StaticTypeWarningCode INSTANCE_ACCESS_TO_STATIC_MEMBER = const StaticTypeWarningCode.con1('INSTANCE_ACCESS_TO_STATIC_MEMBER', 4, "Static member '%s' cannot be accessed using instance access");
+ static const HintCode IS_NOT_INT = const HintCode.con1('IS_NOT_INT', 10, "When compiled to JS, this test might return false when the left hand side is a double");
/**
- * 12.18 Assignment: It is a static type warning if the static type of <i>e</i> may not be
- * assigned to the static type of <i>v</i>. The static type of the expression <i>v = e</i> is the
- * static type of <i>e</i>.
- *
- * 12.18 Assignment: It is a static type warning if the static type of <i>e</i> may not be
- * assigned to the static type of <i>C.v</i>. The static type of the expression <i>C.v = e</i> is
- * the static type of <i>e</i>.
- *
- * 12.18 Assignment: Let <i>T</i> be the static type of <i>e<sub>1</sub></i>. It is a static type
- * warning if the static type of <i>e<sub>2</sub></i> may not be assigned to <i>T</i>.
+ * This hint is generated anywhere where the [StaticTypeWarningCode#INVALID_ASSIGNMENT]
+ * would have been generated, if we used propagated information for the warnings.
*
* @param rhsTypeName the name of the right hand side type
* @param lhsTypeName the name of the left hand side type
+ * @see StaticTypeWarningCode#INVALID_ASSIGNMENT
*/
- static const StaticTypeWarningCode INVALID_ASSIGNMENT = const StaticTypeWarningCode.con1('INVALID_ASSIGNMENT', 5, "A value of type '%s' cannot be assigned to a variable of type '%s'");
-
- /**
- * 12.15.1 Ordinary Invocation: An ordinary method invocation <i>i</i> has the form
- * <i>o.m(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub>n+1</sub>: a<sub>n+1</sub>, &hellip;
- * x<sub>n+k</sub>: a<sub>n+k</sub>)</i>.
- *
- * Let <i>T</i> be the static type of <i>o</i>. It is a static type warning if <i>T</i> does not
- * have an accessible instance member named <i>m</i>. If <i>T.m</i> exists, it is a static warning
- * if the type <i>F</i> of <i>T.m</i> may not be assigned to a function type. If <i>T.m</i> does
- * not exist, or if <i>F</i> is not a function type, the static type of <i>i</i> is dynamic.
- *
- * 12.15.3 Static Invocation: It is a static type warning if the type <i>F</i> of <i>C.m</i> may
- * not be assigned to a function type.
- *
- * 12.15.4 Super Invocation: A super method invocation <i>i</i> has the form
- * <i>super.m(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub>n+1</sub>: a<sub>n+1</sub>, &hellip;
- * x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. If <i>S.m</i> exists, it is a static warning if the type
- * <i>F</i> of <i>S.m</i> may not be assigned to a function type.
- *
- * @param nonFunctionIdentifier the name of the identifier that is not a function type
- */
- static const StaticTypeWarningCode INVOCATION_OF_NON_FUNCTION = const StaticTypeWarningCode.con1('INVOCATION_OF_NON_FUNCTION', 6, "'%s' is not a method");
-
- /**
- * 12.14.4 Function Expression Invocation: A function expression invocation <i>i</i> has the form
- * <i>e<sub>f</sub>(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub>n+1</sub>: a<sub>n+1</sub>,
- * &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>, where <i>e<sub>f</sub></i> is an expression.
- *
- * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub></i> may not be
- * assigned to a function type.
- */
- static const StaticTypeWarningCode INVOCATION_OF_NON_FUNCTION_EXPRESSION = const StaticTypeWarningCode.con1('INVOCATION_OF_NON_FUNCTION_EXPRESSION', 7, "Cannot invoke a non-function");
-
- /**
- * 12.20 Conditional: It is a static type warning if the type of <i>e<sub>1</sub></i> may not be
- * assigned to bool.
- *
- * 13.5 If: It is a static type warning if the type of the expression <i>b</i> may not be assigned
- * to bool.
- *
- * 13.7 While: It is a static type warning if the type of <i>e</i> may not be assigned to bool.
- *
- * 13.8 Do: It is a static type warning if the type of <i>e</i> cannot be assigned to bool.
- */
- static const StaticTypeWarningCode NON_BOOL_CONDITION = const StaticTypeWarningCode.con1('NON_BOOL_CONDITION', 8, "Conditions must have a static type of 'bool'");
+ static const HintCode INVALID_ASSIGNMENT = const HintCode.con1('INVALID_ASSIGNMENT', 11, "A value of type '%s' cannot be assigned to a variable of type '%s'");
/**
- * 13.15 Assert: It is a static type warning if the type of <i>e</i> may not be assigned to either
- * bool or () &rarr; bool
+ * Generate a hint for methods or functions that have a return type, but do not have a non-void
+ * return statement on all branches. At the end of methods or functions with no return, Dart
+ * implicitly returns `null`, avoiding these implicit returns is considered a best practice.
+ *
+ * @param returnType the name of the declared return type
*/
- static const StaticTypeWarningCode NON_BOOL_EXPRESSION = const StaticTypeWarningCode.con1('NON_BOOL_EXPRESSION', 9, "Assertions must be on either a 'bool' or '() -> bool'");
+ static const HintCode MISSING_RETURN = const HintCode.con2('MISSING_RETURN', 12, "This function declares a return type of '%s', but does not end with a return statement", "Either add a return statement or change the return type to 'void'");
/**
- * 12.28 Unary Expressions: The expression !<i>e</i> is equivalent to the expression
- * <i>e</i>?<b>false<b> : <b>true</b>.
- *
- * 12.20 Conditional: It is a static type warning if the type of <i>e<sub>1</sub></i> may not be
- * assigned to bool.
+ * A getter with the override annotation does not override an existing getter.
*/
- static const StaticTypeWarningCode NON_BOOL_NEGATION_EXPRESSION = const StaticTypeWarningCode.con1('NON_BOOL_NEGATION_EXPRESSION', 10, "Negation argument must have a static type of 'bool'");
+ static const HintCode OVERRIDE_ON_NON_OVERRIDING_GETTER = const HintCode.con1('OVERRIDE_ON_NON_OVERRIDING_GETTER', 13, "Getter does not override an inherited getter");
/**
- * 15.8 Parameterized Types: It is a static type warning if <i>A<sub>i</sub>, 1 &lt;= i &lt;=
- * n</i> does not denote a type in the enclosing lexical scope.
+ * A method with the override annotation does not override an existing method.
*/
- static const StaticTypeWarningCode NON_TYPE_AS_TYPE_ARGUMENT = const StaticTypeWarningCode.con1('NON_TYPE_AS_TYPE_ARGUMENT', 11, "The name '%s' is not a type and cannot be used as a parameterized type");
+ static const HintCode OVERRIDE_ON_NON_OVERRIDING_METHOD = const HintCode.con1('OVERRIDE_ON_NON_OVERRIDING_METHOD', 14, "Method does not override an inherited method");
/**
- * 13.11 Return: It is a static type warning if the type of <i>e</i> may not be assigned to the
- * declared return type of the immediately enclosing function.
- *
- * @param actualReturnType the return type as declared in the return statement
- * @param expectedReturnType the expected return type as defined by the method
- * @param methodName the name of the method
+ * A setter with the override annotation does not override an existing setter.
*/
- static const StaticTypeWarningCode RETURN_OF_INVALID_TYPE = const StaticTypeWarningCode.con1('RETURN_OF_INVALID_TYPE', 12, "The return type '%s' is not a '%s', as defined by the method '%s'");
+ static const HintCode OVERRIDE_ON_NON_OVERRIDING_SETTER = const HintCode.con1('OVERRIDE_ON_NON_OVERRIDING_SETTER', 15, "Setter does not override an inherited setter");
/**
- * 12.11 Instance Creation: It is a static type warning if any of the type arguments to a
- * constructor of a generic type <i>G</i> invoked by a new expression or a constant object
- * expression are not subtypes of the bounds of the corresponding formal type parameters of
- * <i>G</i>.
- *
- * 15.8 Parameterized Types: If <i>S</i> is the static type of a member <i>m</i> of <i>G</i>, then
- * the static type of the member <i>m</i> of <i>G&lt;A<sub>1</sub>, &hellip;,
- * A<sub>n</sub>&gt;</i> is <i>[A<sub>1</sub>, &hellip;, A<sub>n</sub>/T<sub>1</sub>, &hellip;,
- * T<sub>n</sub>]S</i> where <i>T<sub>1</sub>, &hellip;, T<sub>n</sub></i> are the formal type
- * parameters of <i>G</i>. Let <i>B<sub>i</sub></i> be the bounds of <i>T<sub>i</sub>, 1 &lt;= i
- * &lt;= n</i>. It is a static type warning if <i>A<sub>i</sub></i> is not a subtype of
- * <i>[A<sub>1</sub>, &hellip;, A<sub>n</sub>/T<sub>1</sub>, &hellip;,
- * T<sub>n</sub>]B<sub>i</sub>, 1 &lt;= i &lt;= n</i>.
- *
- * 7.6.2 Factories: It is a static type warning if any of the type arguments to <i>k'</i> are not
- * subtypes of the bounds of the corresponding formal type parameters of type.
+ * Hint for classes that override equals, but not hashCode.
*
- * @param boundedTypeName the name of the type used in the instance creation that should be
- * limited by the bound as specified in the class declaration
- * @param boundingTypeName the name of the bounding type
- * @see #TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND
+ * @param className the name of the current class
*/
- static const StaticTypeWarningCode TYPE_ARGUMENT_NOT_MATCHING_BOUNDS = const StaticTypeWarningCode.con1('TYPE_ARGUMENT_NOT_MATCHING_BOUNDS', 13, "'%s' does not extend '%s'");
+ static const HintCode OVERRIDE_EQUALS_BUT_NOT_HASH_CODE = const HintCode.con1('OVERRIDE_EQUALS_BUT_NOT_HASH_CODE', 16, "The class '%s' overrides 'operator==', but not 'get hashCode'");
/**
- * 10 Generics: It is a static type warning if a type parameter is a supertype of its upper bound.
- *
- * @param typeParameterName the name of the type parameter
- * @see #TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
+ * Type checks of the type `x is! Null` should be done with `x != null`.
*/
- static const StaticTypeWarningCode TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND = const StaticTypeWarningCode.con1('TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND', 14, "'%s' cannot be a supertype of its upper bound");
+ static const HintCode TYPE_CHECK_IS_NOT_NULL = const HintCode.con1('TYPE_CHECK_IS_NOT_NULL', 17, "Tests for non-null should be done with '!= null'");
/**
- * 12.15.3 Unqualified Invocation: If there exists a lexically visible declaration named
- * <i>id</i>, let <i>f<sub>id</sub></i> be the innermost such declaration. Then: [skip].
- * Otherwise, <i>f<sub>id</sub></i> is considered equivalent to the ordinary method invocation
- * <b>this</b>.<i>id</i>(<i>a<sub>1</sub></i>, ..., <i>a<sub>n</sub></i>, <i>x<sub>n+1</sub></i> :
- * <i>a<sub>n+1</sub></i>, ..., <i>x<sub>n+k</sub></i> : <i>a<sub>n+k</sub></i>).
- *
- * @param methodName the name of the method that is undefined
+ * Type checks of the type `x is Null` should be done with `x == null`.
*/
- static const StaticTypeWarningCode UNDEFINED_FUNCTION = const StaticTypeWarningCode.con1('UNDEFINED_FUNCTION', 15, "The function '%s' is not defined");
+ static const HintCode TYPE_CHECK_IS_NULL = const HintCode.con1('TYPE_CHECK_IS_NULL', 18, "Tests for null should be done with '== null'");
/**
- * 12.17 Getter Invocation: Let <i>T</i> be the static type of <i>e</i>. It is a static type
- * warning if <i>T</i> does not have a getter named <i>m</i>.
+ * This hint is generated anywhere where the [StaticTypeWarningCode#UNDEFINED_GETTER] or
+ * [StaticWarningCode#UNDEFINED_GETTER] would have been generated, if we used propagated
+ * information for the warnings.
*
* @param getterName the name of the getter
* @param enclosingType the name of the enclosing type where the getter is being looked for
+ * @see StaticTypeWarningCode#UNDEFINED_GETTER
+ * @see StaticWarningCode#UNDEFINED_GETTER
*/
- static const StaticTypeWarningCode UNDEFINED_GETTER = const StaticTypeWarningCode.con1('UNDEFINED_GETTER', 16, "There is no such getter '%s' in '%s'");
+ static const HintCode UNDEFINED_GETTER = const HintCode.con1('UNDEFINED_GETTER', 19, "There is no such getter '%s' in '%s'");
/**
- * 12.15.1 Ordinary Invocation: Let <i>T</i> be the static type of <i>o</i>. It is a static type
- * warning if <i>T</i> does not have an accessible instance member named <i>m</i>.
+ * This hint is generated anywhere where the [StaticTypeWarningCode#UNDEFINED_METHOD] would
+ * have been generated, if we used propagated information for the warnings.
*
* @param methodName the name of the method that is undefined
* @param typeName the resolved type name that the method lookup is happening on
+ * @see StaticTypeWarningCode#UNDEFINED_METHOD
*/
- static const StaticTypeWarningCode UNDEFINED_METHOD = const StaticTypeWarningCode.con1('UNDEFINED_METHOD', 17, "The method '%s' is not defined for the class '%s'");
+ static const HintCode UNDEFINED_METHOD = const HintCode.con1('UNDEFINED_METHOD', 20, "The method '%s' is not defined for the class '%s'");
/**
- * 12.18 Assignment: Evaluation of an assignment of the form
- * <i>e<sub>1</sub></i>[<i>e<sub>2</sub></i>] = <i>e<sub>3</sub></i> is equivalent to the
- * evaluation of the expression (a, i, e){a.[]=(i, e); return e;} (<i>e<sub>1</sub></i>,
- * <i>e<sub>2</sub></i>, <i>e<sub>2</sub></i>).
- *
- * 12.29 Assignable Expressions: An assignable expression of the form
- * <i>e<sub>1</sub></i>[<i>e<sub>2</sub></i>] is evaluated as a method invocation of the operator
- * method [] on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.
- *
- * 12.15.1 Ordinary Invocation: Let <i>T</i> be the static type of <i>o</i>. It is a static type
- * warning if <i>T</i> does not have an accessible instance member named <i>m</i>.
+ * This hint is generated anywhere where the [StaticTypeWarningCode#UNDEFINED_OPERATOR]
+ * would have been generated, if we used propagated information for the warnings.
*
* @param operator the name of the operator
* @param enclosingType the name of the enclosing type where the operator is being looked for
+ * @see StaticTypeWarningCode#UNDEFINED_OPERATOR
*/
- static const StaticTypeWarningCode UNDEFINED_OPERATOR = const StaticTypeWarningCode.con1('UNDEFINED_OPERATOR', 18, "There is no such operator '%s' in '%s'");
+ static const HintCode UNDEFINED_OPERATOR = const HintCode.con1('UNDEFINED_OPERATOR', 21, "There is no such operator '%s' in '%s'");
/**
- * 12.18 Assignment: Let <i>T</i> be the static type of <i>e<sub>1</sub></i>. It is a static type
- * warning if <i>T</i> does not have an accessible instance setter named <i>v=</i>.
+ * This hint is generated anywhere where the [StaticTypeWarningCode#UNDEFINED_SETTER] or
+ * [StaticWarningCode#UNDEFINED_SETTER] would have been generated, if we used propagated
+ * information for the warnings.
*
* @param setterName the name of the setter
* @param enclosingType the name of the enclosing type where the setter is being looked for
- * @see #INACCESSIBLE_SETTER
+ * @see StaticTypeWarningCode#UNDEFINED_SETTER
+ * @see StaticWarningCode#UNDEFINED_SETTER
*/
- static const StaticTypeWarningCode UNDEFINED_SETTER = const StaticTypeWarningCode.con1('UNDEFINED_SETTER', 19, "There is no such setter '%s' in '%s'");
+ static const HintCode UNDEFINED_SETTER = const HintCode.con1('UNDEFINED_SETTER', 22, "There is no such setter '%s' in '%s'");
/**
- * 12.15.4 Super Invocation: A super method invocation <i>i</i> has the form
- * <i>super.m(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub>n+1</sub>: a<sub>n+1</sub>, &hellip;
- * x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. It is a static type warning if <i>S</i> does not have an
- * accessible instance member named <i>m</i>.
- *
- * @param methodName the name of the method that is undefined
- * @param typeName the resolved type name that the method lookup is happening on
+ * Unnecessary cast.
*/
- static const StaticTypeWarningCode UNDEFINED_SUPER_METHOD = const StaticTypeWarningCode.con1('UNDEFINED_SUPER_METHOD', 20, "There is no such method '%s' in '%s'");
+ static const HintCode UNNECESSARY_CAST = const HintCode.con1('UNNECESSARY_CAST', 23, "Unnecessary cast");
/**
- * 12.15.1 Ordinary Invocation: It is a static type warning if <i>T</i> does not have an
- * accessible (3.2) instance member named <i>m</i>.
- *
- * This is a specialization of [INSTANCE_ACCESS_TO_STATIC_MEMBER] that is used when we are
- * able to find the name defined in a supertype. It exists to provide a more informative error
- * message.
+ * Unnecessary type checks, the result is always true.
*/
- static const StaticTypeWarningCode UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER = const StaticTypeWarningCode.con1('UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER', 21, "Static members from supertypes must be qualified by the name of the defining type");
+ static const HintCode UNNECESSARY_TYPE_CHECK_FALSE = const HintCode.con1('UNNECESSARY_TYPE_CHECK_FALSE', 24, "Unnecessary type check, the result is always false");
/**
- * 15.8 Parameterized Types: It is a static type warning if <i>G</i> is not a generic type with
- * exactly <i>n</i> type parameters.
+ * Unnecessary type checks, the result is always false.
+ */
+ static const HintCode UNNECESSARY_TYPE_CHECK_TRUE = const HintCode.con1('UNNECESSARY_TYPE_CHECK_TRUE', 25, "Unnecessary type check, the result is always true");
+
+ /**
+ * Unused imports are imports which are never not used.
+ */
+ static const HintCode UNUSED_IMPORT = const HintCode.con1('UNUSED_IMPORT', 26, "Unused import");
+
+ /**
+ * Hint for cases where the source expects a method or function to return a non-void result, but
+ * the method or function signature returns void.
*
- * @param typeName the name of the type being referenced (<i>G</i>)
- * @param parameterCount the number of type parameters that were declared
- * @param argumentCount the number of type arguments provided
- * @see CompileTimeErrorCode#CONST_WITH_INVALID_TYPE_PARAMETERS
- * @see CompileTimeErrorCode#NEW_WITH_INVALID_TYPE_PARAMETERS
+ * @param name the name of the method or function that returns void
*/
- static const StaticTypeWarningCode WRONG_NUMBER_OF_TYPE_ARGUMENTS = const StaticTypeWarningCode.con1('WRONG_NUMBER_OF_TYPE_ARGUMENTS', 22, "The type '%s' is declared with %d type parameters, but %d type arguments were given");
+ static const HintCode USE_OF_VOID_RESULT = const HintCode.con1('USE_OF_VOID_RESULT', 27, "The result of '%s' is being used, even though it is declared to be 'void'");
- static const List<StaticTypeWarningCode> values = const [
- EXPECTED_ONE_LIST_TYPE_ARGUMENTS,
- EXPECTED_TWO_MAP_TYPE_ARGUMENTS,
- INACCESSIBLE_SETTER,
- INCONSISTENT_METHOD_INHERITANCE,
- INSTANCE_ACCESS_TO_STATIC_MEMBER,
+ static const List<HintCode> values = const [
+ ARGUMENT_TYPE_NOT_ASSIGNABLE,
+ DEAD_CODE,
+ DEAD_CODE_CATCH_FOLLOWING_CATCH,
+ DEAD_CODE_ON_CATCH_SUBTYPE,
+ DEPRECATED_MEMBER_USE,
+ DUPLICATE_IMPORT,
+ DIVISION_OPTIMIZATION,
+ IS_DOUBLE,
+ IS_INT,
+ IS_NOT_DOUBLE,
+ IS_NOT_INT,
INVALID_ASSIGNMENT,
- INVOCATION_OF_NON_FUNCTION,
- INVOCATION_OF_NON_FUNCTION_EXPRESSION,
- NON_BOOL_CONDITION,
- NON_BOOL_EXPRESSION,
- NON_BOOL_NEGATION_EXPRESSION,
- NON_TYPE_AS_TYPE_ARGUMENT,
- RETURN_OF_INVALID_TYPE,
- TYPE_ARGUMENT_NOT_MATCHING_BOUNDS,
- TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND,
- UNDEFINED_FUNCTION,
+ MISSING_RETURN,
+ OVERRIDE_ON_NON_OVERRIDING_GETTER,
+ OVERRIDE_ON_NON_OVERRIDING_METHOD,
+ OVERRIDE_ON_NON_OVERRIDING_SETTER,
+ OVERRIDE_EQUALS_BUT_NOT_HASH_CODE,
+ TYPE_CHECK_IS_NOT_NULL,
+ TYPE_CHECK_IS_NULL,
UNDEFINED_GETTER,
UNDEFINED_METHOD,
UNDEFINED_OPERATOR,
UNDEFINED_SETTER,
- UNDEFINED_SUPER_METHOD,
- UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER,
- WRONG_NUMBER_OF_TYPE_ARGUMENTS];
+ UNNECESSARY_CAST,
+ UNNECESSARY_TYPE_CHECK_FALSE,
+ UNNECESSARY_TYPE_CHECK_TRUE,
+ UNUSED_IMPORT,
+ USE_OF_VOID_RESULT];
/**
* The template used to create the message to be displayed for this error.
@@ -2490,7 +2308,7 @@ class StaticTypeWarningCode extends Enum<StaticTypeWarningCode> implements Error
*
* @param message the message template used to create the message to be displayed for the error
*/
- const StaticTypeWarningCode.con1(String name, int ordinal, String message) : this.con2(name, ordinal, message, null);
+ const HintCode.con1(String name, int ordinal, String message) : this.con2(name, ordinal, message, null);
/**
* Initialize a newly created error code to have the given message and correction.
@@ -2498,65 +2316,99 @@ class StaticTypeWarningCode extends Enum<StaticTypeWarningCode> implements Error
* @param message the template used to create the message to be displayed for the error
* @param correction the template used to create the correction to be displayed for the error
*/
- const StaticTypeWarningCode.con2(String name, int ordinal, this.message, this.correction) : super(name, ordinal);
+ const HintCode.con2(String name, int ordinal, this.message, this.correction) : super(name, ordinal);
@override
- ErrorSeverity get errorSeverity => ErrorType.STATIC_TYPE_WARNING.severity;
+ ErrorSeverity get errorSeverity => ErrorType.HINT.severity;
@override
- ErrorType get type => ErrorType.STATIC_TYPE_WARNING;
+ ErrorType get type => ErrorType.HINT;
}
/**
- * The enumeration `AngularCode` defines Angular specific problems.
+ * The enumeration `HtmlWarningCode` defines the error codes used for warnings in HTML files.
+ * The convention for this class is for the name of the error code to indicate the problem that
+ * caused the error to be generated and for the error message to explain what is wrong and, when
+ * appropriate, how the problem can be corrected.
*/
-class AngularCode extends Enum<AngularCode> implements ErrorCode {
- static const AngularCode CANNOT_PARSE_SELECTOR = const AngularCode('CANNOT_PARSE_SELECTOR', 0, "The selector '%s' cannot be parsed");
+class HtmlWarningCode extends Enum<HtmlWarningCode> implements ErrorCode {
+ /**
+ * An error code indicating that the value of the 'src' attribute of a Dart script tag is not a
+ * valid URI.
+ *
+ * @param uri the URI that is invalid
+ */
+ static const HtmlWarningCode INVALID_URI = const HtmlWarningCode.con1('INVALID_URI', 0, "Invalid URI syntax: '%s'");
- static const AngularCode INVALID_FORMATTER_NAME = const AngularCode('INVALID_FORMATTER_NAME', 1, "Formatter name must be a simple identifier");
+ /**
+ * An error code indicating that the value of the 'src' attribute of a Dart script tag references
+ * a file that does not exist.
+ *
+ * @param uri the URI pointing to a non-existent file
+ */
+ static const HtmlWarningCode URI_DOES_NOT_EXIST = const HtmlWarningCode.con1('URI_DOES_NOT_EXIST', 1, "Target of URI does not exist: '%s'");
- static const AngularCode INVALID_PROPERTY_KIND = const AngularCode('INVALID_PROPERTY_KIND', 2, "Unknown property binding kind '%s', use one of the '@', '=>', '=>!' or '<=>'");
+ static const List<HtmlWarningCode> values = const [INVALID_URI, URI_DOES_NOT_EXIST];
- static const AngularCode INVALID_PROPERTY_FIELD = const AngularCode('INVALID_PROPERTY_FIELD', 3, "Unknown property field '%s'");
+ /**
+ * The template used to create the message to be displayed for this error.
+ */
+ final String message;
- static const AngularCode INVALID_PROPERTY_MAP = const AngularCode('INVALID_PROPERTY_MAP', 4, "Argument 'map' must be a constant map literal");
+ /**
+ * The template used to create the correction to be displayed for this error, or `null` if
+ * there is no correction information for this error.
+ */
+ final String correction;
- static const AngularCode INVALID_PROPERTY_NAME = const AngularCode('INVALID_PROPERTY_NAME', 5, "Property name must be a string literal");
+ /**
+ * Initialize a newly created error code to have the given message.
+ *
+ * @param message the message template used to create the message to be displayed for the error
+ */
+ const HtmlWarningCode.con1(String name, int ordinal, String message) : this.con2(name, ordinal, message, null);
- static const AngularCode INVALID_PROPERTY_SPEC = const AngularCode('INVALID_PROPERTY_SPEC', 6, "Property binding specification must be a string literal");
+ /**
+ * Initialize a newly created error code to have the given message and correction.
+ *
+ * @param message the template used to create the message to be displayed for the error
+ * @param correction the template used to create the correction to be displayed for the error
+ */
+ const HtmlWarningCode.con2(String name, int ordinal, this.message, this.correction) : super(name, ordinal);
+
+ @override
+ ErrorSeverity get errorSeverity => ErrorSeverity.WARNING;
- static const AngularCode INVALID_REPEAT_SYNTAX = const AngularCode('INVALID_REPEAT_SYNTAX', 7, "Expected statement in form '_item_ in _collection_ [tracked by _id_]'");
+ @override
+ ErrorType get type => ErrorType.STATIC_WARNING;
+}
- static const AngularCode INVALID_REPEAT_ITEM_SYNTAX = const AngularCode('INVALID_REPEAT_ITEM_SYNTAX', 8, "Item must by identifier or in '(_key_, _value_)' pair.");
+/**
+ * The enumeration `PolymerCode` defines Polymer specific problems.
+ */
+class PolymerCode extends Enum<PolymerCode> implements ErrorCode {
+ static const PolymerCode ATTRIBUTE_FIELD_NOT_PUBLISHED = const PolymerCode('ATTRIBUTE_FIELD_NOT_PUBLISHED', 0, "Field '%s' in '%s' must be @published");
- static const AngularCode INVALID_URI = const AngularCode('INVALID_URI', 9, "Invalid URI syntax: '%s'");
+ static const PolymerCode DUPLICATE_ATTRIBUTE_DEFINITION = const PolymerCode('DUPLICATE_ATTRIBUTE_DEFINITION', 1, "The attribute '%s' is already defined");
- static const AngularCode MISSING_FORMATTER_COLON = const AngularCode('MISSING_FORMATTER_COLON', 10, "Missing ':' before formatter argument");
+ static const PolymerCode EMPTY_ATTRIBUTES = const PolymerCode('EMPTY_ATTRIBUTES', 2, "Empty 'attributes' attribute is useless");
- static const AngularCode MISSING_NAME = const AngularCode('MISSING_NAME', 11, "Argument 'name' must be provided");
+ static const PolymerCode INVALID_ATTRIBUTE_NAME = const PolymerCode('INVALID_ATTRIBUTE_NAME', 3, "'%s' is not a valid name for a custom element attribute");
- static const AngularCode MISSING_PUBLISH_AS = const AngularCode('MISSING_PUBLISH_AS', 12, "Argument 'publishAs' must be provided");
+ static const PolymerCode INVALID_TAG_NAME = const PolymerCode('INVALID_TAG_NAME', 4, "'%s' is not a valid name for a custom element");
- static const AngularCode MISSING_SELECTOR = const AngularCode('MISSING_SELECTOR', 13, "Argument 'selector' must be provided");
+ static const PolymerCode MISSING_TAG_NAME = const PolymerCode('MISSING_TAG_NAME', 5, "Missing tag name of the custom element. Please include an attribute like name='your-tag-name'");
- static const AngularCode URI_DOES_NOT_EXIST = const AngularCode('URI_DOES_NOT_EXIST', 14, "Target of URI does not exist: '%s'");
+ static const PolymerCode UNDEFINED_ATTRIBUTE_FIELD = const PolymerCode('UNDEFINED_ATTRIBUTE_FIELD', 6, "There is no such field '%s' in '%s'");
- static const List<AngularCode> values = const [
- CANNOT_PARSE_SELECTOR,
- INVALID_FORMATTER_NAME,
- INVALID_PROPERTY_KIND,
- INVALID_PROPERTY_FIELD,
- INVALID_PROPERTY_MAP,
- INVALID_PROPERTY_NAME,
- INVALID_PROPERTY_SPEC,
- INVALID_REPEAT_SYNTAX,
- INVALID_REPEAT_ITEM_SYNTAX,
- INVALID_URI,
- MISSING_FORMATTER_COLON,
- MISSING_NAME,
- MISSING_PUBLISH_AS,
- MISSING_SELECTOR,
- URI_DOES_NOT_EXIST];
+ static const List<PolymerCode> values = const [
+ ATTRIBUTE_FIELD_NOT_PUBLISHED,
+ DUPLICATE_ATTRIBUTE_DEFINITION,
+ EMPTY_ATTRIBUTES,
+ INVALID_ATTRIBUTE_NAME,
+ INVALID_TAG_NAME,
+ MISSING_TAG_NAME,
+ UNDEFINED_ATTRIBUTE_FIELD];
/**
* The template used to create the message to be displayed for this error.
@@ -2568,7 +2420,7 @@ class AngularCode extends Enum<AngularCode> implements ErrorCode {
*
* @param message the message template used to create the message to be displayed for the error
*/
- const AngularCode(String name, int ordinal, this.message) : super(name, ordinal);
+ const PolymerCode(String name, int ordinal, this.message) : super(name, ordinal);
@override
String get correction => null;
@@ -2577,235 +2429,381 @@ class AngularCode extends Enum<AngularCode> implements ErrorCode {
ErrorSeverity get errorSeverity => ErrorSeverity.INFO;
@override
- ErrorType get type => ErrorType.ANGULAR;
+ ErrorType get type => ErrorType.POLYMER;
}
/**
- * The enumeration `HintCode` defines the hints and coding recommendations for best practices
- * which are not mentioned in the Dart Language Specification.
+ * The enumeration `PubSuggestionCode` defines the suggestions used for reporting deviations
+ * from pub best practices. The convention for this class is for the name of the bad practice to
+ * indicate the problem that caused the suggestion to be generated and for the message to explain
+ * what is wrong and, when appropriate, how the situation can be corrected.
*/
-class HintCode extends Enum<HintCode> implements ErrorCode {
+class PubSuggestionCode extends Enum<PubSuggestionCode> implements ErrorCode {
/**
- * This hint is generated anywhere where the
- * [StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE] would have been generated, if we used
- * propagated information for the warnings.
- *
- * @param actualType the name of the actual argument type
- * @param expectedType the name of the expected type
- * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
+ * It is a bad practice for a source file in a package "lib" directory hierarchy to traverse
+ * outside that directory hierarchy. For example, a source file in the "lib" directory should not
+ * contain a directive such as `import '../web/some.dart'` which references a file outside
+ * the lib directory.
*/
- static const HintCode ARGUMENT_TYPE_NOT_ASSIGNABLE = const HintCode.con1('ARGUMENT_TYPE_NOT_ASSIGNABLE', 0, "The argument type '%s' cannot be assigned to the parameter type '%s'");
+ static const PubSuggestionCode FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE = const PubSuggestionCode.con1('FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE', 0, "A file in the 'lib' directory hierarchy should not reference a file outside that hierarchy");
/**
- * Dead code is code that is never reached, this can happen for instance if a statement follows a
- * return statement.
+ * It is a bad practice for a source file ouside a package "lib" directory hierarchy to traverse
+ * into that directory hierarchy. For example, a source file in the "web" directory should not
+ * contain a directive such as `import '../lib/some.dart'` which references a file inside
+ * the lib directory.
*/
- static const HintCode DEAD_CODE = const HintCode.con1('DEAD_CODE', 1, "Dead code");
+ static const PubSuggestionCode FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE = const PubSuggestionCode.con1('FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE', 1, "A file outside the 'lib' directory hierarchy should not reference a file inside that hierarchy. Use a package: reference instead.");
/**
- * Dead code is code that is never reached. This case covers cases where the user has catch
- * clauses after `catch (e)` or `on Object catch (e)`.
+ * It is a bad practice for a package import to reference anything outside the given package, or
+ * more generally, it is bad practice for a package import to contain a "..". For example, a
+ * source file should not contain a directive such as `import 'package:foo/../some.dart'`.
*/
- static const HintCode DEAD_CODE_CATCH_FOLLOWING_CATCH = const HintCode.con1('DEAD_CODE_CATCH_FOLLOWING_CATCH', 2, "Dead code, catch clauses after a 'catch (e)' or an 'on Object catch (e)' are never reached");
+ static const PubSuggestionCode PACKAGE_IMPORT_CONTAINS_DOT_DOT = const PubSuggestionCode.con1('PACKAGE_IMPORT_CONTAINS_DOT_DOT', 2, "A package import should not contain '..'");
+
+ static const List<PubSuggestionCode> values = const [
+ FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE,
+ FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE,
+ PACKAGE_IMPORT_CONTAINS_DOT_DOT];
/**
- * Dead code is code that is never reached. This case covers cases where the user has an on-catch
- * clause such as `on A catch (e)`, where a supertype of `A` was already caught.
- *
- * @param subtypeName name of the subtype
- * @param supertypeName name of the supertype
+ * The template used to create the message to be displayed for this error.
*/
- static const HintCode DEAD_CODE_ON_CATCH_SUBTYPE = const HintCode.con1('DEAD_CODE_ON_CATCH_SUBTYPE', 3, "Dead code, this on-catch block will never be executed since '%s' is a subtype of '%s'");
+ final String message;
/**
- * Deprecated members should not be invoked or used.
+ * The template used to create the correction to be displayed for this error, or `null` if
+ * there is no correction information for this error.
+ */
+ final String correction;
+
+ /**
+ * Initialize a newly created error code to have the given message.
*
- * @param memberName the name of the member
+ * @param message the message template used to create the message to be displayed for the error
*/
- static const HintCode DEPRECATED_MEMBER_USE = const HintCode.con1('DEPRECATED_MEMBER_USE', 4, "'%s' is deprecated");
+ const PubSuggestionCode.con1(String name, int ordinal, String message) : this.con2(name, ordinal, message, null);
/**
- * Duplicate imports.
+ * Initialize a newly created error code to have the given message and correction.
+ *
+ * @param message the template used to create the message to be displayed for the error
+ * @param correction the template used to create the correction to be displayed for the error
*/
- static const HintCode DUPLICATE_IMPORT = const HintCode.con1('DUPLICATE_IMPORT', 5, "Duplicate import");
+ const PubSuggestionCode.con2(String name, int ordinal, this.message, this.correction) : super(name, ordinal);
+
+ @override
+ ErrorSeverity get errorSeverity => ErrorType.PUB_SUGGESTION.severity;
+
+ @override
+ ErrorType get type => ErrorType.PUB_SUGGESTION;
+}
+/**
+ * The enumeration `StaticTypeWarningCode` defines the error codes used for static type
+ * warnings. The convention for this class is for the name of the error code to indicate the problem
+ * that caused the error to be generated and for the error message to explain what is wrong and,
+ * when appropriate, how the problem can be corrected.
+ */
+class StaticTypeWarningCode extends Enum<StaticTypeWarningCode> implements ErrorCode {
/**
- * Hint to use the ~/ operator.
+ * 12.7 Lists: A fresh instance (7.6.1) <i>a</i>, of size <i>n</i>, whose class implements the
+ * built-in class <i>List&lt;E></i> is allocated.
+ *
+ * @param numTypeArgument the number of provided type arguments
*/
- static const HintCode DIVISION_OPTIMIZATION = const HintCode.con1('DIVISION_OPTIMIZATION', 6, "The operator x ~/ y is more efficient than (x / y).toInt()");
+ static const StaticTypeWarningCode EXPECTED_ONE_LIST_TYPE_ARGUMENTS = const StaticTypeWarningCode.con1('EXPECTED_ONE_LIST_TYPE_ARGUMENTS', 0, "List literal requires exactly one type arguments or none, but %d found");
/**
- * Hint for the `x is double` type checks.
+ * 12.8 Maps: A fresh instance (7.6.1) <i>m</i>, of size <i>n</i>, whose class implements the
+ * built-in class <i>Map&lt;K, V></i> is allocated.
+ *
+ * @param numTypeArgument the number of provided type arguments
*/
- static const HintCode IS_DOUBLE = const HintCode.con1('IS_DOUBLE', 7, "When compiled to JS, this test might return true when the left hand side is an int");
+ static const StaticTypeWarningCode EXPECTED_TWO_MAP_TYPE_ARGUMENTS = const StaticTypeWarningCode.con1('EXPECTED_TWO_MAP_TYPE_ARGUMENTS', 1, "Map literal requires exactly two type arguments or none, but %d found");
/**
- * Hint for the `x is int` type checks.
+ * 12.18 Assignment: Let <i>T</i> be the static type of <i>e<sub>1</sub></i>. It is a static type
+ * warning if <i>T</i> does not have an accessible instance setter named <i>v=</i>.
+ *
+ * @see #UNDEFINED_SETTER
*/
- static const HintCode IS_INT = const HintCode.con1('IS_INT', 8, "When compiled to JS, this test might return true when the left hand side is a double");
+ static const StaticTypeWarningCode INACCESSIBLE_SETTER = const StaticTypeWarningCode.con1('INACCESSIBLE_SETTER', 2, "");
/**
- * Hint for the `x is! double` type checks.
+ * 8.1.1 Inheritance and Overriding: However, if the above rules would cause multiple members
+ * <i>m<sub>1</sub>, &hellip;, m<sub>k</sub></i> with the same name <i>n</i> that would be
+ * inherited (because identically named members existed in several superinterfaces) then at most
+ * one member is inherited.
+ *
+ * If the static types <i>T<sub>1</sub>, &hellip;, T<sub>k</sub></i> of the members
+ * <i>m<sub>1</sub>, &hellip;, m<sub>k</sub></i> are not identical, then there must be a member
+ * <i>m<sub>x</sub></i> such that <i>T<sub>x</sub> &lt;: T<sub>i</sub>, 1 &lt;= x &lt;= k</i> for
+ * all <i>i, 1 &lt;= i &lt;= k</i>, or a static type warning occurs. The member that is inherited
+ * is <i>m<sub>x</sub></i>, if it exists; otherwise:
+ * * Let <i>numberOfPositionals</i>(<i>f</i>) denote the number of positional parameters of a
+ * function <i>f</i>, and let <i>numberOfRequiredParams</i>(<i>f</i>) denote the number of
+ * required parameters of a function <i>f</i>. Furthermore, let <i>s</i> denote the set of all
+ * named parameters of the <i>m<sub>1</sub>, &hellip;, m<sub>k</sub></i>. Then let
+ * * <i>h = max(numberOfPositionals(m<sub>i</sub>)),</i>
+ * * <i>r = min(numberOfRequiredParams(m<sub>i</sub>)), for all <i>i</i>, 1 <= i <= k.</i>
+ * If <i>r <= h</i> then <i>I</i> has a method named <i>n</i>, with <i>r</i> required parameters
+ * of type <b>dynamic</b>, <i>h</i> positional parameters of type <b>dynamic</b>, named parameters
+ * <i>s</i> of type <b>dynamic</b> and return type <b>dynamic</b>.
+ * * Otherwise none of the members <i>m<sub>1</sub>, &hellip;, m<sub>k</sub></i> is inherited.
*/
- static const HintCode IS_NOT_DOUBLE = const HintCode.con1('IS_NOT_DOUBLE', 9, "When compiled to JS, this test might return false when the left hand side is an int");
+ static const StaticTypeWarningCode INCONSISTENT_METHOD_INHERITANCE = const StaticTypeWarningCode.con1('INCONSISTENT_METHOD_INHERITANCE', 3, "'%s' is inherited by at least two interfaces inconsistently, from %s");
/**
- * Hint for the `x is! int` type checks.
+ * 12.15.1 Ordinary Invocation: It is a static type warning if <i>T</i> does not have an
+ * accessible (3.2) instance member named <i>m</i>.
+ *
+ * @param memberName the name of the static member
+ * @see UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
*/
- static const HintCode IS_NOT_INT = const HintCode.con1('IS_NOT_INT', 10, "When compiled to JS, this test might return false when the left hand side is a double");
+ static const StaticTypeWarningCode INSTANCE_ACCESS_TO_STATIC_MEMBER = const StaticTypeWarningCode.con1('INSTANCE_ACCESS_TO_STATIC_MEMBER', 4, "Static member '%s' cannot be accessed using instance access");
/**
- * This hint is generated anywhere where the [StaticTypeWarningCode#INVALID_ASSIGNMENT]
- * would have been generated, if we used propagated information for the warnings.
+ * 12.18 Assignment: It is a static type warning if the static type of <i>e</i> may not be
+ * assigned to the static type of <i>v</i>. The static type of the expression <i>v = e</i> is the
+ * static type of <i>e</i>.
+ *
+ * 12.18 Assignment: It is a static type warning if the static type of <i>e</i> may not be
+ * assigned to the static type of <i>C.v</i>. The static type of the expression <i>C.v = e</i> is
+ * the static type of <i>e</i>.
+ *
+ * 12.18 Assignment: Let <i>T</i> be the static type of <i>e<sub>1</sub></i>. It is a static type
+ * warning if the static type of <i>e<sub>2</sub></i> may not be assigned to <i>T</i>.
*
* @param rhsTypeName the name of the right hand side type
* @param lhsTypeName the name of the left hand side type
- * @see StaticTypeWarningCode#INVALID_ASSIGNMENT
*/
- static const HintCode INVALID_ASSIGNMENT = const HintCode.con1('INVALID_ASSIGNMENT', 11, "A value of type '%s' cannot be assigned to a variable of type '%s'");
+ static const StaticTypeWarningCode INVALID_ASSIGNMENT = const StaticTypeWarningCode.con1('INVALID_ASSIGNMENT', 5, "A value of type '%s' cannot be assigned to a variable of type '%s'");
/**
- * Generate a hint for methods or functions that have a return type, but do not have a non-void
- * return statement on all branches. At the end of methods or functions with no return, Dart
- * implicitly returns `null`, avoiding these implicit returns is considered a best practice.
+ * 12.15.1 Ordinary Invocation: An ordinary method invocation <i>i</i> has the form
+ * <i>o.m(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub>n+1</sub>: a<sub>n+1</sub>, &hellip;
+ * x<sub>n+k</sub>: a<sub>n+k</sub>)</i>.
*
- * @param returnType the name of the declared return type
+ * Let <i>T</i> be the static type of <i>o</i>. It is a static type warning if <i>T</i> does not
+ * have an accessible instance member named <i>m</i>. If <i>T.m</i> exists, it is a static warning
+ * if the type <i>F</i> of <i>T.m</i> may not be assigned to a function type. If <i>T.m</i> does
+ * not exist, or if <i>F</i> is not a function type, the static type of <i>i</i> is dynamic.
+ *
+ * 12.15.3 Static Invocation: It is a static type warning if the type <i>F</i> of <i>C.m</i> may
+ * not be assigned to a function type.
+ *
+ * 12.15.4 Super Invocation: A super method invocation <i>i</i> has the form
+ * <i>super.m(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub>n+1</sub>: a<sub>n+1</sub>, &hellip;
+ * x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. If <i>S.m</i> exists, it is a static warning if the type
+ * <i>F</i> of <i>S.m</i> may not be assigned to a function type.
+ *
+ * @param nonFunctionIdentifier the name of the identifier that is not a function type
*/
- static const HintCode MISSING_RETURN = const HintCode.con2('MISSING_RETURN', 12, "This function declares a return type of '%s', but does not end with a return statement", "Either add a return statement or change the return type to 'void'");
+ static const StaticTypeWarningCode INVOCATION_OF_NON_FUNCTION = const StaticTypeWarningCode.con1('INVOCATION_OF_NON_FUNCTION', 6, "'%s' is not a method");
/**
- * A getter with the override annotation does not override an existing getter.
+ * 12.14.4 Function Expression Invocation: A function expression invocation <i>i</i> has the form
+ * <i>e<sub>f</sub>(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub>n+1</sub>: a<sub>n+1</sub>,
+ * &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>, where <i>e<sub>f</sub></i> is an expression.
+ *
+ * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub></i> may not be
+ * assigned to a function type.
+ */
+ static const StaticTypeWarningCode INVOCATION_OF_NON_FUNCTION_EXPRESSION = const StaticTypeWarningCode.con1('INVOCATION_OF_NON_FUNCTION_EXPRESSION', 7, "Cannot invoke a non-function");
+
+ /**
+ * 12.20 Conditional: It is a static type warning if the type of <i>e<sub>1</sub></i> may not be
+ * assigned to bool.
+ *
+ * 13.5 If: It is a static type warning if the type of the expression <i>b</i> may not be assigned
+ * to bool.
+ *
+ * 13.7 While: It is a static type warning if the type of <i>e</i> may not be assigned to bool.
+ *
+ * 13.8 Do: It is a static type warning if the type of <i>e</i> cannot be assigned to bool.
+ */
+ static const StaticTypeWarningCode NON_BOOL_CONDITION = const StaticTypeWarningCode.con1('NON_BOOL_CONDITION', 8, "Conditions must have a static type of 'bool'");
+
+ /**
+ * 13.15 Assert: It is a static type warning if the type of <i>e</i> may not be assigned to either
+ * bool or () &rarr; bool
+ */
+ static const StaticTypeWarningCode NON_BOOL_EXPRESSION = const StaticTypeWarningCode.con1('NON_BOOL_EXPRESSION', 9, "Assertions must be on either a 'bool' or '() -> bool'");
+
+ /**
+ * 12.28 Unary Expressions: The expression !<i>e</i> is equivalent to the expression
+ * <i>e</i>?<b>false<b> : <b>true</b>.
+ *
+ * 12.20 Conditional: It is a static type warning if the type of <i>e<sub>1</sub></i> may not be
+ * assigned to bool.
*/
- static const HintCode OVERRIDE_ON_NON_OVERRIDING_GETTER = const HintCode.con1('OVERRIDE_ON_NON_OVERRIDING_GETTER', 13, "Getter does not override an inherited getter");
+ static const StaticTypeWarningCode NON_BOOL_NEGATION_EXPRESSION = const StaticTypeWarningCode.con1('NON_BOOL_NEGATION_EXPRESSION', 10, "Negation argument must have a static type of 'bool'");
/**
- * A method with the override annotation does not override an existing method.
+ * 15.8 Parameterized Types: It is a static type warning if <i>A<sub>i</sub>, 1 &lt;= i &lt;=
+ * n</i> does not denote a type in the enclosing lexical scope.
*/
- static const HintCode OVERRIDE_ON_NON_OVERRIDING_METHOD = const HintCode.con1('OVERRIDE_ON_NON_OVERRIDING_METHOD', 14, "Method does not override an inherited method");
+ static const StaticTypeWarningCode NON_TYPE_AS_TYPE_ARGUMENT = const StaticTypeWarningCode.con1('NON_TYPE_AS_TYPE_ARGUMENT', 11, "The name '%s' is not a type and cannot be used as a parameterized type");
/**
- * A setter with the override annotation does not override an existing setter.
+ * 13.11 Return: It is a static type warning if the type of <i>e</i> may not be assigned to the
+ * declared return type of the immediately enclosing function.
+ *
+ * @param actualReturnType the return type as declared in the return statement
+ * @param expectedReturnType the expected return type as defined by the method
+ * @param methodName the name of the method
*/
- static const HintCode OVERRIDE_ON_NON_OVERRIDING_SETTER = const HintCode.con1('OVERRIDE_ON_NON_OVERRIDING_SETTER', 15, "Setter does not override an inherited setter");
+ static const StaticTypeWarningCode RETURN_OF_INVALID_TYPE = const StaticTypeWarningCode.con1('RETURN_OF_INVALID_TYPE', 12, "The return type '%s' is not a '%s', as defined by the method '%s'");
/**
- * Hint for classes that override equals, but not hashCode.
+ * 12.11 Instance Creation: It is a static type warning if any of the type arguments to a
+ * constructor of a generic type <i>G</i> invoked by a new expression or a constant object
+ * expression are not subtypes of the bounds of the corresponding formal type parameters of
+ * <i>G</i>.
*
- * @param className the name of the current class
+ * 15.8 Parameterized Types: If <i>S</i> is the static type of a member <i>m</i> of <i>G</i>, then
+ * the static type of the member <i>m</i> of <i>G&lt;A<sub>1</sub>, &hellip;,
+ * A<sub>n</sub>&gt;</i> is <i>[A<sub>1</sub>, &hellip;, A<sub>n</sub>/T<sub>1</sub>, &hellip;,
+ * T<sub>n</sub>]S</i> where <i>T<sub>1</sub>, &hellip;, T<sub>n</sub></i> are the formal type
+ * parameters of <i>G</i>. Let <i>B<sub>i</sub></i> be the bounds of <i>T<sub>i</sub>, 1 &lt;= i
+ * &lt;= n</i>. It is a static type warning if <i>A<sub>i</sub></i> is not a subtype of
+ * <i>[A<sub>1</sub>, &hellip;, A<sub>n</sub>/T<sub>1</sub>, &hellip;,
+ * T<sub>n</sub>]B<sub>i</sub>, 1 &lt;= i &lt;= n</i>.
+ *
+ * 7.6.2 Factories: It is a static type warning if any of the type arguments to <i>k'</i> are not
+ * subtypes of the bounds of the corresponding formal type parameters of type.
+ *
+ * @param boundedTypeName the name of the type used in the instance creation that should be
+ * limited by the bound as specified in the class declaration
+ * @param boundingTypeName the name of the bounding type
+ * @see #TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND
*/
- static const HintCode OVERRIDE_EQUALS_BUT_NOT_HASH_CODE = const HintCode.con1('OVERRIDE_EQUALS_BUT_NOT_HASH_CODE', 16, "The class '%s' overrides 'operator==', but not 'get hashCode'");
+ static const StaticTypeWarningCode TYPE_ARGUMENT_NOT_MATCHING_BOUNDS = const StaticTypeWarningCode.con1('TYPE_ARGUMENT_NOT_MATCHING_BOUNDS', 13, "'%s' does not extend '%s'");
/**
- * Type checks of the type `x is! Null` should be done with `x != null`.
+ * 10 Generics: It is a static type warning if a type parameter is a supertype of its upper bound.
+ *
+ * @param typeParameterName the name of the type parameter
+ * @see #TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
*/
- static const HintCode TYPE_CHECK_IS_NOT_NULL = const HintCode.con1('TYPE_CHECK_IS_NOT_NULL', 17, "Tests for non-null should be done with '!= null'");
+ static const StaticTypeWarningCode TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND = const StaticTypeWarningCode.con1('TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND', 14, "'%s' cannot be a supertype of its upper bound");
/**
- * Type checks of the type `x is Null` should be done with `x == null`.
+ * 12.15.3 Unqualified Invocation: If there exists a lexically visible declaration named
+ * <i>id</i>, let <i>f<sub>id</sub></i> be the innermost such declaration. Then: [skip].
+ * Otherwise, <i>f<sub>id</sub></i> is considered equivalent to the ordinary method invocation
+ * <b>this</b>.<i>id</i>(<i>a<sub>1</sub></i>, ..., <i>a<sub>n</sub></i>, <i>x<sub>n+1</sub></i> :
+ * <i>a<sub>n+1</sub></i>, ..., <i>x<sub>n+k</sub></i> : <i>a<sub>n+k</sub></i>).
+ *
+ * @param methodName the name of the method that is undefined
*/
- static const HintCode TYPE_CHECK_IS_NULL = const HintCode.con1('TYPE_CHECK_IS_NULL', 18, "Tests for null should be done with '== null'");
+ static const StaticTypeWarningCode UNDEFINED_FUNCTION = const StaticTypeWarningCode.con1('UNDEFINED_FUNCTION', 15, "The function '%s' is not defined");
/**
- * This hint is generated anywhere where the [StaticTypeWarningCode#UNDEFINED_GETTER] or
- * [StaticWarningCode#UNDEFINED_GETTER] would have been generated, if we used propagated
- * information for the warnings.
+ * 12.17 Getter Invocation: Let <i>T</i> be the static type of <i>e</i>. It is a static type
+ * warning if <i>T</i> does not have a getter named <i>m</i>.
*
* @param getterName the name of the getter
* @param enclosingType the name of the enclosing type where the getter is being looked for
- * @see StaticTypeWarningCode#UNDEFINED_GETTER
- * @see StaticWarningCode#UNDEFINED_GETTER
*/
- static const HintCode UNDEFINED_GETTER = const HintCode.con1('UNDEFINED_GETTER', 19, "There is no such getter '%s' in '%s'");
+ static const StaticTypeWarningCode UNDEFINED_GETTER = const StaticTypeWarningCode.con1('UNDEFINED_GETTER', 16, "There is no such getter '%s' in '%s'");
/**
- * This hint is generated anywhere where the [StaticTypeWarningCode#UNDEFINED_METHOD] would
- * have been generated, if we used propagated information for the warnings.
+ * 12.15.1 Ordinary Invocation: Let <i>T</i> be the static type of <i>o</i>. It is a static type
+ * warning if <i>T</i> does not have an accessible instance member named <i>m</i>.
*
* @param methodName the name of the method that is undefined
* @param typeName the resolved type name that the method lookup is happening on
- * @see StaticTypeWarningCode#UNDEFINED_METHOD
*/
- static const HintCode UNDEFINED_METHOD = const HintCode.con1('UNDEFINED_METHOD', 20, "The method '%s' is not defined for the class '%s'");
+ static const StaticTypeWarningCode UNDEFINED_METHOD = const StaticTypeWarningCode.con1('UNDEFINED_METHOD', 17, "The method '%s' is not defined for the class '%s'");
/**
- * This hint is generated anywhere where the [StaticTypeWarningCode#UNDEFINED_OPERATOR]
- * would have been generated, if we used propagated information for the warnings.
+ * 12.18 Assignment: Evaluation of an assignment of the form
+ * <i>e<sub>1</sub></i>[<i>e<sub>2</sub></i>] = <i>e<sub>3</sub></i> is equivalent to the
+ * evaluation of the expression (a, i, e){a.[]=(i, e); return e;} (<i>e<sub>1</sub></i>,
+ * <i>e<sub>2</sub></i>, <i>e<sub>2</sub></i>).
+ *
+ * 12.29 Assignable Expressions: An assignable expression of the form
+ * <i>e<sub>1</sub></i>[<i>e<sub>2</sub></i>] is evaluated as a method invocation of the operator
+ * method [] on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.
+ *
+ * 12.15.1 Ordinary Invocation: Let <i>T</i> be the static type of <i>o</i>. It is a static type
+ * warning if <i>T</i> does not have an accessible instance member named <i>m</i>.
*
* @param operator the name of the operator
* @param enclosingType the name of the enclosing type where the operator is being looked for
- * @see StaticTypeWarningCode#UNDEFINED_OPERATOR
*/
- static const HintCode UNDEFINED_OPERATOR = const HintCode.con1('UNDEFINED_OPERATOR', 21, "There is no such operator '%s' in '%s'");
+ static const StaticTypeWarningCode UNDEFINED_OPERATOR = const StaticTypeWarningCode.con1('UNDEFINED_OPERATOR', 18, "There is no such operator '%s' in '%s'");
/**
- * This hint is generated anywhere where the [StaticTypeWarningCode#UNDEFINED_SETTER] or
- * [StaticWarningCode#UNDEFINED_SETTER] would have been generated, if we used propagated
- * information for the warnings.
+ * 12.18 Assignment: Let <i>T</i> be the static type of <i>e<sub>1</sub></i>. It is a static type
+ * warning if <i>T</i> does not have an accessible instance setter named <i>v=</i>.
*
* @param setterName the name of the setter
* @param enclosingType the name of the enclosing type where the setter is being looked for
- * @see StaticTypeWarningCode#UNDEFINED_SETTER
- * @see StaticWarningCode#UNDEFINED_SETTER
- */
- static const HintCode UNDEFINED_SETTER = const HintCode.con1('UNDEFINED_SETTER', 22, "There is no such setter '%s' in '%s'");
-
- /**
- * Unnecessary cast.
- */
- static const HintCode UNNECESSARY_CAST = const HintCode.con1('UNNECESSARY_CAST', 23, "Unnecessary cast");
-
- /**
- * Unnecessary type checks, the result is always true.
+ * @see #INACCESSIBLE_SETTER
*/
- static const HintCode UNNECESSARY_TYPE_CHECK_FALSE = const HintCode.con1('UNNECESSARY_TYPE_CHECK_FALSE', 24, "Unnecessary type check, the result is always false");
+ static const StaticTypeWarningCode UNDEFINED_SETTER = const StaticTypeWarningCode.con1('UNDEFINED_SETTER', 19, "There is no such setter '%s' in '%s'");
/**
- * Unnecessary type checks, the result is always false.
+ * 12.15.4 Super Invocation: A super method invocation <i>i</i> has the form
+ * <i>super.m(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub>n+1</sub>: a<sub>n+1</sub>, &hellip;
+ * x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. It is a static type warning if <i>S</i> does not have an
+ * accessible instance member named <i>m</i>.
+ *
+ * @param methodName the name of the method that is undefined
+ * @param typeName the resolved type name that the method lookup is happening on
*/
- static const HintCode UNNECESSARY_TYPE_CHECK_TRUE = const HintCode.con1('UNNECESSARY_TYPE_CHECK_TRUE', 25, "Unnecessary type check, the result is always true");
+ static const StaticTypeWarningCode UNDEFINED_SUPER_METHOD = const StaticTypeWarningCode.con1('UNDEFINED_SUPER_METHOD', 20, "There is no such method '%s' in '%s'");
/**
- * Unused imports are imports which are never not used.
+ * 12.15.1 Ordinary Invocation: It is a static type warning if <i>T</i> does not have an
+ * accessible (3.2) instance member named <i>m</i>.
+ *
+ * This is a specialization of [INSTANCE_ACCESS_TO_STATIC_MEMBER] that is used when we are
+ * able to find the name defined in a supertype. It exists to provide a more informative error
+ * message.
*/
- static const HintCode UNUSED_IMPORT = const HintCode.con1('UNUSED_IMPORT', 26, "Unused import");
+ static const StaticTypeWarningCode UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER = const StaticTypeWarningCode.con1('UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER', 21, "Static members from supertypes must be qualified by the name of the defining type");
/**
- * Hint for cases where the source expects a method or function to return a non-void result, but
- * the method or function signature returns void.
+ * 15.8 Parameterized Types: It is a static type warning if <i>G</i> is not a generic type with
+ * exactly <i>n</i> type parameters.
*
- * @param name the name of the method or function that returns void
+ * @param typeName the name of the type being referenced (<i>G</i>)
+ * @param parameterCount the number of type parameters that were declared
+ * @param argumentCount the number of type arguments provided
+ * @see CompileTimeErrorCode#CONST_WITH_INVALID_TYPE_PARAMETERS
+ * @see CompileTimeErrorCode#NEW_WITH_INVALID_TYPE_PARAMETERS
*/
- static const HintCode USE_OF_VOID_RESULT = const HintCode.con1('USE_OF_VOID_RESULT', 27, "The result of '%s' is being used, even though it is declared to be 'void'");
+ static const StaticTypeWarningCode WRONG_NUMBER_OF_TYPE_ARGUMENTS = const StaticTypeWarningCode.con1('WRONG_NUMBER_OF_TYPE_ARGUMENTS', 22, "The type '%s' is declared with %d type parameters, but %d type arguments were given");
- static const List<HintCode> values = const [
- ARGUMENT_TYPE_NOT_ASSIGNABLE,
- DEAD_CODE,
- DEAD_CODE_CATCH_FOLLOWING_CATCH,
- DEAD_CODE_ON_CATCH_SUBTYPE,
- DEPRECATED_MEMBER_USE,
- DUPLICATE_IMPORT,
- DIVISION_OPTIMIZATION,
- IS_DOUBLE,
- IS_INT,
- IS_NOT_DOUBLE,
- IS_NOT_INT,
+ static const List<StaticTypeWarningCode> values = const [
+ EXPECTED_ONE_LIST_TYPE_ARGUMENTS,
+ EXPECTED_TWO_MAP_TYPE_ARGUMENTS,
+ INACCESSIBLE_SETTER,
+ INCONSISTENT_METHOD_INHERITANCE,
+ INSTANCE_ACCESS_TO_STATIC_MEMBER,
INVALID_ASSIGNMENT,
- MISSING_RETURN,
- OVERRIDE_ON_NON_OVERRIDING_GETTER,
- OVERRIDE_ON_NON_OVERRIDING_METHOD,
- OVERRIDE_ON_NON_OVERRIDING_SETTER,
- OVERRIDE_EQUALS_BUT_NOT_HASH_CODE,
- TYPE_CHECK_IS_NOT_NULL,
- TYPE_CHECK_IS_NULL,
+ INVOCATION_OF_NON_FUNCTION,
+ INVOCATION_OF_NON_FUNCTION_EXPRESSION,
+ NON_BOOL_CONDITION,
+ NON_BOOL_EXPRESSION,
+ NON_BOOL_NEGATION_EXPRESSION,
+ NON_TYPE_AS_TYPE_ARGUMENT,
+ RETURN_OF_INVALID_TYPE,
+ TYPE_ARGUMENT_NOT_MATCHING_BOUNDS,
+ TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND,
+ UNDEFINED_FUNCTION,
UNDEFINED_GETTER,
UNDEFINED_METHOD,
UNDEFINED_OPERATOR,
UNDEFINED_SETTER,
- UNNECESSARY_CAST,
- UNNECESSARY_TYPE_CHECK_FALSE,
- UNNECESSARY_TYPE_CHECK_TRUE,
- UNUSED_IMPORT,
- USE_OF_VOID_RESULT];
+ UNDEFINED_SUPER_METHOD,
+ UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER,
+ WRONG_NUMBER_OF_TYPE_ARGUMENTS];
/**
* The template used to create the message to be displayed for this error.
@@ -2823,7 +2821,7 @@ class HintCode extends Enum<HintCode> implements ErrorCode {
*
* @param message the message template used to create the message to be displayed for the error
*/
- const HintCode.con1(String name, int ordinal, String message) : this.con2(name, ordinal, message, null);
+ const StaticTypeWarningCode.con1(String name, int ordinal, String message) : this.con2(name, ordinal, message, null);
/**
* Initialize a newly created error code to have the given message and correction.
@@ -2831,36 +2829,13 @@ class HintCode extends Enum<HintCode> implements ErrorCode {
* @param message the template used to create the message to be displayed for the error
* @param correction the template used to create the correction to be displayed for the error
*/
- const HintCode.con2(String name, int ordinal, this.message, this.correction) : super(name, ordinal);
-
- @override
- ErrorSeverity get errorSeverity => ErrorType.HINT.severity;
+ const StaticTypeWarningCode.con2(String name, int ordinal, this.message, this.correction) : super(name, ordinal);
@override
- ErrorType get type => ErrorType.HINT;
-}
-
-/**
- * Instances of the class `BooleanErrorListener` implement a listener that keeps track of
- * whether an error has been reported to it.
- */
-class BooleanErrorListener implements AnalysisErrorListener {
- /**
- * A flag indicating whether an error has been reported to this listener.
- */
- bool _errorReported = false;
-
- /**
- * Return `true` if an error has been reported to this listener.
- *
- * @return `true` if an error has been reported to this listener
- */
- bool get errorReported => _errorReported;
+ ErrorSeverity get errorSeverity => ErrorType.STATIC_TYPE_WARNING.severity;
@override
- void onError(AnalysisError error) {
- _errorReported = true;
- }
+ ErrorType get type => ErrorType.STATIC_TYPE_WARNING;
}
/**
@@ -3774,17 +3749,42 @@ class StaticWarningCode extends Enum<StaticWarningCode> implements ErrorCode {
}
/**
- * The enumeration `ErrorProperty` defines the properties that can be associated with an
- * [AnalysisError].
+ * The enumeration `TodoCode` defines the single TODO `ErrorCode`.
*/
-class ErrorProperty extends Enum<ErrorProperty> {
+class TodoCode extends Enum<TodoCode> implements ErrorCode {
/**
- * A property whose value is an array of [ExecutableElement] that should
- * be but are not implemented by a concrete class.
+ * The single enum of TodoCode.
*/
- static const ErrorProperty UNIMPLEMENTED_METHODS = const ErrorProperty('UNIMPLEMENTED_METHODS', 0);
+ static const TodoCode TODO = const TodoCode('TODO', 0);
- static const List<ErrorProperty> values = const [UNIMPLEMENTED_METHODS];
+ static const List<TodoCode> values = const [TODO];
- const ErrorProperty(String name, int ordinal) : super(name, ordinal);
+ /**
+ * This matches the two common Dart task styles
+ *
+ * * TODO:
+ * * TODO(username):
+ *
+ * As well as
+ * * TODO
+ *
+ * But not
+ * * todo
+ * * TODOS
+ */
+ static RegExp TODO_REGEX = new RegExp("([\\s/\\*])((TODO[^\\w\\d][^\\r\\n]*)|(TODO:?\$))");
+
+ const TodoCode(String name, int ordinal) : super(name, ordinal);
+
+ @override
+ String get correction => null;
+
+ @override
+ ErrorSeverity get errorSeverity => ErrorSeverity.INFO;
+
+ @override
+ String get message => "%s";
+
+ @override
+ ErrorType get type => ErrorType.TODO;
}
« no previous file with comments | « pkg/analyzer/lib/src/generated/element.dart ('k') | pkg/analyzer/lib/src/generated/html.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698