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

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

Issue 913573002: Fix for incremental resolution in case of inserting a new token into elegant comments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | « no previous file | pkg/analyzer/test/generated/incremental_resolver_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 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/services/lint.dart'; 10 import 'package:analyzer/src/services/lint.dart';
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 CompilationUnitElement _unitElement; 1163 CompilationUnitElement _unitElement;
1164 1164
1165 int _updateOffset; 1165 int _updateOffset;
1166 int _updateDelta; 1166 int _updateDelta;
1167 int _updateEndOld; 1167 int _updateEndOld;
1168 int _updateEndNew; 1168 int _updateEndNew;
1169 1169
1170 List<AnalysisError> _newScanErrors = <AnalysisError>[]; 1170 List<AnalysisError> _newScanErrors = <AnalysisError>[];
1171 List<AnalysisError> _newParseErrors = <AnalysisError>[]; 1171 List<AnalysisError> _newParseErrors = <AnalysisError>[];
1172 1172
1173 PoorMansIncrementalResolver(this._typeProvider, this._unitSource, 1173 PoorMansIncrementalResolver(this._typeProvider, this._unitSource, this._entry,
1174 this._entry, this._oldUnit, bool resolveApiChanges) { 1174 this._oldUnit, bool resolveApiChanges) {
1175 _resolveApiChanges = resolveApiChanges; 1175 _resolveApiChanges = resolveApiChanges;
1176 } 1176 }
1177 1177
1178 /** 1178 /**
1179 * Attempts to update [_oldUnit] to the state corresponding to [newCode]. 1179 * Attempts to update [_oldUnit] to the state corresponding to [newCode].
1180 * Returns `true` if success, or `false` otherwise. 1180 * Returns `true` if success, or `false` otherwise.
1181 * The [_oldUnit] might be damaged. 1181 * The [_oldUnit] might be damaged.
1182 */ 1182 */
1183 bool resolve(String newCode) { 1183 bool resolve(String newCode) {
1184 logger.enter('diff/resolve $_unitSource'); 1184 logger.enter('diff/resolve $_unitSource');
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 */ 1419 */
1420 static bool _areCurlyBracketsBalanced(Token token) { 1420 static bool _areCurlyBracketsBalanced(Token token) {
1421 int numOpen = _getTokenCount(token, TokenType.OPEN_CURLY_BRACKET); 1421 int numOpen = _getTokenCount(token, TokenType.OPEN_CURLY_BRACKET);
1422 int numOpen2 = 1422 int numOpen2 =
1423 _getTokenCount(token, TokenType.STRING_INTERPOLATION_EXPRESSION); 1423 _getTokenCount(token, TokenType.STRING_INTERPOLATION_EXPRESSION);
1424 int numClosed = _getTokenCount(token, TokenType.CLOSE_CURLY_BRACKET); 1424 int numClosed = _getTokenCount(token, TokenType.CLOSE_CURLY_BRACKET);
1425 return numOpen + numOpen2 == numClosed; 1425 return numOpen + numOpen2 == numClosed;
1426 } 1426 }
1427 1427
1428 static _TokenDifferenceKind _compareToken(Token oldToken, Token newToken, 1428 static _TokenDifferenceKind _compareToken(Token oldToken, Token newToken,
1429 int delta) { 1429 int delta, bool forComment) {
1430 if (oldToken == null && newToken == null) { 1430 while (true) {
1431 return null; 1431 if (oldToken == null && newToken == null) {
1432 } 1432 return null;
1433 if (oldToken == null || newToken == null) { 1433 }
1434 return _TokenDifferenceKind.CONTENT; 1434 if (oldToken == null || newToken == null) {
1435 } 1435 return _TokenDifferenceKind.CONTENT;
1436 if (oldToken.type != newToken.type) { 1436 }
1437 return _TokenDifferenceKind.CONTENT; 1437 if (oldToken.type != newToken.type) {
1438 } 1438 return _TokenDifferenceKind.CONTENT;
1439 if (oldToken.lexeme != newToken.lexeme) { 1439 }
1440 return _TokenDifferenceKind.CONTENT; 1440 if (oldToken.lexeme != newToken.lexeme) {
1441 } 1441 return _TokenDifferenceKind.CONTENT;
1442 if (newToken.offset - oldToken.offset != delta) { 1442 }
1443 return _TokenDifferenceKind.OFFSET; 1443 if (newToken.offset - oldToken.offset != delta) {
1444 return _TokenDifferenceKind.OFFSET;
1445 }
1446 // continue if comment tokens are being checked
1447 if (!forComment) {
1448 break;
1449 }
1450 oldToken = oldToken.next;
1451 newToken = newToken.next;
1444 } 1452 }
1445 return null; 1453 return null;
1446 } 1454 }
1447 1455
1448 static _TokenPair _findFirstDifferentToken(Token oldToken, Token newToken) { 1456 static _TokenPair _findFirstDifferentToken(Token oldToken, Token newToken) {
1449 while (true) { 1457 while (true) {
1450 if (oldToken.type == TokenType.EOF && newToken.type == TokenType.EOF) { 1458 if (oldToken.type == TokenType.EOF && newToken.type == TokenType.EOF) {
1451 return null; 1459 return null;
1452 } 1460 }
1453 if (oldToken.type == TokenType.EOF || newToken.type == TokenType.EOF) { 1461 if (oldToken.type == TokenType.EOF || newToken.type == TokenType.EOF) {
1454 return new _TokenPair(_TokenDifferenceKind.CONTENT, oldToken, newToken); 1462 return new _TokenPair(_TokenDifferenceKind.CONTENT, oldToken, newToken);
1455 } 1463 }
1456 // compare comments 1464 // compare comments
1457 { 1465 {
1458 Token oldComment = oldToken.precedingComments; 1466 Token oldComment = oldToken.precedingComments;
1459 Token newComment = newToken.precedingComments; 1467 Token newComment = newToken.precedingComments;
1460 if (_compareToken(oldComment, newComment, 0) != null) { 1468 if (_compareToken(oldComment, newComment, 0, true) != null) {
1461 _TokenDifferenceKind diffKind = _TokenDifferenceKind.COMMENT; 1469 _TokenDifferenceKind diffKind = _TokenDifferenceKind.COMMENT;
1462 if (oldComment is DocumentationCommentToken || 1470 if (oldComment is DocumentationCommentToken ||
1463 newComment is DocumentationCommentToken) { 1471 newComment is DocumentationCommentToken) {
1464 diffKind = _TokenDifferenceKind.COMMENT_DOC; 1472 diffKind = _TokenDifferenceKind.COMMENT_DOC;
1465 } 1473 }
1466 return new _TokenPair(diffKind, oldToken, newToken); 1474 return new _TokenPair(diffKind, oldToken, newToken);
1467 } 1475 }
1468 } 1476 }
1469 // compare tokens 1477 // compare tokens
1470 _TokenDifferenceKind diffKind = _compareToken(oldToken, newToken, 0); 1478 _TokenDifferenceKind diffKind =
1479 _compareToken(oldToken, newToken, 0, false);
1471 if (diffKind != null) { 1480 if (diffKind != null) {
1472 return new _TokenPair(diffKind, oldToken, newToken); 1481 return new _TokenPair(diffKind, oldToken, newToken);
1473 } 1482 }
1474 // next tokens 1483 // next tokens
1475 oldToken = oldToken.next; 1484 oldToken = oldToken.next;
1476 newToken = newToken.next; 1485 newToken = newToken.next;
1477 } 1486 }
1478 // no difference 1487 // no difference
1479 return null; 1488 return null;
1480 } 1489 }
1481 1490
1482 static _TokenPair _findLastDifferentToken(Token oldToken, Token newToken) { 1491 static _TokenPair _findLastDifferentToken(Token oldToken, Token newToken) {
1483 int delta = newToken.offset - oldToken.offset; 1492 int delta = newToken.offset - oldToken.offset;
1484 while (oldToken.previous != oldToken && newToken.previous != newToken) { 1493 while (oldToken.previous != oldToken && newToken.previous != newToken) {
1485 // compare tokens 1494 // compare tokens
1486 _TokenDifferenceKind diffKind = _compareToken(oldToken, newToken, delta); 1495 _TokenDifferenceKind diffKind =
1496 _compareToken(oldToken, newToken, delta, false);
1487 if (diffKind != null) { 1497 if (diffKind != null) {
1488 return new _TokenPair(diffKind, oldToken.next, newToken.next); 1498 return new _TokenPair(diffKind, oldToken.next, newToken.next);
1489 } 1499 }
1490 // compare comments 1500 // compare comments
1491 { 1501 {
1492 Token oldComment = oldToken.precedingComments; 1502 Token oldComment = oldToken.precedingComments;
1493 Token newComment = newToken.precedingComments; 1503 Token newComment = newToken.precedingComments;
1494 if (_compareToken(oldComment, newComment, delta) != null) { 1504 if (_compareToken(oldComment, newComment, delta, true) != null) {
1495 _TokenDifferenceKind diffKind = _TokenDifferenceKind.COMMENT; 1505 _TokenDifferenceKind diffKind = _TokenDifferenceKind.COMMENT;
1496 if (oldComment is DocumentationCommentToken || 1506 if (oldComment is DocumentationCommentToken ||
1497 newComment is DocumentationCommentToken) { 1507 newComment is DocumentationCommentToken) {
1498 diffKind = _TokenDifferenceKind.COMMENT_DOC; 1508 diffKind = _TokenDifferenceKind.COMMENT_DOC;
1499 } 1509 }
1500 return new _TokenPair(diffKind, oldToken, newToken); 1510 return new _TokenPair(diffKind, oldToken, newToken);
1501 } 1511 }
1502 } 1512 }
1503 // next tokens 1513 // next tokens
1504 oldToken = oldToken.previous; 1514 oldToken = oldToken.previous;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1835 String toString() => name; 1845 String toString() => name;
1836 } 1846 }
1837 1847
1838 1848
1839 class _TokenPair { 1849 class _TokenPair {
1840 final _TokenDifferenceKind kind; 1850 final _TokenDifferenceKind kind;
1841 final Token oldToken; 1851 final Token oldToken;
1842 final Token newToken; 1852 final Token newToken;
1843 _TokenPair(this.kind, this.oldToken, this.newToken); 1853 _TokenPair(this.kind, this.oldToken, this.newToken);
1844 } 1854 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698