| 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 analyzer.src.generated.incremental_resolver; | 5 library analyzer.src.generated.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/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1463 AstNode oldNode = | 1463 AstNode oldNode = |
| 1464 _findNodeCovering(_oldUnit, beginOffsetOld, endOffsetOld - 1); | 1464 _findNodeCovering(_oldUnit, beginOffsetOld, endOffsetOld - 1); |
| 1465 AstNode newNode = | 1465 AstNode newNode = |
| 1466 _findNodeCovering(newUnit, beginOffsetNew, endOffsetNew - 1); | 1466 _findNodeCovering(newUnit, beginOffsetNew, endOffsetNew - 1); |
| 1467 logger.log(() => 'oldNode: $oldNode'); | 1467 logger.log(() => 'oldNode: $oldNode'); |
| 1468 logger.log(() => 'newNode: $newNode'); | 1468 logger.log(() => 'newNode: $newNode'); |
| 1469 // Try to find the smallest common node, a FunctionBody currently. | 1469 // Try to find the smallest common node, a FunctionBody currently. |
| 1470 { | 1470 { |
| 1471 List<AstNode> oldParents = _getParents(oldNode); | 1471 List<AstNode> oldParents = _getParents(oldNode); |
| 1472 List<AstNode> newParents = _getParents(newNode); | 1472 List<AstNode> newParents = _getParents(newNode); |
| 1473 // fail if an initializer change |
| 1474 if (oldParents.any((n) => n is ConstructorInitializer) || |
| 1475 newParents.any((n) => n is ConstructorInitializer)) { |
| 1476 logger.log('Failure: a change in a constructor initializer'); |
| 1477 return false; |
| 1478 } |
| 1479 // find matching methods / bodies |
| 1473 int length = math.min(oldParents.length, newParents.length); | 1480 int length = math.min(oldParents.length, newParents.length); |
| 1474 bool found = false; | 1481 bool found = false; |
| 1475 for (int i = 0; i < length; i++) { | 1482 for (int i = 0; i < length; i++) { |
| 1476 AstNode oldParent = oldParents[i]; | 1483 AstNode oldParent = oldParents[i]; |
| 1477 AstNode newParent = newParents[i]; | 1484 AstNode newParent = newParents[i]; |
| 1478 if (oldParent is CompilationUnit && newParent is CompilationUnit) { | 1485 if (oldParent is CompilationUnit && newParent is CompilationUnit) { |
| 1479 int oldLength = oldParent.declarations.length; | 1486 int oldLength = oldParent.declarations.length; |
| 1480 int newLength = newParent.declarations.length; | 1487 int newLength = newParent.declarations.length; |
| 1481 if (oldLength != newLength) { | 1488 if (oldLength != newLength) { |
| 1482 logger.log( | 1489 logger.log( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1500 newParent is MethodDeclaration) { | 1507 newParent is MethodDeclaration) { |
| 1501 Element oldElement = (oldParent as Declaration).element; | 1508 Element oldElement = (oldParent as Declaration).element; |
| 1502 if (new DeclarationMatcher().matches(newParent, oldElement) == | 1509 if (new DeclarationMatcher().matches(newParent, oldElement) == |
| 1503 DeclarationMatchKind.MATCH) { | 1510 DeclarationMatchKind.MATCH) { |
| 1504 oldNode = oldParent; | 1511 oldNode = oldParent; |
| 1505 newNode = newParent; | 1512 newNode = newParent; |
| 1506 found = true; | 1513 found = true; |
| 1507 } else { | 1514 } else { |
| 1508 return false; | 1515 return false; |
| 1509 } | 1516 } |
| 1510 } else if (oldParent is ConstructorInitializer || | |
| 1511 newParent is ConstructorInitializer) { | |
| 1512 logger.log('Failure: changes in constant constructor initializers' | |
| 1513 ' may cause external changes in constant objects.'); | |
| 1514 return false; | |
| 1515 } else if (oldParent is FunctionBody && newParent is FunctionBody) { | 1517 } else if (oldParent is FunctionBody && newParent is FunctionBody) { |
| 1516 if (oldParent is BlockFunctionBody && | 1518 if (oldParent is BlockFunctionBody && |
| 1517 newParent is BlockFunctionBody) { | 1519 newParent is BlockFunctionBody) { |
| 1518 oldNode = oldParent; | 1520 oldNode = oldParent; |
| 1519 newNode = newParent; | 1521 newNode = newParent; |
| 1520 found = true; | 1522 found = true; |
| 1521 break; | 1523 break; |
| 1522 } | 1524 } |
| 1523 logger.log('Failure: not a block function body.'); | 1525 logger.log('Failure: not a block function body.'); |
| 1524 return false; | 1526 return false; |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2135 @override | 2137 @override |
| 2136 String toString() => name; | 2138 String toString() => name; |
| 2137 } | 2139 } |
| 2138 | 2140 |
| 2139 class _TokenPair { | 2141 class _TokenPair { |
| 2140 final _TokenDifferenceKind kind; | 2142 final _TokenDifferenceKind kind; |
| 2141 final Token oldToken; | 2143 final Token oldToken; |
| 2142 final Token newToken; | 2144 final Token newToken; |
| 2143 _TokenPair(this.kind, this.oldToken, this.newToken); | 2145 _TokenPair(this.kind, this.oldToken, this.newToken); |
| 2144 } | 2146 } |
| OLD | NEW |