| 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 'package:analyzer/src/generated/error_verifier.dart'; | 10 import 'package:analyzer/src/generated/error_verifier.dart'; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 272 } |
| 273 | 273 |
| 274 @override | 274 @override |
| 275 visitMethodDeclaration(MethodDeclaration node) { | 275 visitMethodDeclaration(MethodDeclaration node) { |
| 276 // prepare element name | 276 // prepare element name |
| 277 String name = node.name.name; | 277 String name = node.name.name; |
| 278 if (name == TokenType.MINUS.lexeme && | 278 if (name == TokenType.MINUS.lexeme && |
| 279 node.parameters.parameters.length == 0) { | 279 node.parameters.parameters.length == 0) { |
| 280 name = "unary-"; | 280 name = "unary-"; |
| 281 } | 281 } |
| 282 if (node.isSetter) { |
| 283 name += '='; |
| 284 } |
| 282 // prepare element | 285 // prepare element |
| 283 Token property = node.propertyKeyword; | 286 Token property = node.propertyKeyword; |
| 284 ExecutableElement element; | 287 ExecutableElement element; |
| 285 if (property == null) { | 288 if (property == null) { |
| 286 element = _findElement(_enclosingClass.methods, name); | 289 element = _findElement(_enclosingClass.methods, name); |
| 287 } else { | 290 } else { |
| 288 element = _findElement(_enclosingClass.accessors, name); | 291 element = _findElement(_enclosingClass.accessors, name); |
| 289 } | 292 } |
| 290 // process element | 293 // process element |
| 291 _processElement(element); | 294 _processElement(element); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 437 } |
| 435 | 438 |
| 436 void _assertSameType(TypeName node, DartType type) { | 439 void _assertSameType(TypeName node, DartType type) { |
| 437 // no return type == dynamic | 440 // no return type == dynamic |
| 438 if (node == null) { | 441 if (node == null) { |
| 439 return _assertTrue(type == null || type.isDynamic); | 442 return _assertTrue(type == null || type.isDynamic); |
| 440 } | 443 } |
| 441 if (type == null) { | 444 if (type == null) { |
| 442 return _assertTrue(false); | 445 return _assertTrue(false); |
| 443 } | 446 } |
| 447 // prepare name |
| 448 Identifier nameIdentifier = node.name; |
| 449 if (nameIdentifier is PrefixedIdentifier) { |
| 450 nameIdentifier = (nameIdentifier as PrefixedIdentifier).identifier; |
| 451 } |
| 452 String nodeName = nameIdentifier.name; |
| 444 // check specific type kinds | 453 // check specific type kinds |
| 445 String nodeName = node.name.name; | |
| 446 if (type is InterfaceType) { | 454 if (type is InterfaceType) { |
| 447 _assertEquals(nodeName, type.name); | 455 _assertEquals(nodeName, type.name); |
| 448 // check arguments | 456 // check arguments |
| 449 TypeArgumentList nodeArgumentList = node.typeArguments; | 457 TypeArgumentList nodeArgumentList = node.typeArguments; |
| 450 List<DartType> typeArguments = type.typeArguments; | 458 List<DartType> typeArguments = type.typeArguments; |
| 451 if (nodeArgumentList == null) { | 459 if (nodeArgumentList == null) { |
| 452 // Node doesn't have type arguments, so all type argument of the | 460 // Node doesn't have type arguments, so all type arguments of the |
| 453 // element must be "dynamic". | 461 // element must be "dynamic". |
| 454 for (DartType typeArgument in typeArguments) { | 462 for (DartType typeArgument in typeArguments) { |
| 455 _assertTrue(typeArgument.isDynamic); | 463 _assertTrue(typeArgument.isDynamic); |
| 456 } | 464 } |
| 457 } else { | 465 } else { |
| 458 List<TypeName> nodeArguments = nodeArgumentList.arguments; | 466 List<TypeName> nodeArguments = nodeArgumentList.arguments; |
| 459 _assertSameTypes(nodeArguments, typeArguments); | 467 _assertSameTypes(nodeArguments, typeArguments); |
| 460 } | 468 } |
| 461 } else if (type is TypeParameterType) { | 469 } else if (type is TypeParameterType) { |
| 462 _assertEquals(nodeName, type.name); | 470 _assertEquals(nodeName, type.name); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 * | 699 * |
| 692 * [node] - the node defining the portion of the element model being tested. | 700 * [node] - the node defining the portion of the element model being tested. |
| 693 * | 701 * |
| 694 * Throws [AnalysisException] if the correctness of the element model cannot | 702 * Throws [AnalysisException] if the correctness of the element model cannot |
| 695 * be determined. | 703 * be determined. |
| 696 */ | 704 */ |
| 697 bool _elementModelChanged(AstNode node) { | 705 bool _elementModelChanged(AstNode node) { |
| 698 // If we are replacing the whole declaration (e.g. rename a parameter), we | 706 // If we are replacing the whole declaration (e.g. rename a parameter), we |
| 699 // can try to find the corresponding Element in the enclosing one, see if it | 707 // can try to find the corresponding Element in the enclosing one, see if it |
| 700 // is compatible, and if 'yes', then restore and update it. | 708 // is compatible, and if 'yes', then restore and update it. |
| 709 // TODO(scheglov) This should be rewritten. It causes validating the whole |
| 710 // class, when just one method is changed. |
| 701 if (node is Declaration) { | 711 if (node is Declaration) { |
| 702 node = node.parent; | 712 node = node.parent; |
| 703 } | 713 } |
| 704 Element element = _getElement(node); | 714 Element element = _getElement(node); |
| 705 if (element == null) { | 715 if (element == null) { |
| 706 throw new AnalysisException( | 716 throw new AnalysisException( |
| 707 "Cannot resolve node: a ${node.runtimeType} does not define an element
"); | 717 "Cannot resolve node: a ${node.runtimeType} does not define an element
"); |
| 708 } | 718 } |
| 709 DeclarationMatcher matcher = new DeclarationMatcher(); | 719 DeclarationMatcher matcher = new DeclarationMatcher(); |
| 710 return !matcher.matches(node, element); | 720 return !matcher.matches(node, element); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 oldNode = oldParent; | 917 oldNode = oldParent; |
| 908 newNode = newParent; | 918 newNode = newParent; |
| 909 found = true; | 919 found = true; |
| 910 break; | 920 break; |
| 911 } | 921 } |
| 912 } | 922 } |
| 913 if (!found) { | 923 if (!found) { |
| 914 return false; | 924 return false; |
| 915 } | 925 } |
| 916 } | 926 } |
| 927 // print('oldNode: $oldNode'); |
| 928 // print('newNode: $newNode'); |
| 917 // prepare update range | 929 // prepare update range |
| 918 _updateOffset = oldNode.offset; | 930 _updateOffset = oldNode.offset; |
| 919 _updateEndOld = oldNode.end; | 931 _updateEndOld = oldNode.end; |
| 920 _updateEndNew = newNode.end; | 932 _updateEndNew = newNode.end; |
| 921 _updateDelta = _updateEndNew - _updateEndOld; | 933 _updateDelta = _updateEndNew - _updateEndOld; |
| 922 // replace node | 934 // replace node |
| 923 NodeReplacer.replace(oldNode, newNode); | 935 NodeReplacer.replace(oldNode, newNode); |
| 924 // update token references | 936 // update token references |
| 925 { | 937 { |
| 926 Token oldBeginToken = oldNode.beginToken; | 938 Token oldBeginToken = oldNode.beginToken; |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1389 _elements[node] = node.staticElement; | 1401 _elements[node] = node.staticElement; |
| 1390 } | 1402 } |
| 1391 } | 1403 } |
| 1392 | 1404 |
| 1393 | 1405 |
| 1394 class _TokenPair { | 1406 class _TokenPair { |
| 1395 final Token oldToken; | 1407 final Token oldToken; |
| 1396 final Token newToken; | 1408 final Token newToken; |
| 1397 _TokenPair(this.oldToken, this.newToken); | 1409 _TokenPair(this.oldToken, this.newToken); |
| 1398 } | 1410 } |
| OLD | NEW |