Chromium Code Reviews| 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 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1461 } | 1461 } |
| 1462 // Find nodes covering the "old" and "new" token ranges. | 1462 // Find nodes covering the "old" and "new" token ranges. |
| 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); |
|
skybrian
2016/01/20 06:29:50
It would be clearer to rename the function to _get
| |
| 1472 List<AstNode> newParents = _getParents(newNode); | 1472 List<AstNode> newParents = _getParents(newNode); |
| 1473 int length = math.min(oldParents.length, newParents.length); | 1473 int length = math.min(oldParents.length, newParents.length); |
| 1474 bool found = false; | 1474 bool found = false; |
| 1475 for (int i = 0; i < length; i++) { | 1475 for (int i = 0; i < length; i++) { |
| 1476 AstNode oldParent = oldParents[i]; | 1476 AstNode oldParent = oldParents[i]; |
| 1477 AstNode newParent = newParents[i]; | 1477 AstNode newParent = newParents[i]; |
| 1478 if (oldParent is ConstructorInitializer || | 1478 if (oldParent is CompilationUnit && newParent is CompilationUnit) { |
| 1479 newParent is ConstructorInitializer) { | 1479 int oldLength = oldParent.declarations.length; |
| 1480 logger.log('Failure: changes in constant constructor initializers' | 1480 int newLength = newParent.declarations.length; |
| 1481 ' may cause external changes in constant objects.'); | 1481 if (oldLength != newLength) { |
| 1482 return false; | 1482 logger.log( |
| 1483 } | 1483 'Failure: unit declarations mismatch $oldLength vs. $newLeng th'); |
| 1484 if (oldParent is FunctionDeclaration && | 1484 return false; |
| 1485 } | |
| 1486 } else if (oldParent is ClassDeclaration && | |
| 1487 newParent is ClassDeclaration) { | |
| 1488 int oldLength = oldParent.members.length; | |
| 1489 int newLength = newParent.members.length; | |
| 1490 if (oldLength != newLength) { | |
| 1491 logger.log( | |
| 1492 'Failure: class declarations mismatch $oldLength vs. $newLen gth'); | |
| 1493 return false; | |
| 1494 } | |
| 1495 } else if (oldParent is FunctionDeclaration && | |
| 1485 newParent is FunctionDeclaration || | 1496 newParent is FunctionDeclaration || |
| 1497 oldParent is ConstructorDeclaration && | |
| 1498 newParent is ConstructorDeclaration || | |
| 1486 oldParent is MethodDeclaration && | 1499 oldParent is MethodDeclaration && |
| 1487 newParent is MethodDeclaration || | 1500 newParent is MethodDeclaration) { |
| 1488 oldParent is ConstructorDeclaration && | |
| 1489 newParent is ConstructorDeclaration) { | |
| 1490 Element oldElement = (oldParent as Declaration).element; | 1501 Element oldElement = (oldParent as Declaration).element; |
| 1491 if (new DeclarationMatcher().matches(newParent, oldElement) == | 1502 if (new DeclarationMatcher().matches(newParent, oldElement) == |
| 1492 DeclarationMatchKind.MATCH) { | 1503 DeclarationMatchKind.MATCH) { |
| 1493 oldNode = oldParent; | 1504 oldNode = oldParent; |
| 1494 newNode = newParent; | 1505 newNode = newParent; |
| 1495 found = true; | 1506 found = true; |
| 1507 } else { | |
| 1508 return false; | |
| 1496 } | 1509 } |
| 1497 } | 1510 } else if (oldParent is ConstructorInitializer || |
| 1498 if (oldParent is FunctionBody || newParent is FunctionBody) { | 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) { | |
| 1499 if (oldParent is BlockFunctionBody && | 1516 if (oldParent is BlockFunctionBody && |
| 1500 newParent is BlockFunctionBody) { | 1517 newParent is BlockFunctionBody) { |
| 1501 oldNode = oldParent; | 1518 oldNode = oldParent; |
| 1502 newNode = newParent; | 1519 newNode = newParent; |
| 1503 found = true; | 1520 found = true; |
| 1504 break; | 1521 break; |
| 1505 } | 1522 } |
| 1506 logger.log('Failure: not a block function body.'); | 1523 logger.log('Failure: not a block function body.'); |
| 1507 return false; | 1524 return false; |
| 1525 } else if (oldParent is FieldDeclaration && | |
| 1526 newParent is FieldDeclaration || | |
| 1527 oldParent is FunctionExpression && | |
| 1528 newParent is FunctionExpression || | |
| 1529 oldParent is VariableDeclaration && | |
| 1530 newParent is VariableDeclaration) { | |
| 1531 // skip | |
| 1532 } else { | |
| 1533 logger.log('Failure: old and new parent mismatch' | |
| 1534 ' ${oldParent.runtimeType} vs. ${newParent.runtimeType}'); | |
| 1535 return false; | |
| 1508 } | 1536 } |
| 1509 } | 1537 } |
| 1510 if (!found) { | 1538 if (!found) { |
| 1511 logger.log('Failure: no enclosing function body or executable.'); | 1539 logger.log('Failure: no enclosing function body or executable.'); |
| 1512 return false; | 1540 return false; |
| 1513 } | 1541 } |
| 1514 // fail if a comment change outside the bodies | 1542 // fail if a comment change outside the bodies |
| 1515 if (firstPair.kind == _TokenDifferenceKind.COMMENT) { | 1543 if (firstPair.kind == _TokenDifferenceKind.COMMENT) { |
| 1516 if (beginOffsetOld <= oldNode.offset || | 1544 if (beginOffsetOld <= oldNode.offset || |
| 1517 beginOffsetNew <= newNode.offset) { | 1545 beginOffsetNew <= newNode.offset) { |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2111 @override | 2139 @override |
| 2112 String toString() => name; | 2140 String toString() => name; |
| 2113 } | 2141 } |
| 2114 | 2142 |
| 2115 class _TokenPair { | 2143 class _TokenPair { |
| 2116 final _TokenDifferenceKind kind; | 2144 final _TokenDifferenceKind kind; |
| 2117 final Token oldToken; | 2145 final Token oldToken; |
| 2118 final Token newToken; | 2146 final Token newToken; |
| 2119 _TokenPair(this.kind, this.oldToken, this.newToken); | 2147 _TokenPair(this.kind, this.oldToken, this.newToken); |
| 2120 } | 2148 } |
| OLD | NEW |