| OLD | NEW |
| 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 'ast.dart'; | 10 import 'ast.dart'; |
| (...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 int endOffsetNew = math.max(firstOffsetNew, lastOffsetNew); | 1205 int endOffsetNew = math.max(firstOffsetNew, lastOffsetNew); |
| 1206 // check for a whitespace only change | 1206 // check for a whitespace only change |
| 1207 if (identical(lastPair.oldToken, firstPair.oldToken) && | 1207 if (identical(lastPair.oldToken, firstPair.oldToken) && |
| 1208 identical(lastPair.newToken, firstPair.newToken)) { | 1208 identical(lastPair.newToken, firstPair.newToken)) { |
| 1209 _updateOffset = beginOffsetOld - 1; | 1209 _updateOffset = beginOffsetOld - 1; |
| 1210 _updateEndOld = endOffsetOld; | 1210 _updateEndOld = endOffsetOld; |
| 1211 _updateEndNew = endOffsetNew; | 1211 _updateEndNew = endOffsetNew; |
| 1212 _updateDelta = newUnit.length - oldUnit.length; | 1212 _updateDelta = newUnit.length - oldUnit.length; |
| 1213 // A Dart documentation comment change. | 1213 // A Dart documentation comment change. |
| 1214 if (firstPair.kind == _TokenDifferenceKind.COMMENT_DOC) { | 1214 if (firstPair.kind == _TokenDifferenceKind.COMMENT_DOC) { |
| 1215 _resolveComment(oldUnit, newUnit, firstPair); | 1215 bool success = _resolveComment(oldUnit, newUnit, firstPair); |
| 1216 logger.log('Success.'); | 1216 logger.log('Documentation comment resolved: $success'); |
| 1217 return true; | 1217 return success; |
| 1218 } | 1218 } |
| 1219 // A pure whitespace change. | 1219 // A pure whitespace change. |
| 1220 if (firstPair.kind == _TokenDifferenceKind.OFFSET) { | 1220 if (firstPair.kind == _TokenDifferenceKind.OFFSET) { |
| 1221 logger.log('Whitespace change.'); | 1221 logger.log('Whitespace change.'); |
| 1222 _shiftTokens(firstPair.oldToken); | 1222 _shiftTokens(firstPair.oldToken); |
| 1223 { | 1223 { |
| 1224 IncrementalResolver incrementalResolver = new IncrementalResolver( | 1224 IncrementalResolver incrementalResolver = new IncrementalResolver( |
| 1225 _unitElement, | 1225 _unitElement, |
| 1226 _updateOffset, | 1226 _updateOffset, |
| 1227 _updateEndOld, | 1227 _updateEndOld, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 RecordingErrorListener errorListener = new RecordingErrorListener(); | 1326 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 1327 Parser parser = new Parser(_unitSource, errorListener); | 1327 Parser parser = new Parser(_unitSource, errorListener); |
| 1328 CompilationUnit unit = parser.parseCompilationUnit(token); | 1328 CompilationUnit unit = parser.parseCompilationUnit(token); |
| 1329 _newParseErrors = errorListener.errors; | 1329 _newParseErrors = errorListener.errors; |
| 1330 return unit; | 1330 return unit; |
| 1331 } finally { | 1331 } finally { |
| 1332 timer.stop('parse'); | 1332 timer.stop('parse'); |
| 1333 } | 1333 } |
| 1334 } | 1334 } |
| 1335 | 1335 |
| 1336 void _resolveComment(CompilationUnit oldUnit, CompilationUnit newUnit, | 1336 /** |
| 1337 * Attempts to resolve a documentation comment change. |
| 1338 * Returns `true` if success. |
| 1339 */ |
| 1340 bool _resolveComment(CompilationUnit oldUnit, CompilationUnit newUnit, |
| 1337 _TokenPair firstPair) { | 1341 _TokenPair firstPair) { |
| 1338 Token oldToken = firstPair.oldToken; | 1342 Token oldToken = firstPair.oldToken; |
| 1339 CommentToken precedingComments = oldToken.precedingComments; | 1343 Token newToken = firstPair.newToken; |
| 1340 int offset = precedingComments.offset; | 1344 CommentToken oldComments = oldToken.precedingComments; |
| 1345 CommentToken newComments = newToken.precedingComments; |
| 1346 if (oldComments == null || newComments == null) { |
| 1347 return false; |
| 1348 } |
| 1349 // find nodes |
| 1350 int offset = oldComments.offset; |
| 1341 logger.log('offset: $offset'); | 1351 logger.log('offset: $offset'); |
| 1342 Comment oldComment = _findNodeCovering(oldUnit, offset, offset); | 1352 Comment oldComment = _findNodeCovering(oldUnit, offset, offset); |
| 1343 Comment newComment = _findNodeCovering(newUnit, offset, offset); | 1353 Comment newComment = _findNodeCovering(newUnit, offset, offset); |
| 1344 logger.log('oldComment.beginToken: ${oldComment.beginToken}'); | 1354 logger.log('oldComment.beginToken: ${oldComment.beginToken}'); |
| 1345 logger.log('newComment.beginToken: ${newComment.beginToken}'); | 1355 logger.log('newComment.beginToken: ${newComment.beginToken}'); |
| 1346 _updateOffset = oldToken.offset - 1; | 1356 _updateOffset = oldToken.offset - 1; |
| 1347 // update token references | 1357 // update token references |
| 1348 _shiftTokens(firstPair.oldToken); | 1358 _shiftTokens(firstPair.oldToken); |
| 1349 _setPrecedingComments(oldToken, newComment.tokens.first); | 1359 _setPrecedingComments(oldToken, newComment.tokens.first); |
| 1350 // replace node | 1360 // replace node |
| 1351 NodeReplacer.replace(oldComment, newComment); | 1361 NodeReplacer.replace(oldComment, newComment); |
| 1352 // update elements | 1362 // update elements |
| 1353 IncrementalResolver incrementalResolver = new IncrementalResolver( | 1363 IncrementalResolver incrementalResolver = new IncrementalResolver( |
| 1354 _unitElement, | 1364 _unitElement, |
| 1355 _updateOffset, | 1365 _updateOffset, |
| 1356 _updateEndOld, | 1366 _updateEndOld, |
| 1357 _updateEndNew); | 1367 _updateEndNew); |
| 1358 incrementalResolver._updateElementNameOffsets(); | 1368 incrementalResolver._updateElementNameOffsets(); |
| 1359 _updateEntry(); | 1369 _updateEntry(); |
| 1360 // resolve references in the comment | 1370 // resolve references in the comment |
| 1361 incrementalResolver._resolveReferences(newComment); | 1371 incrementalResolver._resolveReferences(newComment); |
| 1372 // OK |
| 1373 return true; |
| 1362 } | 1374 } |
| 1363 | 1375 |
| 1364 Token _scan(String code) { | 1376 Token _scan(String code) { |
| 1365 RecordingErrorListener errorListener = new RecordingErrorListener(); | 1377 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 1366 CharSequenceReader reader = new CharSequenceReader(code); | 1378 CharSequenceReader reader = new CharSequenceReader(code); |
| 1367 Scanner scanner = new Scanner(_unitSource, reader, errorListener); | 1379 Scanner scanner = new Scanner(_unitSource, reader, errorListener); |
| 1368 Token token = scanner.tokenize(); | 1380 Token token = scanner.tokenize(); |
| 1369 _newScanErrors = errorListener.errors; | 1381 _newScanErrors = errorListener.errors; |
| 1370 return token; | 1382 return token; |
| 1371 } | 1383 } |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1791 String toString() => name; | 1803 String toString() => name; |
| 1792 } | 1804 } |
| 1793 | 1805 |
| 1794 | 1806 |
| 1795 class _TokenPair { | 1807 class _TokenPair { |
| 1796 final _TokenDifferenceKind kind; | 1808 final _TokenDifferenceKind kind; |
| 1797 final Token oldToken; | 1809 final Token oldToken; |
| 1798 final Token newToken; | 1810 final Token newToken; |
| 1799 _TokenPair(this.kind, this.oldToken, this.newToken); | 1811 _TokenPair(this.kind, this.oldToken, this.newToken); |
| 1800 } | 1812 } |
| OLD | NEW |