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 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2042 /** | 2042 /** |
2043 * Instances of the class [_DeclarationMismatchException] represent an exception | 2043 * Instances of the class [_DeclarationMismatchException] represent an exception |
2044 * that is thrown when the element model defined by a given AST structure does | 2044 * that is thrown when the element model defined by a given AST structure does |
2045 * not match an existing element model. | 2045 * not match an existing element model. |
2046 */ | 2046 */ |
2047 class _DeclarationMismatchException {} | 2047 class _DeclarationMismatchException {} |
2048 | 2048 |
2049 /** | 2049 /** |
2050 * Adjusts the location of each Element that moved. | 2050 * Adjusts the location of each Element that moved. |
2051 * | 2051 * |
2052 * Since operator== and hashCode of an Element are based | 2052 * Since `==` and `hashCode` of a local variable or function Element are based |
2053 * on the element location, we also need to remove each | 2053 * on the element name offsets, we also need to remove these elements from the |
2054 * moved element from the cache to avoid a memory leak. | 2054 * cache to avoid a memory leak. TODO(scheglov) fix and remove this |
2055 */ | 2055 */ |
2056 class _ElementOffsetUpdater extends GeneralizingElementVisitor { | 2056 class _ElementOffsetUpdater extends GeneralizingElementVisitor { |
2057 final int updateOffset; | 2057 final int updateOffset; |
2058 final int updateDelta; | 2058 final int updateDelta; |
2059 final AnalysisCache cache; | 2059 final AnalysisCache cache; |
2060 | 2060 |
2061 _ElementOffsetUpdater(this.updateOffset, this.updateDelta, this.cache); | 2061 _ElementOffsetUpdater(this.updateOffset, this.updateDelta, this.cache); |
2062 | 2062 |
2063 @override | 2063 @override |
2064 visitElement(Element element) { | 2064 visitElement(Element element) { |
2065 // name offset | 2065 // name offset |
2066 int nameOffset = element.nameOffset; | 2066 int nameOffset = element.nameOffset; |
2067 if (nameOffset > updateOffset) { | 2067 if (nameOffset > updateOffset) { |
2068 cache.remove(element); | 2068 // TODO(scheglov) make sure that we don't put local variables |
2069 // and functions into the cache at all. | |
2070 if (element is LocalVariableElement || | |
skybrian
2016/02/13 18:39:22
This check is missing DefaultParameterElementImpl
| |
2071 element is FunctionElement && | |
2072 element.enclosingElement is ExecutableElement) { | |
2073 cache.remove(element); | |
2074 } | |
2069 (element as ElementImpl).nameOffset = nameOffset + updateDelta; | 2075 (element as ElementImpl).nameOffset = nameOffset + updateDelta; |
2070 if (element is ConstVariableElement) { | 2076 if (element is ConstVariableElement) { |
2071 ConstVariableElement constVariable = element as ConstVariableElement; | 2077 ConstVariableElement constVariable = element as ConstVariableElement; |
2072 Expression initializer = constVariable.constantInitializer; | 2078 Expression initializer = constVariable.constantInitializer; |
2073 if (initializer != null) { | 2079 if (initializer != null) { |
2074 _shiftTokens(initializer.beginToken); | 2080 _shiftTokens(initializer.beginToken); |
2075 } | 2081 } |
2076 } | 2082 } |
2077 } | 2083 } |
2078 // visible range | 2084 // visible range |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2190 @override | 2196 @override |
2191 String toString() => name; | 2197 String toString() => name; |
2192 } | 2198 } |
2193 | 2199 |
2194 class _TokenPair { | 2200 class _TokenPair { |
2195 final _TokenDifferenceKind kind; | 2201 final _TokenDifferenceKind kind; |
2196 final Token oldToken; | 2202 final Token oldToken; |
2197 final Token newToken; | 2203 final Token newToken; |
2198 _TokenPair(this.kind, this.oldToken, this.newToken); | 2204 _TokenPair(this.kind, this.oldToken, this.newToken); |
2199 } | 2205 } |
OLD | NEW |