| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.services.refactoring.rename_constructor; | 5 library test.services.refactoring.rename_constructor; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 8 import 'package:analysis_server/src/services/correction/status.dart'; | 8 import 'package:analysis_server/src/services/correction/status.dart'; |
| 9 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 9 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| 11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
| 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 13 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 14 | 14 |
| 15 import '../../utils.dart'; | 15 import '../../utils.dart'; |
| 16 import 'abstract_rename.dart'; | 16 import 'abstract_rename.dart'; |
| 17 | 17 |
| 18 main() { | 18 main() { |
| 19 initializeTestEnvironment(); | 19 initializeTestEnvironment(); |
| 20 defineReflectiveTests(RenameConstructorTest); | 20 defineReflectiveTests(RenameConstructorTest); |
| 21 } | 21 } |
| 22 | 22 |
| 23 @reflectiveTest | 23 @reflectiveTest |
| 24 class RenameConstructorTest extends RenameRefactoringTest { | 24 class RenameConstructorTest extends RenameRefactoringTest { |
| 25 test_checkFinalConditions_hasMember_constructor() async { | |
| 26 indexTestUnit(''' | |
| 27 class A { | |
| 28 A.test() {} | |
| 29 A.newName() {} // existing | |
| 30 } | |
| 31 '''); | |
| 32 _createConstructorDeclarationRefactoring('test() {}'); | |
| 33 // check status | |
| 34 refactoring.newName = 'newName'; | |
| 35 RefactoringStatus status = await refactoring.checkFinalConditions(); | |
| 36 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | |
| 37 expectedMessage: | |
| 38 "Class 'A' already declares constructor with name 'newName'.", | |
| 39 expectedContextSearch: 'newName() {} // existing'); | |
| 40 } | |
| 41 | |
| 42 test_checkFinalConditions_hasMember_method() async { | |
| 43 indexTestUnit(''' | |
| 44 class A { | |
| 45 A.test() {} | |
| 46 newName() {} // existing | |
| 47 } | |
| 48 '''); | |
| 49 _createConstructorDeclarationRefactoring('test() {}'); | |
| 50 // check status | |
| 51 refactoring.newName = 'newName'; | |
| 52 RefactoringStatus status = await refactoring.checkFinalConditions(); | |
| 53 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | |
| 54 expectedMessage: | |
| 55 "Class 'A' already declares method with name 'newName'.", | |
| 56 expectedContextSearch: 'newName() {} // existing'); | |
| 57 } | |
| 58 | |
| 59 test_checkInitialConditions_inSDK() async { | 25 test_checkInitialConditions_inSDK() async { |
| 60 indexTestUnit(''' | 26 indexTestUnit(''' |
| 61 main() { | 27 main() { |
| 62 new String.fromCharCodes([]); | 28 new String.fromCharCodes([]); |
| 63 } | 29 } |
| 64 '''); | 30 '''); |
| 65 createRenameRefactoringAtString('fromCharCodes('); | 31 createRenameRefactoringAtString('fromCharCodes('); |
| 66 // check status | 32 // check status |
| 67 refactoring.newName = 'newName'; | 33 refactoring.newName = 'newName'; |
| 68 RefactoringStatus status = await refactoring.checkInitialConditions(); | 34 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 91 expectedMessage: | 57 expectedMessage: |
| 92 "The new name must be different than the current name."); | 58 "The new name must be different than the current name."); |
| 93 // empty | 59 // empty |
| 94 refactoring.newName = ''; | 60 refactoring.newName = ''; |
| 95 assertRefactoringStatusOK(refactoring.checkNewName()); | 61 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 96 // OK | 62 // OK |
| 97 refactoring.newName = 'newName'; | 63 refactoring.newName = 'newName'; |
| 98 assertRefactoringStatusOK(refactoring.checkNewName()); | 64 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 99 } | 65 } |
| 100 | 66 |
| 67 test_checkNewName_hasMember_constructor() async { |
| 68 indexTestUnit(''' |
| 69 class A { |
| 70 A.test() {} |
| 71 A.newName() {} // existing |
| 72 } |
| 73 '''); |
| 74 _createConstructorDeclarationRefactoring('test() {}'); |
| 75 // check status |
| 76 refactoring.newName = 'newName'; |
| 77 RefactoringStatus status = refactoring.checkNewName(); |
| 78 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 79 expectedMessage: |
| 80 "Class 'A' already declares constructor with name 'newName'.", |
| 81 expectedContextSearch: 'newName() {} // existing'); |
| 82 } |
| 83 |
| 84 test_checkNewName_hasMember_method() async { |
| 85 indexTestUnit(''' |
| 86 class A { |
| 87 A.test() {} |
| 88 newName() {} // existing |
| 89 } |
| 90 '''); |
| 91 _createConstructorDeclarationRefactoring('test() {}'); |
| 92 // check status |
| 93 refactoring.newName = 'newName'; |
| 94 RefactoringStatus status = refactoring.checkNewName(); |
| 95 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 96 expectedMessage: |
| 97 "Class 'A' already declares method with name 'newName'.", |
| 98 expectedContextSearch: 'newName() {} // existing'); |
| 99 } |
| 100 |
| 101 test_createChange_add() { | 101 test_createChange_add() { |
| 102 indexTestUnit(''' | 102 indexTestUnit(''' |
| 103 class A { | 103 class A { |
| 104 A() {} // marker | 104 A() {} // marker |
| 105 } | 105 } |
| 106 class B extends A { | 106 class B extends A { |
| 107 B() : super() {} | 107 B() : super() {} |
| 108 factory B._() = A; | 108 factory B._() = A; |
| 109 } | 109 } |
| 110 main() { | 110 main() { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 search, (node) => node is ConstructorDeclaration); | 243 search, (node) => node is ConstructorDeclaration); |
| 244 createRenameRefactoringForElement(element); | 244 createRenameRefactoringForElement(element); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void _createConstructorInvocationRefactoring(String search) { | 247 void _createConstructorInvocationRefactoring(String search) { |
| 248 ConstructorElement element = findNodeElementAtString( | 248 ConstructorElement element = findNodeElementAtString( |
| 249 search, (node) => node is InstanceCreationExpression); | 249 search, (node) => node is InstanceCreationExpression); |
| 250 createRenameRefactoringForElement(element); | 250 createRenameRefactoringForElement(element); |
| 251 } | 251 } |
| 252 } | 252 } |
| OLD | NEW |