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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 * Determines how elements model corresponding to the given [node] differs | 111 * Determines how elements model corresponding to the given [node] differs |
| 112 * from the [element]. | 112 * from the [element]. |
| 113 */ | 113 */ |
| 114 DeclarationMatchKind matches(AstNode node, Element element) { | 114 DeclarationMatchKind matches(AstNode node, Element element) { |
| 115 logger.enter('match $element @ ${element.nameOffset}'); | 115 logger.enter('match $element @ ${element.nameOffset}'); |
| 116 try { | 116 try { |
| 117 _captureEnclosingElements(element); | 117 _captureEnclosingElements(element); |
| 118 _gatherElements(element); | 118 _gatherElements(element); |
| 119 node.accept(this); | 119 node.accept(this); |
| 120 } on _DeclarationMismatchException { | 120 } on _DeclarationMismatchException { |
| 121 logger.log("mismatched"); | |
| 121 return DeclarationMatchKind.MISMATCH; | 122 return DeclarationMatchKind.MISMATCH; |
| 122 } finally { | 123 } finally { |
| 123 logger.exit(); | 124 logger.exit(); |
| 124 } | 125 } |
| 125 // no API changes | 126 // no API changes |
| 126 if (_removedElements.isEmpty && _addedElements.isEmpty) { | 127 if (_removedElements.isEmpty && _addedElements.isEmpty) { |
| 128 logger.log("no API changes"); | |
| 127 return DeclarationMatchKind.MATCH; | 129 return DeclarationMatchKind.MATCH; |
| 128 } | 130 } |
| 129 // simple API change | 131 // simple API change |
| 130 logger.log('_removedElements: $_removedElements'); | 132 logger.log('_removedElements: $_removedElements'); |
| 131 logger.log('_addedElements: $_addedElements'); | 133 logger.log('_addedElements: $_addedElements'); |
| 132 _removedElements.forEach(_removeElement); | 134 _removedElements.forEach(_removeElement); |
| 133 if (_removedElements.length <= 1 && _addedElements.length == 1) { | 135 if (_removedElements.length <= 1 && _addedElements.length == 1) { |
| 134 return DeclarationMatchKind.MISMATCH_OK; | 136 return DeclarationMatchKind.MISMATCH_OK; |
| 135 } | 137 } |
| 136 // something more complex | 138 // something more complex |
| (...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2063 | 2065 |
| 2064 _ElementOffsetUpdater(this.updateOffset, this.updateDelta, this.cache); | 2066 _ElementOffsetUpdater(this.updateOffset, this.updateDelta, this.cache); |
| 2065 | 2067 |
| 2066 @override | 2068 @override |
| 2067 visitElement(Element element) { | 2069 visitElement(Element element) { |
| 2068 // name offset | 2070 // name offset |
| 2069 int nameOffset = element.nameOffset; | 2071 int nameOffset = element.nameOffset; |
| 2070 if (nameOffset > updateOffset) { | 2072 if (nameOffset > updateOffset) { |
| 2071 // TODO(scheglov) make sure that we don't put local variables | 2073 // TODO(scheglov) make sure that we don't put local variables |
| 2072 // and functions into the cache at all. | 2074 // and functions into the cache at all. |
| 2073 if (element is LocalVariableElement || | 2075 try { |
| 2074 element is FunctionElement && | 2076 (element as ElementImpl).nameOffset = nameOffset + updateDelta; |
| 2075 element.enclosingElement is ExecutableElement) { | 2077 } on StateError { |
|
skybrian
2016/02/17 01:23:41
StateError is definitely not the right exception,
| |
| 2076 cache.remove(element); | 2078 cache.remove(element); |
| 2079 (element as ElementImpl).nameOffset = nameOffset + updateDelta; | |
| 2077 } | 2080 } |
| 2078 (element as ElementImpl).nameOffset = nameOffset + updateDelta; | |
| 2079 if (element is ConstVariableElement) { | 2081 if (element is ConstVariableElement) { |
| 2080 ConstVariableElement constVariable = element as ConstVariableElement; | 2082 ConstVariableElement constVariable = element as ConstVariableElement; |
| 2081 Expression initializer = constVariable.constantInitializer; | 2083 Expression initializer = constVariable.constantInitializer; |
| 2082 if (initializer != null) { | 2084 if (initializer != null) { |
| 2083 _shiftTokens(initializer.beginToken); | 2085 _shiftTokens(initializer.beginToken); |
| 2084 } | 2086 } |
| 2085 } | 2087 } |
| 2086 } | 2088 } |
| 2087 // visible range | 2089 // visible range |
| 2088 if (element is LocalElement) { | 2090 if (element is LocalElement) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2199 @override | 2201 @override |
| 2200 String toString() => name; | 2202 String toString() => name; |
| 2201 } | 2203 } |
| 2202 | 2204 |
| 2203 class _TokenPair { | 2205 class _TokenPair { |
| 2204 final _TokenDifferenceKind kind; | 2206 final _TokenDifferenceKind kind; |
| 2205 final Token oldToken; | 2207 final Token oldToken; |
| 2206 final Token newToken; | 2208 final Token newToken; |
| 2207 _TokenPair(this.kind, this.oldToken, this.newToken); | 2209 _TokenPair(this.kind, this.oldToken, this.newToken); |
| 2208 } | 2210 } |
| OLD | NEW |