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

Side by Side Diff: pkg/analyzer/lib/src/generated/incremental_resolver.dart

Issue 755373003: Try to resolve incrementally whole functions, constructors or methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 engine.incremental_resolver; 5 library engine.incremental_resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 9
10 import 'package:analyzer/src/generated/error_verifier.dart'; 10 import 'package:analyzer/src/generated/error_verifier.dart';
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 // print('newNode: $newNode'); 888 // print('newNode: $newNode');
889 // Try to find the smallest common node, a FunctionBody currently. 889 // Try to find the smallest common node, a FunctionBody currently.
890 { 890 {
891 List<AstNode> oldParents = _getParents(oldNode); 891 List<AstNode> oldParents = _getParents(oldNode);
892 List<AstNode> newParents = _getParents(newNode); 892 List<AstNode> newParents = _getParents(newNode);
893 int length = math.min(oldParents.length, newParents.length); 893 int length = math.min(oldParents.length, newParents.length);
894 bool found = false; 894 bool found = false;
895 for (int i = 0; i < length; i++) { 895 for (int i = 0; i < length; i++) {
896 AstNode oldParent = oldParents[i]; 896 AstNode oldParent = oldParents[i];
897 AstNode newParent = newParents[i]; 897 AstNode newParent = newParents[i];
898 if (oldParent is FunctionDeclaration &&
899 newParent is FunctionDeclaration ||
900 oldParent is MethodDeclaration && newParent is MethodDeclaration ||
901 oldParent is ConstructorDeclaration && newParent is ConstructorD eclaration) {
902 oldNode = oldParent;
903 newNode = newParent;
904 found = true;
905 }
898 if (oldParent is FunctionBody && newParent is FunctionBody) { 906 if (oldParent is FunctionBody && newParent is FunctionBody) {
899 oldNode = oldParent; 907 oldNode = oldParent;
900 newNode = newParent; 908 newNode = newParent;
901 found = true; 909 found = true;
902 break; 910 break;
903 } 911 }
904 } 912 }
905 if (!found) { 913 if (!found) {
906 return false; 914 return false;
907 } 915 }
908 } 916 }
909 // prepare update range 917 // prepare update range
910 _updateOffset = oldNode.offset; 918 _updateOffset = oldNode.offset;
911 _updateEndOld = oldNode.end; 919 _updateEndOld = oldNode.end;
912 _updateEndNew = newNode.end; 920 _updateEndNew = newNode.end;
913 _updateDelta = _updateEndNew - _updateEndOld; 921 _updateDelta = _updateEndNew - _updateEndOld;
914 // _updateDelta = lastPair.delta;
915 // replace node 922 // replace node
916 NodeReplacer.replace(oldNode, newNode); 923 NodeReplacer.replace(oldNode, newNode);
917 // update token references 924 // update token references
918 oldNode.beginToken.previous.setNext(newNode.beginToken); 925 {
919 newNode.endToken.setNext(oldNode.endToken.next); 926 Token oldBeginToken = oldNode.beginToken;
920 _shiftTokens(oldNode.endToken.next, _updateDelta); 927 if (oldBeginToken.previous.type == TokenType.EOF) {
928 oldUnit.beginToken = newNode.beginToken;
929 } else {
930 oldBeginToken.previous.setNext(newNode.beginToken);
931 }
932 newNode.endToken.setNext(oldNode.endToken.next);
933 _shiftTokens(oldNode.endToken.next, _updateDelta);
934 }
921 // perform incremental resolution 935 // perform incremental resolution
922 CompilationUnitElement oldUnitElement = oldUnit.element; 936 CompilationUnitElement oldUnitElement = oldUnit.element;
923 IncrementalResolver incrementalResolver = new IncrementalResolver( 937 IncrementalResolver incrementalResolver = new IncrementalResolver(
924 _typeProvider, 938 _typeProvider,
925 oldUnitElement.library, 939 oldUnitElement.library,
926 oldUnitElement, 940 oldUnitElement,
927 oldUnitElement.source, 941 oldUnitElement.source,
928 _updateOffset, 942 _updateOffset,
929 oldNode.length, 943 oldNode.length,
930 newNode.length); 944 newNode.length);
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 1268
1255 class _ElementNameOffsetUpdater extends GeneralizingElementVisitor { 1269 class _ElementNameOffsetUpdater extends GeneralizingElementVisitor {
1256 final int updateOffset; 1270 final int updateOffset;
1257 final int updateDelta; 1271 final int updateDelta;
1258 1272
1259 _ElementNameOffsetUpdater(this.updateOffset, this.updateDelta); 1273 _ElementNameOffsetUpdater(this.updateOffset, this.updateDelta);
1260 1274
1261 @override 1275 @override
1262 visitElement(Element element) { 1276 visitElement(Element element) {
1263 int nameOffset = element.nameOffset; 1277 int nameOffset = element.nameOffset;
1264 if (nameOffset >= updateOffset) { 1278 if (nameOffset > updateOffset) {
1265 (element as ElementImpl).nameOffset = nameOffset + updateDelta; 1279 (element as ElementImpl).nameOffset = nameOffset + updateDelta;
1266 } 1280 }
1267 super.visitElement(element); 1281 super.visitElement(element);
1268 } 1282 }
1269 } 1283 }
1270 1284
1271 1285
1272 class _ElementsGatherer extends GeneralizingElementVisitor { 1286 class _ElementsGatherer extends GeneralizingElementVisitor {
1273 final DeclarationMatcher matcher; 1287 final DeclarationMatcher matcher;
1274 1288
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 _elements[node] = node.staticElement; 1389 _elements[node] = node.staticElement;
1376 } 1390 }
1377 } 1391 }
1378 1392
1379 1393
1380 class _TokenPair { 1394 class _TokenPair {
1381 final Token oldToken; 1395 final Token oldToken;
1382 final Token newToken; 1396 final Token newToken;
1383 _TokenPair(this.oldToken, this.newToken); 1397 _TokenPair(this.oldToken, this.newToken);
1384 } 1398 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/ast.dart ('k') | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698