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

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

Issue 1398213004: Warn about conflict before renamed class member and enclosing class name. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/rename_class_member_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_class_member; 5 library services.src.refactoring.rename_class_member;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol_server.dart' 9 import 'package:analysis_server/src/protocol_server.dart'
10 hide Element, ElementKind; 10 hide Element, ElementKind;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 elementClass.displayName, 163 elementClass.displayName,
164 getElementKindName(newNameMember), 164 getElementKindName(newNameMember),
165 name), 165 name),
166 newLocation_fromElement(newNameMember)); 166 newLocation_fromElement(newNameMember));
167 } 167 }
168 // do chained computations 168 // do chained computations
169 Set<ClassElement> superClasses = getSuperClasses(elementClass); 169 Set<ClassElement> superClasses = getSuperClasses(elementClass);
170 await _prepareReferences(); 170 await _prepareReferences();
171 Set<ClassElement> subClasses = 171 Set<ClassElement> subClasses =
172 await getSubClasses(searchEngine, elementClass); 172 await getSubClasses(searchEngine, elementClass);
173 // check shadowing of class names
174 if (element != null) {
175 for (Element element in elements) {
176 ClassElement clazz = element.enclosingElement;
177 if (clazz.name == name) {
178 result.addError(
179 format(
180 "Renamed {0} has the same name as the declaring class '{1}'.",
181 elementKind.displayName,
182 name),
183 newLocation_fromElement(element));
184 }
185 }
186 } else {
187 if (elementClass.name == name) {
188 result.addError(
189 format(
190 "Created {0} has the same name as the declaring class '{1}'.",
191 elementKind.displayName,
192 name),
193 newLocation_fromElement(elementClass));
194 }
195 }
173 // check shadowing in hierarchy 196 // check shadowing in hierarchy
174 List<SearchMatch> declarations = 197 List<SearchMatch> declarations =
175 await searchEngine.searchElementDeclarations(name); 198 await searchEngine.searchElementDeclarations(name);
176 for (SearchMatch declaration in declarations) { 199 for (SearchMatch declaration in declarations) {
177 Element nameElement = getSyntheticAccessorVariable(declaration.element); 200 Element nameElement = getSyntheticAccessorVariable(declaration.element);
178 Element nameClass = nameElement.enclosingElement; 201 Element nameClass = nameElement.enclosingElement;
179 // renamed Element shadows member of superclass 202 // renamed Element shadows member of superclass
180 if (superClasses.contains(nameClass)) { 203 if (superClasses.contains(nameClass)) {
181 result.addError( 204 result.addError(
182 format( 205 format(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 Element refElement = reference.element; 287 Element refElement = reference.element;
265 LibraryElement refLibrary = refElement.library; 288 LibraryElement refLibrary = refElement.library;
266 if (refLibrary != library) { 289 if (refLibrary != library) {
267 String message = format("Renamed {0} will be invisible in '{1}'.", 290 String message = format("Renamed {0} will be invisible in '{1}'.",
268 getElementKindName(element), getElementQualifiedName(refLibrary)); 291 getElementKindName(element), getElementQualifiedName(refLibrary));
269 result.addError(message, newLocation_fromMatch(reference)); 292 result.addError(message, newLocation_fromMatch(reference));
270 } 293 }
271 } 294 }
272 } 295 }
273 } 296 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/rename_class_member_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698