Allow using pseudo keywords for names in refactorings.
The specification does not diallow them (actually does not say anything
at all).
R=brianwilkerson@google.com, devoncarew@google.com
Bug: https://github.com/dart-lang/sdk/issues/32893
Change-Id: I963b01aaf123bbf51d74dfcad6daf82cdb911bea
Reviewed-on: https://dart-review.googlesource.com/53841
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/lib/src/services/refactoring/naming_conventions.dart b/pkg/analysis_server/lib/src/services/refactoring/naming_conventions.dart
index 7691fbb..199e929 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/naming_conventions.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/naming_conventions.dart
@@ -167,7 +167,7 @@
// keyword
{
Keyword keyword = Keyword.keywords[identifier];
- if (keyword != null) {
+ if (keyword != null && !keyword.isPseudo) {
String message = "$desc must not be a keyword.";
return new RefactoringStatus.fatal(message);
}
diff --git a/pkg/analysis_server/test/services/refactoring/naming_conventions_test.dart b/pkg/analysis_server/test/services/refactoring/naming_conventions_test.dart
index 736448b..5674877 100644
--- a/pkg/analysis_server/test/services/refactoring/naming_conventions_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/naming_conventions_test.dart
@@ -144,6 +144,12 @@
expectedMessage: "Field name must not be empty.");
}
+ void test_validateFieldName_keyword() {
+ assertRefactoringStatus(
+ validateFieldName("for"), RefactoringProblemSeverity.FATAL,
+ expectedMessage: "Field name must not be a keyword.");
+ }
+
void test_validateFieldName_leadingBlanks() {
assertRefactoringStatus(
validateFieldName(" newName"), RefactoringProblemSeverity.FATAL,
@@ -163,18 +169,6 @@
"Field name must begin with a lowercase letter or underscore.");
}
- void test_validateFieldName_notKeyword() {
- assertRefactoringStatus(
- validateFieldName("for"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Field name must not be a keyword.");
- }
-
- void test_validateFieldName_notPseudoKeyword() {
- assertRefactoringStatus(
- validateFieldName("await"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Field name must not be a keyword.");
- }
-
void test_validateFieldName_null() {
assertRefactoringStatus(
validateFieldName(null), RefactoringProblemSeverity.FATAL,
@@ -193,6 +187,10 @@
assertRefactoringStatusOK(validateFieldName("new_name"));
}
+ void test_validateFieldName_pseudoKeyword() {
+ assertRefactoringStatusOK(validateFieldName("await"));
+ }
+
void test_validateFieldName_trailingBlanks() {
assertRefactoringStatus(
validateFieldName("newName "), RefactoringProblemSeverity.FATAL,
@@ -211,6 +209,12 @@
expectedMessage: "Function name must not be empty.");
}
+ void test_validateFunctionName_keyword() {
+ assertRefactoringStatus(
+ validateFunctionName("new"), RefactoringProblemSeverity.FATAL,
+ expectedMessage: "Function name must not be a keyword.");
+ }
+
void test_validateFunctionName_leadingBlanks() {
assertRefactoringStatus(
validateFunctionName(" newName"), RefactoringProblemSeverity.FATAL,
@@ -230,18 +234,6 @@
"Function name must begin with a lowercase letter or underscore.");
}
- void test_validateFunctionName_notKeyword() {
- assertRefactoringStatus(
- validateFunctionName("new"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Function name must not be a keyword.");
- }
-
- void test_validateFunctionName_notPseudoKeyword() {
- assertRefactoringStatus(
- validateFunctionName("yield"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Function name must not be a keyword.");
- }
-
void test_validateFunctionName_null() {
assertRefactoringStatus(
validateFunctionName(null), RefactoringProblemSeverity.FATAL,
@@ -260,6 +252,10 @@
assertRefactoringStatusOK(validateFunctionName("new_name"));
}
+ void test_validateFunctionName_pseudoKeyword() {
+ assertRefactoringStatusOK(validateFunctionName("yield"));
+ }
+
void test_validateFunctionName_trailingBlanks() {
assertRefactoringStatus(
validateFunctionName("newName "), RefactoringProblemSeverity.FATAL,
@@ -339,6 +335,12 @@
assertRefactoringStatusOK(validateImportPrefixName(""));
}
+ void test_validateImportPrefixName_keyword() {
+ assertRefactoringStatus(
+ validateImportPrefixName("while"), RefactoringProblemSeverity.FATAL,
+ expectedMessage: "Import prefix name must not be a keyword.");
+ }
+
void test_validateImportPrefixName_leadingBlanks() {
assertRefactoringStatus(
validateImportPrefixName(" newName"), RefactoringProblemSeverity.FATAL,
@@ -359,18 +361,6 @@
"Import prefix name must begin with a lowercase letter or underscore.");
}
- void test_validateImportPrefixName_notKeyword() {
- assertRefactoringStatus(
- validateImportPrefixName("while"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Import prefix name must not be a keyword.");
- }
-
- void test_validateImportPrefixName_notPseudoKeyword() {
- assertRefactoringStatus(
- validateImportPrefixName("await"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Import prefix name must not be a keyword.");
- }
-
void test_validateImportPrefixName_null() {
assertRefactoringStatus(
validateImportPrefixName(null), RefactoringProblemSeverity.FATAL,
@@ -389,6 +379,10 @@
assertRefactoringStatusOK(validateImportPrefixName("new_name"));
}
+ void test_validateImportPrefixName_pseudoKeyword() {
+ assertRefactoringStatusOK(validateImportPrefixName("await"));
+ }
+
void test_validateImportPrefixName_trailingBlanks() {
assertRefactoringStatus(
validateImportPrefixName("newName "), RefactoringProblemSeverity.FATAL,
@@ -408,6 +402,12 @@
expectedMessage: "Label name must not be empty.");
}
+ void test_validateLabelName_keyword() {
+ assertRefactoringStatus(
+ validateLabelName("for"), RefactoringProblemSeverity.FATAL,
+ expectedMessage: "Label name must not be a keyword.");
+ }
+
void test_validateLabelName_leadingBlanks() {
assertRefactoringStatus(
validateLabelName(" newName"), RefactoringProblemSeverity.FATAL,
@@ -427,18 +427,6 @@
"Label name must begin with a lowercase letter or underscore.");
}
- void test_validateLabelName_notKeyword() {
- assertRefactoringStatus(
- validateLabelName("for"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Label name must not be a keyword.");
- }
-
- void test_validateLabelName_notPseudoKeyword() {
- assertRefactoringStatus(
- validateLabelName("await"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Label name must not be a keyword.");
- }
-
void test_validateLabelName_null() {
assertRefactoringStatus(
validateLabelName(null), RefactoringProblemSeverity.FATAL,
@@ -461,6 +449,10 @@
assertRefactoringStatusOK(validateLabelName("new_name"));
}
+ void test_validateLabelName_pseudoKeyword() {
+ assertRefactoringStatusOK(validateLabelName("await"));
+ }
+
void test_validateLabelName_trailingBlanks() {
assertRefactoringStatus(
validateLabelName("newName "), RefactoringProblemSeverity.FATAL,
@@ -493,6 +485,12 @@
"Library name should consist of lowercase identifier separated by dots.");
}
+ void test_validateLibraryName_keyword() {
+ assertRefactoringStatus(
+ validateLibraryName("my.for.name"), RefactoringProblemSeverity.FATAL,
+ expectedMessage: "Library name identifier must not be a keyword.");
+ }
+
void test_validateLibraryName_leadingBlanks() {
assertRefactoringStatus(
validateLibraryName("my. name"), RefactoringProblemSeverity.FATAL,
@@ -513,12 +511,6 @@
"Library name identifier must begin with a lowercase letter or underscore.");
}
- void test_validateLibraryName_notKeyword() {
- assertRefactoringStatus(
- validateLibraryName("my.yield.name"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Library name identifier must not be a keyword.");
- }
-
void test_validateLibraryName_null() {
assertRefactoringStatus(
validateLibraryName(null), RefactoringProblemSeverity.FATAL,
@@ -577,18 +569,6 @@
"Method name must begin with a lowercase letter or underscore.");
}
- void test_validateMethodName_notKeyword() {
- assertRefactoringStatus(
- validateMethodName("do"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Method name must not be a keyword.");
- }
-
- void test_validateMethodName_notPseudoKeyword() {
- assertRefactoringStatus(
- validateMethodName("yield"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Method name must not be a keyword.");
- }
-
void test_validateMethodName_null() {
assertRefactoringStatus(
validateMethodName(null), RefactoringProblemSeverity.FATAL,
@@ -607,12 +587,20 @@
assertRefactoringStatusOK(validateMethodName("new_name"));
}
+ void test_validateMethodName_pseudoKeyword() {
+ assertRefactoringStatusOK(validateMethodName("yield"));
+ }
+
void test_validateMethodName_trailingBlanks() {
assertRefactoringStatus(
validateMethodName("newName "), RefactoringProblemSeverity.FATAL,
expectedMessage: "Method name must not start or end with a blank.");
}
+ void test_validateParameterName_builtIn() {
+ assertRefactoringStatusOK(validateParameterName("await"));
+ }
+
void test_validateParameterName_doesNotStartWithLowerCase() {
assertRefactoringStatus(
validateParameterName("NewName"), RefactoringProblemSeverity.WARNING,
@@ -626,6 +614,12 @@
expectedMessage: "Parameter name must not be empty.");
}
+ void test_validateParameterName_keyword() {
+ assertRefactoringStatus(
+ validateParameterName("while"), RefactoringProblemSeverity.FATAL,
+ expectedMessage: "Parameter name must not be a keyword.");
+ }
+
void test_validateParameterName_leadingBlanks() {
assertRefactoringStatus(
validateParameterName(" newName"), RefactoringProblemSeverity.FATAL,
@@ -645,18 +639,6 @@
"Parameter name must begin with a lowercase letter or underscore.");
}
- void test_validateParameterName_notKeyword() {
- assertRefactoringStatus(
- validateParameterName("while"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Parameter name must not be a keyword.");
- }
-
- void test_validateParameterName_notPseudoKeyword() {
- assertRefactoringStatus(
- validateParameterName("await"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Parameter name must not be a keyword.");
- }
-
void test_validateParameterName_null() {
assertRefactoringStatus(
validateParameterName(null), RefactoringProblemSeverity.FATAL,
@@ -675,6 +657,10 @@
assertRefactoringStatusOK(validateParameterName("new_name"));
}
+ void test_validateParameterName_pseudoKeyword() {
+ assertRefactoringStatusOK(validateParameterName("await"));
+ }
+
void test_validateParameterName_trailingBlanks() {
assertRefactoringStatus(
validateParameterName("newName "), RefactoringProblemSeverity.FATAL,
@@ -693,6 +679,12 @@
expectedMessage: "Variable name must not be empty.");
}
+ void test_validateVariableName_keyword() {
+ assertRefactoringStatus(
+ validateVariableName("for"), RefactoringProblemSeverity.FATAL,
+ expectedMessage: "Variable name must not be a keyword.");
+ }
+
void test_validateVariableName_leadingBlanks() {
assertRefactoringStatus(
validateVariableName(" newName"), RefactoringProblemSeverity.FATAL,
@@ -712,18 +704,6 @@
"Variable name must begin with a lowercase letter or underscore.");
}
- void test_validateVariableName_notKeyword() {
- assertRefactoringStatus(
- validateVariableName("for"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Variable name must not be a keyword.");
- }
-
- void test_validateVariableName_notPseudoKeyword() {
- assertRefactoringStatus(
- validateVariableName("await"), RefactoringProblemSeverity.FATAL,
- expectedMessage: "Variable name must not be a keyword.");
- }
-
void test_validateVariableName_null() {
assertRefactoringStatus(
validateVariableName(null), RefactoringProblemSeverity.FATAL,
@@ -746,6 +726,10 @@
assertRefactoringStatusOK(validateVariableName("new_name"));
}
+ void test_validateVariableName_pseudoKeyword() {
+ assertRefactoringStatusOK(validateVariableName("await"));
+ }
+
void test_validateVariableName_trailingBlanks() {
assertRefactoringStatus(
validateVariableName("newName "), RefactoringProblemSeverity.FATAL,