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

Side by Side Diff: pkg/analysis_server/test/services/refactoring/rename_class_member_test.dart

Issue 2204263002: Issue 25666. Add test for shadowing of a superclass member from other library. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | 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 test.services.refactoring.rename_class_member; 5 library test.services.refactoring.rename_class_member;
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:analyzer/src/generated/source.dart';
9 import 'package:test_reflective_loader/test_reflective_loader.dart'; 10 import 'package:test_reflective_loader/test_reflective_loader.dart';
10 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
11 12
12 import '../../utils.dart'; 13 import '../../utils.dart';
13 import 'abstract_rename.dart'; 14 import 'abstract_rename.dart';
14 15
15 main() { 16 main() {
16 initializeTestEnvironment(); 17 initializeTestEnvironment();
17 defineReflectiveTests(RenameClassMemberTest); 18 defineReflectiveTests(RenameClassMemberTest);
18 } 19 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 createRenameRefactoringAtString('test() {}'); 259 createRenameRefactoringAtString('test() {}');
259 // check status 260 // check status
260 refactoring.newName = 'newName'; 261 refactoring.newName = 'newName';
261 RefactoringStatus status = await refactoring.checkFinalConditions(); 262 RefactoringStatus status = await refactoring.checkFinalConditions();
262 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, 263 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
263 expectedMessage: 264 expectedMessage:
264 "Usage of renamed method will be shadowed by parameter 'newName'.", 265 "Usage of renamed method will be shadowed by parameter 'newName'.",
265 expectedContextSearch: 'test(); // marker'); 266 expectedContextSearch: 'test(); // marker');
266 } 267 }
267 268
268 test_checkFinalConditions_shadowed_inSubClass() async { 269 test_checkFinalConditions_shadowedBySub_MethodElement() async {
269 indexTestUnit(''' 270 indexTestUnit('''
270 class A { 271 class A {
271 newName() {} // marker 272 test() {}
272 } 273 }
273 class B extends A { 274 class B extends A {
274 test() {} 275 newName() {} // marker
275 main() { 276 main() {
276 newName(); 277 test();
277 } 278 }
278 } 279 }
279 '''); 280 ''');
280 createRenameRefactoringAtString('test() {}'); 281 createRenameRefactoringAtString('test() {}');
281 // check status 282 // check status
282 refactoring.newName = 'newName'; 283 refactoring.newName = 'newName';
283 RefactoringStatus status = await refactoring.checkFinalConditions(); 284 RefactoringStatus status = await refactoring.checkFinalConditions();
284 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, 285 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
285 expectedMessage: "Renamed method will shadow method 'A.newName'.", 286 expectedMessage:
287 "Renamed method will be shadowed by method 'B.newName'.",
286 expectedContextSearch: 'newName() {} // marker'); 288 expectedContextSearch: 'newName() {} // marker');
287 } 289 }
288 290
289 test_checkFinalConditions_shadowsSuper_inSubClass_FieldElement() async { 291 test_checkFinalConditions_shadowsSuper_FieldElement() async {
290 indexTestUnit(''' 292 indexTestUnit('''
291 class A { 293 class A {
292 int newName; // marker 294 int newName; // marker
293 } 295 }
294 class B extends A { 296 class B extends A {
295 test() {} 297 test() {}
296 } 298 }
297 class C extends B { 299 class C extends B {
298 main() { 300 main() {
299 print(newName); 301 print(newName);
300 } 302 }
301 } 303 }
302 '''); 304 ''');
303 createRenameRefactoringAtString('test() {}'); 305 createRenameRefactoringAtString('test() {}');
304 // check status 306 // check status
305 refactoring.newName = 'newName'; 307 refactoring.newName = 'newName';
306 RefactoringStatus status = await refactoring.checkFinalConditions(); 308 RefactoringStatus status = await refactoring.checkFinalConditions();
307 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, 309 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
308 expectedMessage: "Renamed method will shadow field 'A.newName'.", 310 expectedMessage: "Renamed method will shadow field 'A.newName'.",
309 expectedContextSearch: 'newName; // marker'); 311 expectedContextSearch: 'newName; // marker');
310 } 312 }
311 313
312 test_checkFinalConditions_shadowsSuper_MethodElement() async { 314 test_checkFinalConditions_shadowsSuper_MethodElement() async {
313 indexTestUnit(''' 315 indexTestUnit('''
314 class A { 316 class A {
315 test() {} 317 newName() {} // marker
316 } 318 }
317 class B extends A { 319 class B extends A {
318 newName() {} // marker 320 test() {}
319 main() {
320 test();
321 }
322 } 321 }
323 '''); 322 ''');
324 createRenameRefactoringAtString('test() {}'); 323 createRenameRefactoringAtString('test() {}');
325 // check status 324 // check status
326 refactoring.newName = 'newName'; 325 refactoring.newName = 'newName';
327 RefactoringStatus status = await refactoring.checkFinalConditions(); 326 RefactoringStatus status = await refactoring.checkFinalConditions();
328 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, 327 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
329 expectedMessage: 328 expectedMessage: "Renamed method will shadow method 'A.newName'.",
330 "Renamed method will be shadowed by method 'B.newName'.",
331 expectedContextSearch: 'newName() {} // marker'); 329 expectedContextSearch: 'newName() {} // marker');
332 } 330 }
333 331
332 test_checkFinalConditions_shadowsSuper_MethodElement_otherLib() async {
333 var libCode = r'''
334 class A {
335 newName() {} // marker
336 }
337 ''';
338 indexUnit('/lib.dart', libCode);
339 indexTestUnit('''
340 import 'lib.dart';
341 class B extends A {
342 test() {}
343 }
344 ''');
345 createRenameRefactoringAtString('test() {}');
346 // check status
347 refactoring.newName = 'newName';
348 RefactoringStatus status = await refactoring.checkFinalConditions();
349 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
350 expectedMessage: "Renamed method will shadow method 'A.newName'.",
351 expectedContextRange: new SourceRange(
352 libCode.indexOf('newName() {} // marker'), 'newName'.length));
353 }
354
334 test_checkInitialConditions_inSDK() async { 355 test_checkInitialConditions_inSDK() async {
335 indexTestUnit(''' 356 indexTestUnit('''
336 main() { 357 main() {
337 'abc'.toUpperCase(); 358 'abc'.toUpperCase();
338 } 359 }
339 '''); 360 ''');
340 createRenameRefactoringAtString('toUpperCase()'); 361 createRenameRefactoringAtString('toUpperCase()');
341 // check status 362 // check status
342 refactoring.newName = 'NewName'; 363 refactoring.newName = 'NewName';
343 RefactoringStatus status = await refactoring.checkInitialConditions(); 364 RefactoringStatus status = await refactoring.checkInitialConditions();
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 // validate change 893 // validate change
873 return assertSuccessfulRefactoring(''' 894 return assertSuccessfulRefactoring('''
874 class A<NewName> { 895 class A<NewName> {
875 NewName field; 896 NewName field;
876 List<NewName> items; 897 List<NewName> items;
877 NewName method(NewName p) => null; 898 NewName method(NewName p) => null;
878 } 899 }
879 '''); 900 ''');
880 } 901 }
881 } 902 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698