| 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/context/cache.dart' | 10 import 'package:analyzer/src/context/cache.dart' |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 _assertSameAnnotations(node, element); | 354 _assertSameAnnotations(node, element); |
| 355 _assertEquals(node.isStatic, element.isStatic); | 355 _assertEquals(node.isStatic, element.isStatic); |
| 356 _assertSameType(node.returnType, element.returnType); | 356 _assertSameType(node.returnType, element.returnType); |
| 357 _assertCompatibleParameters(node.parameters, element.parameters); | 357 _assertCompatibleParameters(node.parameters, element.parameters); |
| 358 _assertBody(node.body, element); | 358 _assertBody(node.body, element); |
| 359 _removedElements.remove(element); | 359 _removedElements.remove(element); |
| 360 // matches, update the existing element | 360 // matches, update the existing element |
| 361 node.name.staticElement = element; | 361 node.name.staticElement = element; |
| 362 _setLocalElements(element, newElement); | 362 _setLocalElements(element, newElement); |
| 363 } on _DeclarationMismatchException { | 363 } on _DeclarationMismatchException { |
| 364 _addedElements.add(newElement); | |
| 365 _removeElement(element); | 364 _removeElement(element); |
| 366 // add new element | 365 // add new element |
| 367 if (newElement is MethodElement) { | 366 if (newElement != null) { |
| 368 List<MethodElement> methods = _enclosingClass.methods; | 367 _addedElements.add(newElement); |
| 369 methods.add(newElement); | 368 if (newElement is MethodElement) { |
| 370 _enclosingClass.methods = methods; | 369 List<MethodElement> methods = _enclosingClass.methods; |
| 371 } else { | 370 methods.add(newElement); |
| 372 List<PropertyAccessorElement> accessors = _enclosingClass.accessors; | 371 _enclosingClass.methods = methods; |
| 373 accessors.add(newElement); | 372 } else { |
| 374 _enclosingClass.accessors = accessors; | 373 List<PropertyAccessorElement> accessors = _enclosingClass.accessors; |
| 374 accessors.add(newElement); |
| 375 _enclosingClass.accessors = accessors; |
| 376 } |
| 375 } | 377 } |
| 376 } | 378 } |
| 377 } | 379 } |
| 378 | 380 |
| 379 @override | 381 @override |
| 380 visitPartDirective(PartDirective node) { | 382 visitPartDirective(PartDirective node) { |
| 381 String uri = _getStringValue(node.uri); | 383 String uri = _getStringValue(node.uri); |
| 382 if (uri != null) { | 384 if (uri != null) { |
| 383 CompilationUnitElement element = | 385 CompilationUnitElement element = |
| 384 _findUriReferencedElement(_enclosingLibrary.parts, uri); | 386 _findUriReferencedElement(_enclosingLibrary.parts, uri); |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 for (int i = 0; i < length; i++) { | 785 for (int i = 0; i < length; i++) { |
| 784 if (identical(elements[i], element)) { | 786 if (identical(elements[i], element)) { |
| 785 elements.removeAt(i); | 787 elements.removeAt(i); |
| 786 return; | 788 return; |
| 787 } | 789 } |
| 788 } | 790 } |
| 789 } | 791 } |
| 790 | 792 |
| 791 static void _setLocalElements( | 793 static void _setLocalElements( |
| 792 ExecutableElementImpl to, ExecutableElement from) { | 794 ExecutableElementImpl to, ExecutableElement from) { |
| 793 to.functions = from.functions; | 795 if (from != null) { |
| 794 to.labels = from.labels; | 796 to.functions = from.functions; |
| 795 to.localVariables = from.localVariables; | 797 to.labels = from.labels; |
| 796 to.parameters = from.parameters; | 798 to.localVariables = from.localVariables; |
| 799 to.parameters = from.parameters; |
| 800 } |
| 797 } | 801 } |
| 798 } | 802 } |
| 799 | 803 |
| 800 /** | 804 /** |
| 801 * Describes how declarations match an existing elements model. | 805 * Describes how declarations match an existing elements model. |
| 802 */ | 806 */ |
| 803 class DeclarationMatchKind { | 807 class DeclarationMatchKind { |
| 804 /** | 808 /** |
| 805 * Complete match, no API changes. | 809 * Complete match, no API changes. |
| 806 */ | 810 */ |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1388 logger.log('Failure: changes in constant constructor initializers' | 1392 logger.log('Failure: changes in constant constructor initializers' |
| 1389 ' may cause external changes in constant objects.'); | 1393 ' may cause external changes in constant objects.'); |
| 1390 return false; | 1394 return false; |
| 1391 } | 1395 } |
| 1392 if (oldParent is FunctionDeclaration && | 1396 if (oldParent is FunctionDeclaration && |
| 1393 newParent is FunctionDeclaration || | 1397 newParent is FunctionDeclaration || |
| 1394 oldParent is MethodDeclaration && | 1398 oldParent is MethodDeclaration && |
| 1395 newParent is MethodDeclaration || | 1399 newParent is MethodDeclaration || |
| 1396 oldParent is ConstructorDeclaration && | 1400 oldParent is ConstructorDeclaration && |
| 1397 newParent is ConstructorDeclaration) { | 1401 newParent is ConstructorDeclaration) { |
| 1398 oldNode = oldParent; | 1402 Element oldElement = (oldParent as Declaration).element; |
| 1399 newNode = newParent; | 1403 if (new DeclarationMatcher().matches(newParent, oldElement) == |
| 1400 found = true; | 1404 DeclarationMatchKind.MATCH) { |
| 1405 oldNode = oldParent; |
| 1406 newNode = newParent; |
| 1407 found = true; |
| 1408 } |
| 1401 } | 1409 } |
| 1402 if (oldParent is FunctionBody && newParent is FunctionBody) { | 1410 if (oldParent is FunctionBody && newParent is FunctionBody) { |
| 1403 oldNode = oldParent; | 1411 oldNode = oldParent; |
| 1404 newNode = newParent; | 1412 newNode = newParent; |
| 1405 found = true; | 1413 found = true; |
| 1406 break; | 1414 break; |
| 1407 } | 1415 } |
| 1408 } | 1416 } |
| 1409 if (!found) { | 1417 if (!found) { |
| 1410 logger.log('Failure: no enclosing function body or executable.'); | 1418 logger.log('Failure: no enclosing function body or executable.'); |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 @override | 2004 @override |
| 1997 String toString() => name; | 2005 String toString() => name; |
| 1998 } | 2006 } |
| 1999 | 2007 |
| 2000 class _TokenPair { | 2008 class _TokenPair { |
| 2001 final _TokenDifferenceKind kind; | 2009 final _TokenDifferenceKind kind; |
| 2002 final Token oldToken; | 2010 final Token oldToken; |
| 2003 final Token newToken; | 2011 final Token newToken; |
| 2004 _TokenPair(this.kind, this.oldToken, this.newToken); | 2012 _TokenPair(this.kind, this.oldToken, this.newToken); |
| 2005 } | 2013 } |
| OLD | NEW |