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

Side by Side Diff: pkg/analysis_server/lib/src/services/refactoring/rename_unit_member.dart

Issue 462403005: Move Location factories and RefactoringProblemSeverity.max into the generated classes. (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_unit_member; 5 library services.src.refactoring.rename_unit_member;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol2.dart' show Location;
9 import 'package:analysis_server/src/services/correction/change.dart'; 10 import 'package:analysis_server/src/services/correction/change.dart';
10 import 'package:analysis_server/src/services/correction/status.dart'; 11 import 'package:analysis_server/src/services/correction/status.dart';
11 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
12 import 'package:analysis_server/src/services/search/search_engine.dart';
13 import 'package:analysis_server/src/services/correction/util.dart'; 12 import 'package:analysis_server/src/services/correction/util.dart';
14 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';
15 import 'package:analysis_server/src/services/refactoring/rename.dart'; 15 import 'package:analysis_server/src/services/refactoring/rename.dart';
16 import 'package:analysis_server/src/services/search/element_visitors.dart';
17 import 'package:analysis_server/src/services/search/search_engine.dart';
16 import 'package:analyzer/src/generated/element.dart'; 18 import 'package:analyzer/src/generated/element.dart';
17 import 'package:analyzer/src/generated/java_core.dart'; 19 import 'package:analyzer/src/generated/java_core.dart';
18 import 'package:analysis_server/src/services/search/element_visitors.dart';
19 20
20 21
21 /** 22 /**
22 * A [Refactoring] for renaming compilation unit member [Element]s. 23 * A [Refactoring] for renaming compilation unit member [Element]s.
23 */ 24 */
24 class RenameUnitMemberRefactoringImpl extends RenameRefactoringImpl { 25 class RenameUnitMemberRefactoringImpl extends RenameRefactoringImpl {
25 RenameUnitMemberRefactoringImpl(SearchEngine searchEngine, Element element) 26 RenameUnitMemberRefactoringImpl(SearchEngine searchEngine, Element element)
26 : super(searchEngine, element); 27 : super(searchEngine, element);
27 28
28 @override 29 @override
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 */ 165 */
165 Future _validateWillBeShadowed() { 166 Future _validateWillBeShadowed() {
166 return searchEngine.searchReferences(element).then((references) { 167 return searchEngine.searchReferences(element).then((references) {
167 for (SearchMatch reference in references) { 168 for (SearchMatch reference in references) {
168 Element refElement = reference.element; 169 Element refElement = reference.element;
169 ClassElement refClass = 170 ClassElement refClass =
170 refElement.getAncestor((e) => e is ClassElement); 171 refElement.getAncestor((e) => e is ClassElement);
171 if (refClass != null) { 172 if (refClass != null) {
172 visitChildren(refClass, (shadow) { 173 visitChildren(refClass, (shadow) {
173 if (hasDisplayName(shadow, newName)) { 174 if (hasDisplayName(shadow, newName)) {
174 String message = 175 String message = format(
175 format( 176 "Reference to renamed {0} will be shadowed by {1} '{2}'.",
176 "Reference to renamed {0} will be shadowed by {1} '{2}'.", 177 getElementKindName(element),
177 getElementKindName(element), 178 getElementKindName(shadow),
178 getElementKindName(shadow), 179 getElementQualifiedName(shadow));
179 getElementQualifiedName(shadow)); 180 result.addError(message, new Location.forElement(shadow));
180 result.addError(
181 message,
182 createLocation_forElement(shadow));
183 } 181 }
184 }); 182 });
185 } 183 }
186 } 184 }
187 }); 185 });
188 } 186 }
189 187
190 /** 188 /**
191 * Validates if [element] renamed to [newName] will conflict with another 189 * Validates if [element] renamed to [newName] will conflict with another
192 * top-level [Element] in the same library. 190 * top-level [Element] in the same library.
193 */ 191 */
194 void _validateWillConflict() { 192 void _validateWillConflict() {
195 LibraryElement library = element.getAncestor((e) => e is LibraryElement); 193 LibraryElement library = element.getAncestor((e) => e is LibraryElement);
196 visitLibraryTopLevelElements(library, (element) { 194 visitLibraryTopLevelElements(library, (element) {
197 if (hasDisplayName(element, newName)) { 195 if (hasDisplayName(element, newName)) {
198 String message = 196 String message = format(
199 format( 197 "Library already declares {0} with name '{1}'.",
200 "Library already declares {0} with name '{1}'.", 198 getElementKindName(element),
201 getElementKindName(element), 199 newName);
202 newName); 200 result.addError(message, new Location.forElement(element));
203 result.addError(
204 message,
205 createLocation_forElement(element));
206 } 201 }
207 }); 202 });
208 } 203 }
209 204
210 /** 205 /**
211 * Validates if renamed [element] will shadow any [Element] named [newName]. 206 * Validates if renamed [element] will shadow any [Element] named [newName].
212 */ 207 */
213 Future _validateWillShadow() { 208 Future _validateWillShadow() {
214 return searchEngine.searchMemberDeclarations(newName).then((declarations) { 209 return searchEngine.searchMemberDeclarations(newName).then((declarations) {
215 return Future.forEach(declarations, (SearchMatch declaration) { 210 return Future.forEach(declarations, (SearchMatch declaration) {
(...skipping 10 matching lines...) Expand all
226 ClassElement refClass = 221 ClassElement refClass =
227 refElement.getAncestor((e) => e is ClassElement); 222 refElement.getAncestor((e) => e is ClassElement);
228 if (refClass == declaringClass) { 223 if (refClass == declaringClass) {
229 continue; 224 continue;
230 } 225 }
231 // ignore if not visitble 226 // ignore if not visitble
232 if (!_isVisibleAt(element, memberReference)) { 227 if (!_isVisibleAt(element, memberReference)) {
233 continue; 228 continue;
234 } 229 }
235 // OK, reference will be shadowed be the element being renamed 230 // OK, reference will be shadowed be the element being renamed
236 String message = 231 String message = format(
237 format( 232 forRename ?
238 forRename ? 233 "Renamed {0} will shadow {1} '{2}'." :
239 "Renamed {0} will shadow {1} '{2}'." : 234 "Created {0} will shadow {1} '{2}'.",
240 "Created {0} will shadow {1} '{2}'.", 235 getElementKindName(element),
241 getElementKindName(element), 236 getElementKindName(member),
242 getElementKindName(member), 237 getElementQualifiedName(member));
243 getElementQualifiedName(member)); 238 result.addError(message, new Location.forMatch(memberReference));
244 result.addError(
245 message,
246 createLocation_forMatch(memberReference));
247 } 239 }
248 }); 240 });
249 }); 241 });
250 }); 242 });
251 } 243 }
252 } 244 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698