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

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

Issue 1377623002: Report a fatal error on attempt to rename an element declared in SDK. (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
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; 5 library services.src.refactoring.rename;
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/refactoring/refactoring.dart'; 13 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
13 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da rt'; 14 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da rt';
14 import 'package:analysis_server/src/services/search/search_engine.dart'; 15 import 'package:analysis_server/src/services/search/search_engine.dart';
15 import 'package:analyzer/src/generated/element.dart'; 16 import 'package:analyzer/src/generated/element.dart';
16 import 'package:analyzer/src/generated/engine.dart'; 17 import 'package:analyzer/src/generated/engine.dart';
18 import 'package:analyzer/src/generated/java_core.dart';
17 import 'package:analyzer/src/generated/source.dart'; 19 import 'package:analyzer/src/generated/source.dart';
18 20
19 /** 21 /**
20 * Returns `true` if two given [Element]s are [LocalElement]s and have 22 * Returns `true` if two given [Element]s are [LocalElement]s and have
21 * intersecting with visibility ranges. 23 * intersecting with visibility ranges.
22 */ 24 */
23 bool haveIntersectingRanges(LocalElement localElement, Element element) { 25 bool haveIntersectingRanges(LocalElement localElement, Element element) {
24 if (element is! LocalElement) { 26 if (element is! LocalElement) {
25 return false; 27 return false;
26 } 28 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 void addReferenceEdits(List<SearchMatch> matches) { 131 void addReferenceEdits(List<SearchMatch> matches) {
130 List<SourceReference> references = getSourceReferences(matches); 132 List<SourceReference> references = getSourceReferences(matches);
131 for (SourceReference reference in references) { 133 for (SourceReference reference in references) {
132 reference.addEdit(change, newName); 134 reference.addEdit(change, newName);
133 } 135 }
134 } 136 }
135 137
136 @override 138 @override
137 Future<RefactoringStatus> checkInitialConditions() { 139 Future<RefactoringStatus> checkInitialConditions() {
138 RefactoringStatus result = new RefactoringStatus(); 140 RefactoringStatus result = new RefactoringStatus();
141 if (element.source.isInSystemLibrary) {
142 String message = format(
143 "The {0} '{1}' is defined in the SDK, so cannot be renamed.",
144 getElementKindName(element),
145 getElementQualifiedName(element));
146 result.addFatalError(message);
147 }
139 return new Future.value(result); 148 return new Future.value(result);
140 } 149 }
141 150
142 @override 151 @override
143 RefactoringStatus checkNewName() { 152 RefactoringStatus checkNewName() {
144 RefactoringStatus result = new RefactoringStatus(); 153 RefactoringStatus result = new RefactoringStatus();
145 if (newName == oldName) { 154 if (newName == oldName) {
146 result.addFatalError( 155 result.addFatalError(
147 "The new name must be different than the current name."); 156 "The new name must be different than the current name.");
148 } 157 }
(...skipping 22 matching lines...) Expand all
171 if (element is ImportElement) { 180 if (element is ImportElement) {
172 PrefixElement prefix = element.prefix; 181 PrefixElement prefix = element.prefix;
173 if (prefix != null) { 182 if (prefix != null) {
174 return prefix.displayName; 183 return prefix.displayName;
175 } 184 }
176 return ''; 185 return '';
177 } 186 }
178 return element.displayName; 187 return element.displayName;
179 } 188 }
180 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698