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

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

Issue 2487583002: Convert generic method errors to hints (Closed)
Patch Set: address comments Created 4 years, 1 month 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/error/error.dart ('k') | pkg/analyzer/lib/src/error/codes.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/error/hint_codes.dart
diff --git a/pkg/analyzer/lib/src/dart/error/hint_codes.dart b/pkg/analyzer/lib/src/dart/error/hint_codes.dart
index 011b8424a124fe708134c23b6e4e3910571330ba..d9914a2e844e0c0395690290b078fb635254b3e9 100644
--- a/pkg/analyzer/lib/src/dart/error/hint_codes.dart
+++ b/pkg/analyzer/lib/src/dart/error/hint_codes.dart
@@ -95,12 +95,6 @@ class HintCode extends ErrorCode {
"Try replacing the use of the deprecated member with the replacement.");
/**
- * Duplicate imports.
- */
- static const HintCode DUPLICATE_IMPORT = const HintCode('DUPLICATE_IMPORT',
- "Duplicate import.", "Try removing all but one import of the library.");
-
- /**
* Hint to use the ~/ operator.
*/
static const HintCode DIVISION_OPTIMIZATION = const HintCode(
@@ -109,40 +103,39 @@ class HintCode extends ErrorCode {
"Try re-writing the expression to use the '~/' operator.");
/**
- * Hint for the `x is double` type checks.
- */
- static const HintCode IS_DOUBLE = const HintCode(
- 'IS_DOUBLE',
- "When compiled to JS, this test might return true when the left hand "
- "side is an int.",
- "Try testing for 'num' instead.");
-
- /**
- * Hint for the `x is int` type checks.
+ * Duplicate imports.
*/
- static const HintCode IS_INT = const HintCode(
- 'IS_INT',
- "When compiled to JS, this test might return true when the left hand "
- "side is a double.",
- "Try testing for 'num' instead.");
+ static const HintCode DUPLICATE_IMPORT = const HintCode('DUPLICATE_IMPORT',
+ "Duplicate import.", "Try removing all but one import of the library.");
/**
- * Hint for the `x is! double` type checks.
+ * 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 IS_NOT_DOUBLE = const HintCode(
- 'IS_NOT_DOUBLE',
- "When compiled to JS, this test might return false when the left hand "
- "side is an int.",
- "Try testing for 'num' instead.");
+ static const HintCode FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE =
+ const HintCode(
+ 'FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE',
+ "A file in the 'lib' directory shouldn't import a file outside the "
+ "'lib' directory.",
+ "Try removing the import, or "
+ "moving the imported file inside the 'lib' directory.");
/**
- * Hint for the `x is! int` type checks.
+ * 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 IS_NOT_INT = const HintCode(
- 'IS_NOT_INT',
- "When compiled to JS, this test might return false when the left hand "
- "side is a double.",
- "Try testing for 'num' instead.");
+ static const HintCode FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE =
+ const HintCode(
+ 'FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE',
+ "A file outside the 'lib' directory shouldn't reference a file "
+ "inside the 'lib' directory using a relative path.",
+ "Try using a package: URI instead.");
/**
* Deferred libraries shouldn't define a top level function 'loadLibrary'.
@@ -199,6 +192,40 @@ class HintCode extends ErrorCode {
"Factory method '{0}' doesn't return a newly allocated object.");
/**
+ * Generic Method DEP: number of type parameters must match.
+ * <https://github.com/leafpetersen/dep-generic-methods/blob/master/proposal.md#function-subtyping>
+ *
+ * Parameters:
+ * 0: the number of type parameters in the method
+ * 1: the number of type parameters in the overridden method
+ * 2: the name of the class where the overridden method is declared
+ */
+ static const HintCode INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS =
+ const HintCode(
+ 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS',
+ "The method has {0} type parameters, but it is overriding a method "
+ "with {1} type parameters from '{2}'.",
+ "Try changing the number of type parameters so that they are the same.");
+
+ /**
+ * Generic Method DEP: bounds of type parameters must be compatible.
+ * <https://github.com/leafpetersen/dep-generic-methods/blob/master/proposal.md#function-subtyping>
+ *
+ * Parameters:
+ * 0: the type parameter name
+ * 1: the type parameter bound
+ * 2: the overridden type parameter name
+ * 3: the overridden type parameter bound
+ * 4: the name of the class where the overridden method is declared
+ */
+ static const HintCode INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND =
+ const HintCode(
+ 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND',
+ "The type parameter '{0}' extends '{1}', but that is stricter than "
+ "'{2}' extends '{3}' in the overridden method from '{4}'.",
+ "Try changing the bounds on the type parameters so that they are compatible.");
+
+ /**
* This hint is generated anywhere where a member annotated with `@protected`
* is used outside an instance member of a subclass.
*
@@ -212,6 +239,52 @@ class HintCode extends ErrorCode {
"of '{1}'.");
/**
+ * Hint for the `x is double` type checks.
+ */
+ static const HintCode IS_DOUBLE = const HintCode(
+ 'IS_DOUBLE',
+ "When compiled to JS, this test might return true when the left hand "
+ "side is an int.",
+ "Try testing for 'num' instead.");
+
+ /**
+ * Hint for the `x is int` type checks.
+ */
+ static const HintCode IS_INT = const HintCode(
+ 'IS_INT',
+ "When compiled to JS, this test might return true when the left hand "
+ "side is a double.",
+ "Try testing for 'num' instead.");
+
+ /**
+ * Hint for the `x is! double` type checks.
+ */
+ static const HintCode IS_NOT_DOUBLE = const HintCode(
+ 'IS_NOT_DOUBLE',
+ "When compiled to JS, this test might return false when the left hand "
+ "side is an int.",
+ "Try testing for 'num' instead.");
+
+ /**
+ * Hint for the `x is! int` type checks.
+ */
+ static const HintCode IS_NOT_INT = const HintCode(
+ 'IS_NOT_INT',
+ "When compiled to JS, this test might return false when the left hand "
+ "side is a double.",
+ "Try testing for 'num' instead.");
+
+ /**
+ * Generate a hint for an element that is annotated with `@JS(...)` whose
+ * library declaration is not similarly annotated.
+ */
+ static const HintCode MISSING_JS_LIB_ANNOTATION = const HintCode(
+ 'MISSING_JS_LIB_ANNOTATION',
+ "The @JS() annotation can only be used if it is also declared on the "
+ "library directive.",
+ "Try adding the annotation to the library directive.");
+
+ /**
* Generate a hint for a constructor, function or method invocation where a
* required parameter is missing.
*
@@ -234,16 +307,6 @@ class HintCode extends ErrorCode {
"The parameter '{0}' is required. {1}.");
/**
- * Generate a hint for an element that is annotated with `@JS(...)` whose
- * library declaration is not similarly annotated.
- */
- static const HintCode MISSING_JS_LIB_ANNOTATION = const HintCode(
- 'MISSING_JS_LIB_ANNOTATION',
- "The @JS() annotation can only be used if it is also declared on the "
- "library directive.",
- "Try adding the annotation to the library directive.");
-
- /**
* 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
@@ -282,6 +345,17 @@ class HintCode extends ErrorCode {
"necessary.");
/**
+ * Hint for classes that override equals, but not hashCode.
+ *
+ * Parameters:
+ * 0: the name of the current class
+ */
+ static const HintCode OVERRIDE_EQUALS_BUT_NOT_HASH_CODE = const HintCode(
+ 'OVERRIDE_EQUALS_BUT_NOT_HASH_CODE',
+ "The class '{0}' overrides 'operator==', but not 'get hashCode'.",
+ "Try implementing 'hashCode'.");
+
+ /**
* A getter with the override annotation does not override an existing getter.
*/
static const HintCode OVERRIDE_ON_NON_OVERRIDING_GETTER = const HintCode(
@@ -318,15 +392,14 @@ class HintCode extends ErrorCode {
"removing the override annotation.");
/**
- * Hint for classes that override equals, but not hashCode.
- *
- * Parameters:
- * 0: the name of the current class
+ * 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 OVERRIDE_EQUALS_BUT_NOT_HASH_CODE = const HintCode(
- 'OVERRIDE_EQUALS_BUT_NOT_HASH_CODE',
- "The class '{0}' overrides 'operator==', but not 'get hashCode'.",
- "Try implementing 'hashCode'.");
+ static const HintCode PACKAGE_IMPORT_CONTAINS_DOT_DOT = const HintCode(
+ 'PACKAGE_IMPORT_CONTAINS_DOT_DOT',
+ "A package import shouldn't contain '..'.");
/**
* Type checks of the type `x is! Null` should be done with `x != null`.
@@ -450,6 +523,25 @@ class HintCode extends ErrorCode {
"Try correcting the type check, or removing the type check.");
/**
+ * Unused catch exception variables.
+ */
+ static const HintCode UNUSED_CATCH_CLAUSE = const HintCode(
+ 'UNUSED_CATCH_CLAUSE',
+ "The exception variable '{0}' isn't used, so the 'catch' clause can be removed.",
+ // TODO(brianwilkerson) Split this error code so that we can differentiate
+ // between removing the catch clause and replacing the catch clause with
+ // an on clause.
+ "Try removing the catch clause.");
+
+ /**
+ * Unused catch stack trace variables.
+ */
+ static const HintCode UNUSED_CATCH_STACK = const HintCode(
+ 'UNUSED_CATCH_STACK',
+ "The stack trace variable '{0}' isn't used and can be removed.",
+ "Try removing the stack trace variable, or using it.");
+
+ /**
* See [Modifier.IS_USED_IN_LIBRARY].
*/
static const HintCode UNUSED_ELEMENT = const HintCode('UNUSED_ELEMENT',
@@ -470,25 +562,6 @@ class HintCode extends ErrorCode {
'UNUSED_IMPORT', "Unused import.", "Try removing the import directive.");
/**
- * Unused catch exception variables.
- */
- static const HintCode UNUSED_CATCH_CLAUSE = const HintCode(
- 'UNUSED_CATCH_CLAUSE',
- "The exception variable '{0}' isn't used, so the 'catch' clause can be removed.",
- // TODO(brianwilkerson) Split this error code so that we can differentiate
- // between removing the catch clause and replacing the catch clause with
- // an on clause.
- "Try removing the catch clause.");
-
- /**
- * Unused catch stack trace variables.
- */
- static const HintCode UNUSED_CATCH_STACK = const HintCode(
- 'UNUSED_CATCH_STACK',
- "The stack trace variable '{0}' isn't used and can be removed.",
- "Try removing the stack trace variable, or using it.");
-
- /**
* Unused local variables are local variables which are never read.
*/
static const HintCode UNUSED_LOCAL_VARIABLE = const HintCode(
@@ -516,43 +589,20 @@ class HintCode extends ErrorCode {
"The result of '{0}' is being used, even though it is declared to be 'void'.");
/**
- * 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 FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE =
- const HintCode(
- 'FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE',
- "A file in the 'lib' directory shouldn't import a file outside the "
- "'lib' directory.",
- "Try removing the import, or "
- "moving the imported file inside the 'lib' directory.");
-
- /**
- * 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 FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE =
- const HintCode(
- 'FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE',
- "A file outside the 'lib' directory shouldn't reference a file "
- "inside the 'lib' directory using a relative path.",
- "Try using a package: URI instead.");
-
- /**
- * 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 PACKAGE_IMPORT_CONTAINS_DOT_DOT = const HintCode(
- 'PACKAGE_IMPORT_CONTAINS_DOT_DOT',
- "A package import shouldn't contain '..'.");
+ * It will be a static type warning if <i>m</i> is not a generic method with
+ * exactly <i>n</i> type parameters.
+ *
+ * Parameters:
+ * 0: the name of the method being referenced (<i>G</i>)
+ * 1: the number of type parameters that were declared
+ * 2: the number of type arguments provided
+ */
+ static const HintCode WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD =
+ const HintCode(
+ 'WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD',
+ "The method '{0}' is declared with {1} type parameters, "
+ "but {2} type arguments were given.",
+ "Try adjusting the number of type arguments.");
/**
* Initialize a newly created error code to have the given [name]. The message
« no previous file with comments | « pkg/analyzer/lib/error/error.dart ('k') | pkg/analyzer/lib/src/error/codes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698