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

Unified Diff: pkg/analysis_services/test/refactoring/rename_class_member_test.dart

Issue 477383002: Checks for shadowing in 'Rename Class Member' refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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/analysis_services/lib/src/refactoring/rename_class_member.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_services/test/refactoring/rename_class_member_test.dart
diff --git a/pkg/analysis_services/test/refactoring/rename_class_member_test.dart b/pkg/analysis_services/test/refactoring/rename_class_member_test.dart
index 07811bd07f57cc0b8ad4b711334178b7d43f953e..f1b716304ea550223da333c9b0a0b4bec49f8629 100644
--- a/pkg/analysis_services/test/refactoring/rename_class_member_test.dart
+++ b/pkg/analysis_services/test/refactoring/rename_class_member_test.dart
@@ -9,7 +9,6 @@ import 'package:analysis_testing/reflective_tests.dart';
import 'package:unittest/unittest.dart';
import 'abstract_rename.dart';
-import 'package:analysis_services/correction/change.dart';
main() {
@@ -20,6 +19,226 @@ main() {
@ReflectiveTestCase()
class RenameClassMemberTest extends RenameRefactoringTest {
+ test_checkFinalConditions_OK_noShadow() {
+ indexTestUnit('''
+class A {
+ int newName;
+}
+class B {
+ test() {}
+}
+class C extends A {
+ main() {
+ print(newName);
+ }
+}
+''');
+ createRenameRefactoringAtString('test() {}');
+ // check status
+ refactoring.newName = 'newName';
+ return refactoring.checkFinalConditions().then((status) {
+ assertRefactoringStatusOK(status);
+ });
+ }
+
+ test_checkFinalConditions_hasMember_MethodElement() {
+ indexTestUnit('''
+class A {
+ test() {}
+ newName() {} // existing
+}
+''');
+ createRenameRefactoringAtString('test() {}');
+ // check status
+ refactoring.newName = 'newName';
+ return refactoring.checkFinalConditions().then((status) {
+ assertRefactoringStatus(
+ status,
+ RefactoringStatusSeverity.ERROR,
+ expectedMessage: "Class 'A' already declares method with name 'newName'.",
+ expectedContextSearch: 'newName() {} // existing');
+ });
+ }
+
+ test_checkFinalConditions_shadowed_byLocal_OK_qualifiedReference() {
+ indexTestUnit('''
+class A {
+ test() {}
+ main() {
+ var newName;
+ this.test(); // marker
+ }
+}
+''');
+ createRenameRefactoringAtString('test() {}');
+ // check status
+ refactoring.newName = 'newName';
+ return refactoring.checkFinalConditions().then((status) {
+ assertRefactoringStatusOK(status);
+ });
+ }
+
+ test_checkFinalConditions_shadowed_byLocal_OK_renamedNotUsed() {
+ indexTestUnit('''
+class A {
+ test() {}
+ main() {
+ var newName;
+ }
+}
+''');
+ createRenameRefactoringAtString('test() {}');
+ // check status
+ refactoring.newName = 'newName';
+ return refactoring.checkFinalConditions().then((status) {
+ assertRefactoringStatusOK(status);
+ });
+ }
+
+ test_checkFinalConditions_shadowed_byLocal_inSameClass() {
+ indexTestUnit('''
+class A {
+ test() {}
+ main() {
+ var newName;
+ test(); // marker
+ }
+}
+''');
+ createRenameRefactoringAtString('test() {}');
+ // check status
+ refactoring.newName = 'newName';
+ return refactoring.checkFinalConditions().then((status) {
+ assertRefactoringStatus(
+ status,
+ RefactoringStatusSeverity.ERROR,
+ expectedMessage:
+ "Usage of renamed method will be shadowed by local variable 'newName'.",
+ expectedContextSearch: 'test(); // marker');
+ });
+ }
+
+ test_checkFinalConditions_shadowed_byLocal_inSubClass() {
+ indexTestUnit('''
+class A {
+ test() {}
+}
+class B extends A {
+ main() {
+ var newName;
+ test(); // marker
+ }
+}
+''');
+ createRenameRefactoringAtString('test() {}');
+ // check status
+ refactoring.newName = 'newName';
+ return refactoring.checkFinalConditions().then((status) {
+ assertRefactoringStatus(
+ status,
+ RefactoringStatusSeverity.ERROR,
+ expectedMessage:
+ "Usage of renamed method will be shadowed by local variable 'newName'.",
+ expectedContextSearch: 'test(); // marker');
+ });
+ }
+
+ test_checkFinalConditions_shadowed_byParameter_inSameClass() {
+ indexTestUnit('''
+class A {
+ test() {}
+ main(newName) {
+ test(); // marker
+ }
+}
+''');
+ createRenameRefactoringAtString('test() {}');
+ // check status
+ refactoring.newName = 'newName';
+ return refactoring.checkFinalConditions().then((status) {
+ assertRefactoringStatus(
+ status,
+ RefactoringStatusSeverity.ERROR,
+ expectedMessage:
+ "Usage of renamed method will be shadowed by parameter 'newName'.",
+ expectedContextSearch: 'test(); // marker');
+ });
+ }
+
+ test_checkFinalConditions_shadowed_inSubClass() {
+ indexTestUnit('''
+class A {
+ newName() {} // marker
+}
+class B extends A {
+ test() {}
+ main() {
+ newName();
+ }
+}
+''');
+ createRenameRefactoringAtString('test() {}');
+ // check status
+ refactoring.newName = 'newName';
+ return refactoring.checkFinalConditions().then((status) {
+ assertRefactoringStatus(
+ status,
+ RefactoringStatusSeverity.ERROR,
+ expectedMessage: "Renamed method will shadow method 'A.newName'.",
+ expectedContextSearch: 'newName() {} // marker');
+ });
+ }
+
+ test_checkFinalConditions_shadowsSuper_MethodElement() {
+ indexTestUnit('''
+class A {
+ test() {}
+}
+class B extends A {
+ newName() {} // marker
+ main() {
+ test();
+ }
+}
+''');
+ createRenameRefactoringAtString('test() {}');
+ // check status
+ refactoring.newName = 'newName';
+ return refactoring.checkFinalConditions().then((status) {
+ assertRefactoringStatus(
+ status,
+ RefactoringStatusSeverity.ERROR,
+ expectedMessage: "Renamed method will be shadowed by method 'B.newName'.",
+ expectedContextSearch: 'newName() {} // marker');
+ });
+ }
+
+ test_checkFinalConditions_shadowsSuper_inSubClass_FieldElement() {
+ indexTestUnit('''
+class A {
+ int newName; // marker
+}
+class B extends A {
+ test() {}
+}
+class C extends B {
+ main() {
+ print(newName);
+ }
+}
+''');
+ createRenameRefactoringAtString('test() {}');
+ // check status
+ refactoring.newName = 'newName';
+ return refactoring.checkFinalConditions().then((status) {
+ assertRefactoringStatus(
+ status,
+ RefactoringStatusSeverity.ERROR,
+ expectedMessage: "Renamed method will shadow field 'A.newName'.",
+ expectedContextSearch: 'newName; // marker');
+ });
+ }
+
test_checkInitialConditions_operator() {
indexTestUnit('''
class A {
@@ -380,29 +599,6 @@ main(var a) {
});
}
- test_createChange_TypeParameterElement() {
- indexTestUnit('''
-class A<Test> {
- Test field;
- List<Test> items;
- Test method(Test p) => null;
-}
-''');
- // configure refactoring
- createRenameRefactoringAtString('Test> {');
- expect(refactoring.refactoringName, 'Rename Type Parameter');
- expect(refactoring.oldName, 'Test');
- refactoring.newName = 'NewName';
- // validate change
- return assertSuccessfulRename('''
-class A<NewName> {
- NewName field;
- List<NewName> items;
- NewName method(NewName p) => null;
-}
-''');
- }
-
test_createChange_PropertyAccessorElement_getter() {
indexTestUnit('''
class A {
@@ -512,4 +708,27 @@ main() {
}
''');
}
+
+ test_createChange_TypeParameterElement() {
+ indexTestUnit('''
+class A<Test> {
+ Test field;
+ List<Test> items;
+ Test method(Test p) => null;
+}
+''');
+ // configure refactoring
+ createRenameRefactoringAtString('Test> {');
+ expect(refactoring.refactoringName, 'Rename Type Parameter');
+ expect(refactoring.oldName, 'Test');
+ refactoring.newName = 'NewName';
+ // validate change
+ return assertSuccessfulRename('''
+class A<NewName> {
+ NewName field;
+ List<NewName> items;
+ NewName method(NewName p) => null;
+}
+''');
+ }
}
« no previous file with comments | « pkg/analysis_services/lib/src/refactoring/rename_class_member.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698