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

Side by Side Diff: pkg/analyzer/test/src/task/incremental_element_builder_test.dart

Issue 1131053002: Don't update offsets for elements of 'part' and 'part of' directives. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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
« no previous file with comments | « pkg/analyzer/lib/src/task/incremental_element_builder.dart ('k') | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.src.task.incremental_element_builder_test; 5 library test.src.task.incremental_element_builder_test;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:analyzer/src/task/incremental_element_builder.dart'; 10 import 'package:analyzer/src/task/incremental_element_builder.dart';
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 { 61 {
62 Directive newNode = newDirectives[2]; 62 Directive newNode = newDirectives[2];
63 expect(newNode, same(oldDirectives[1])); 63 expect(newNode, same(oldDirectives[1]));
64 expect(getNodeText(newNode), "import 'dart:math';"); 64 expect(getNodeText(newNode), "import 'dart:math';");
65 ImportElement element = newNode.element; 65 ImportElement element = newNode.element;
66 expect(element, isNotNull); 66 expect(element, isNotNull);
67 expect(element.nameOffset, newCode.indexOf("import 'dart:math';")); 67 expect(element.nameOffset, newCode.indexOf("import 'dart:math';"));
68 } 68 }
69 } 69 }
70 70
71 test_directives_keepOffset_partOf() {
72 String libCode = '''
73 // comment to shift tokens
74 library my_lib;
75 part 'test.dart';
76 ''';
77 Source libSource = newSource('/lib.dart', libCode);
78 _buildOldUnit(r'''
79 part of my_lib;
80 class A {}
81 ''', libSource);
82 _buildNewUnit(r'''
83 part of my_lib;
84 class A {}
85 ''');
86 var oldDirectives = oldUnit.directives;
87 var newDirectives = newUnit.directives;
88 {
89 Directive newNode = newDirectives[0];
90 expect(newNode, same(oldDirectives[0]));
91 expect(getNodeText(newNode), 'part of my_lib;');
92 LibraryElement element = newNode.element;
93 expect(element, isNotNull);
94 expect(element.nameOffset, libCode.indexOf('my_lib;'));
95 }
96 }
97
71 test_directives_remove() { 98 test_directives_remove() {
72 _buildOldUnit(r''' 99 _buildOldUnit(r'''
73 library test; 100 library test;
74 import 'dart:async'; 101 import 'dart:async';
75 import 'dart:math'; 102 import 'dart:math';
76 '''); 103 ''');
77 _buildNewUnit(r''' 104 _buildNewUnit(r'''
78 library test; 105 library test;
79 import 'dart:math'; 106 import 'dart:math';
80 '''); 107 ''');
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 } 577 }
551 578
552 void _buildNewUnit(String newCode) { 579 void _buildNewUnit(String newCode) {
553 this.newCode = newCode; 580 this.newCode = newCode;
554 context.setContents(source, newCode); 581 context.setContents(source, newCode);
555 newUnit = context.parseCompilationUnit(source); 582 newUnit = context.parseCompilationUnit(source);
556 new IncrementalCompilationUnitElementBuilder(oldUnit, newUnit).build(); 583 new IncrementalCompilationUnitElementBuilder(oldUnit, newUnit).build();
557 expect(newUnit.element, unitElement); 584 expect(newUnit.element, unitElement);
558 } 585 }
559 586
560 void _buildOldUnit(String oldCode) { 587 void _buildOldUnit(String oldCode, [Source libSource]) {
561 this.oldCode = oldCode; 588 this.oldCode = oldCode;
562 source = newSource('/test.dart', oldCode); 589 source = newSource('/test.dart', oldCode);
563 oldUnit = context.resolveCompilationUnit2(source, source); 590 if (libSource == null) {
591 libSource = source;
592 }
593 oldUnit = context.resolveCompilationUnit2(source, libSource);
564 unitElement = oldUnit.element; 594 unitElement = oldUnit.element;
565 expect(unitElement, isNotNull); 595 expect(unitElement, isNotNull);
566 } 596 }
567 } 597 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/incremental_element_builder.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698