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 services.src.refactoring.rename_constructor; | 5 library services.src.refactoring.rename_constructor; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/src/protocol_server.dart' hide Element; | 9 import 'package:analysis_server/src/protocol_server.dart' hide Element; |
10 import 'package:analysis_server/src/services/correction/source_range.dart'; | 10 import 'package:analysis_server/src/services/correction/source_range.dart'; |
11 import 'package:analysis_server/src/services/correction/status.dart'; | 11 import 'package:analysis_server/src/services/correction/status.dart'; |
12 import 'package:analysis_server/src/services/correction/util.dart'; | 12 import 'package:analysis_server/src/services/correction/util.dart'; |
13 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart
'; | 13 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart
'; |
14 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 14 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
15 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da
rt'; | 15 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da
rt'; |
16 import 'package:analysis_server/src/services/refactoring/rename.dart'; | 16 import 'package:analysis_server/src/services/refactoring/rename.dart'; |
17 import 'package:analysis_server/src/services/search/hierarchy.dart'; | 17 import 'package:analysis_server/src/services/search/hierarchy.dart'; |
18 import 'package:analysis_server/src/services/search/search_engine.dart'; | 18 import 'package:analysis_server/src/services/search/search_engine.dart'; |
19 import 'package:analyzer/src/generated/element.dart'; | 19 import 'package:analyzer/src/generated/element.dart'; |
20 import 'package:analyzer/src/generated/java_core.dart'; | 20 import 'package:analyzer/src/generated/java_core.dart'; |
21 import 'package:analyzer/src/generated/source.dart'; | 21 import 'package:analyzer/src/generated/source.dart'; |
22 | 22 |
23 | |
24 /** | 23 /** |
25 * A [Refactoring] for renaming [ConstructorElement]s. | 24 * A [Refactoring] for renaming [ConstructorElement]s. |
26 */ | 25 */ |
27 class RenameConstructorRefactoringImpl extends RenameRefactoringImpl { | 26 class RenameConstructorRefactoringImpl extends RenameRefactoringImpl { |
28 RenameConstructorRefactoringImpl(SearchEngine searchEngine, | 27 RenameConstructorRefactoringImpl( |
29 ConstructorElement element) | 28 SearchEngine searchEngine, ConstructorElement element) |
30 : super(searchEngine, element); | 29 : super(searchEngine, element); |
31 | 30 |
32 @override | 31 @override |
33 ConstructorElement get element => super.element as ConstructorElement; | 32 ConstructorElement get element => super.element as ConstructorElement; |
34 | 33 |
35 @override | 34 @override |
36 String get refactoringName { | 35 String get refactoringName { |
37 return "Rename Constructor"; | 36 return "Rename Constructor"; |
38 } | 37 } |
39 | 38 |
(...skipping 26 matching lines...) Expand all Loading... |
66 } | 65 } |
67 } | 66 } |
68 } | 67 } |
69 | 68 |
70 void _analyzePossibleConflicts(RefactoringStatus result) { | 69 void _analyzePossibleConflicts(RefactoringStatus result) { |
71 // check if there are members with "newName" in the same ClassElement | 70 // check if there are members with "newName" in the same ClassElement |
72 ClassElement parentClass = element.enclosingElement; | 71 ClassElement parentClass = element.enclosingElement; |
73 for (Element newNameMember in getChildren(parentClass, newName)) { | 72 for (Element newNameMember in getChildren(parentClass, newName)) { |
74 String message = format( | 73 String message = format( |
75 "Class '{0}' already declares {1} with name '{2}'.", | 74 "Class '{0}' already declares {1} with name '{2}'.", |
76 parentClass.displayName, | 75 parentClass.displayName, getElementKindName(newNameMember), newName); |
77 getElementKindName(newNameMember), | |
78 newName); | |
79 result.addError(message, newLocation_fromElement(newNameMember)); | 76 result.addError(message, newLocation_fromElement(newNameMember)); |
80 } | 77 } |
81 } | 78 } |
82 | 79 |
83 SourceReference _createDeclarationReference() { | 80 SourceReference _createDeclarationReference() { |
84 SourceRange sourceRange; | 81 SourceRange sourceRange; |
85 if (element.periodOffset != null) { | 82 if (element.periodOffset != null) { |
86 sourceRange = rangeStartEnd(element.periodOffset, element.nameEnd); | 83 sourceRange = rangeStartEnd(element.periodOffset, element.nameEnd); |
87 } else { | 84 } else { |
88 sourceRange = rangeStartLength(element.nameEnd, 0); | 85 sourceRange = rangeStartLength(element.nameEnd, 0); |
89 } | 86 } |
90 String file = element.source.fullName; | 87 String file = element.source.fullName; |
91 return new SourceReference(file, sourceRange, element, true, true); | 88 return new SourceReference(file, sourceRange, element, true, true); |
92 } | 89 } |
93 } | 90 } |
OLD | NEW |