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

Unified Diff: pkg/analysis_server/lib/src/services/refactoring/rename_constructor.dart

Issue 2399533003: Issue 27475. Discourage users from naming constructors the same as the enclosing classes. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/rename_constructor_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/refactoring/rename_constructor.dart
diff --git a/pkg/analysis_server/lib/src/services/refactoring/rename_constructor.dart b/pkg/analysis_server/lib/src/services/refactoring/rename_constructor.dart
index 72a29ce323a346248f8a25f84b744ccde1e2ff1e..80fd4b1d09a3cec82927651aee2c0036facb4a98 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/rename_constructor.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/rename_constructor.dart
@@ -40,7 +40,6 @@ class RenameConstructorRefactoringImpl extends RenameRefactoringImpl {
@override
Future<RefactoringStatus> checkFinalConditions() {
RefactoringStatus result = new RefactoringStatus();
- _analyzePossibleConflicts(result);
return new Future.value(result);
}
@@ -48,6 +47,9 @@ class RenameConstructorRefactoringImpl extends RenameRefactoringImpl {
RefactoringStatus checkNewName() {
RefactoringStatus result = super.checkNewName();
result.addStatus(validateConstructorName(newName));
+ if (newName != null) {
+ _analyzePossibleConflicts(result);
+ }
return result;
}
@@ -70,8 +72,13 @@ class RenameConstructorRefactoringImpl extends RenameRefactoringImpl {
}
void _analyzePossibleConflicts(RefactoringStatus result) {
- // check if there are members with "newName" in the same ClassElement
ClassElement parentClass = element.enclosingElement;
+ // Check if the "newName" is the name of the enclosing class.
+ if (parentClass.name == newName) {
+ result.addError('The constructor should not have the same name '
+ 'as the name of the enclosing class.');
+ }
+ // check if there are members with "newName" in the same ClassElement
for (Element newNameMember in getChildren(parentClass, newName)) {
String message = format(
"Class '{0}' already declares {1} with name '{2}'.",
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/rename_constructor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698