Chromium Code Reviews| Index: pkg/analyzer/lib/src/generated/incremental_resolver.dart |
| diff --git a/pkg/analyzer/lib/src/generated/incremental_resolver.dart b/pkg/analyzer/lib/src/generated/incremental_resolver.dart |
| index 2088c516164db58fa2af547947c8d47e8b549b8b..710c0ef58d38496f76c23811c066e8fe1db3d7fa 100644 |
| --- a/pkg/analyzer/lib/src/generated/incremental_resolver.dart |
| +++ b/pkg/analyzer/lib/src/generated/incremental_resolver.dart |
| @@ -1261,9 +1261,20 @@ class PoorMansIncrementalResolver { |
| bool resolve(String newCode) { |
| logger.enter('diff/resolve $_unitSource'); |
| try { |
| + // prepare old unit |
| CompilationUnit oldUnit = _units[_unitSource]; |
| + if (!_areCurlyBracketsBalanced(oldUnit.beginToken)) { |
| + logger.log('Unbalanced number of curly brackets in the old unit.'); |
| + return false; |
| + } |
| _unitElement = oldUnit.element; |
| + // prepare ne unit |
|
Brian Wilkerson
2015/01/20 19:08:27
'ne' --> 'new'
|
| CompilationUnit newUnit = _parseUnit(newCode); |
| + if (!_areCurlyBracketsBalanced(newUnit.beginToken)) { |
| + logger.log('Unbalanced number of curly brackets in the new unit.'); |
| + return false; |
| + } |
| + // find difference |
| _TokenPair firstPair = |
| _findFirstDifferentToken(oldUnit.beginToken, newUnit.beginToken); |
| _TokenPair lastPair = |
| @@ -1485,6 +1496,17 @@ class PoorMansIncrementalResolver { |
| _entry.setValue(DartEntry.PARSE_ERRORS, _newParseErrors); |
| } |
| + /** |
| + * Checks if [token] has a balanced number of open and closed curly brackets. |
| + */ |
| + static bool _areCurlyBracketsBalanced(Token token) { |
|
Brian Wilkerson
2015/01/20 19:08:27
Not for this CL, but... The scanner already comput
|
| + int numOpen = _getTokenCount(token, TokenType.OPEN_CURLY_BRACKET); |
| + int numOpen2 = |
| + _getTokenCount(token, TokenType.STRING_INTERPOLATION_EXPRESSION); |
| + int numClosed = _getTokenCount(token, TokenType.CLOSE_CURLY_BRACKET); |
| + return numOpen + numOpen2 == numClosed; |
| + } |
| + |
| static _TokenDifferenceKind _compareToken(Token oldToken, Token newToken, |
| int delta) { |
| if (oldToken == null && newToken == null) { |
| @@ -1580,7 +1602,6 @@ class PoorMansIncrementalResolver { |
| return oldBeginToken; |
| } |
| - |
| static List<AstNode> _getParents(AstNode node) { |
| List<AstNode> parents = <AstNode>[]; |
| while (node != null) { |
| @@ -1590,6 +1611,21 @@ class PoorMansIncrementalResolver { |
| return parents; |
| } |
| + |
| + /** |
| + * Returns number of tokens with the given [type]. |
| + */ |
| + static int _getTokenCount(Token token, TokenType type) { |
| + int count = 0; |
| + while (token.type != TokenType.EOF) { |
| + if (token.type == type) { |
| + count++; |
| + } |
| + token = token.next; |
| + } |
| + return count; |
| + } |
| + |
| /** |
| * Set the given [comment] as a "precedingComments" for [parent]. |
| */ |