Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1054)

Side by Side Diff: pkg/analyzer/lib/src/generated/incremental_resolver.dart

Issue 1667023002: Issue 25657. Update offsets of cloned constant initializers. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2050 matching lines...) Expand 10 before | Expand all | Expand 10 after
2061 2061
2062 _ElementOffsetUpdater(this.updateOffset, this.updateDelta, this.cache); 2062 _ElementOffsetUpdater(this.updateOffset, this.updateDelta, this.cache);
2063 2063
2064 @override 2064 @override
2065 visitElement(Element element) { 2065 visitElement(Element element) {
2066 // name offset 2066 // name offset
2067 int nameOffset = element.nameOffset; 2067 int nameOffset = element.nameOffset;
2068 if (nameOffset > updateOffset) { 2068 if (nameOffset > updateOffset) {
2069 cache.remove(element); 2069 cache.remove(element);
2070 (element as ElementImpl).nameOffset = nameOffset + updateDelta; 2070 (element as ElementImpl).nameOffset = nameOffset + updateDelta;
2071 if (element is ConstVariableElement) {
2072 ConstVariableElement constVariable = element as ConstVariableElement;
2073 Expression initializer = constVariable.constantInitializer;
2074 if (initializer != null) {
2075 _shiftTokens(initializer.beginToken);
2076 }
2077 }
2071 } 2078 }
2072 // visible range 2079 // visible range
2073 if (element is LocalElement) { 2080 if (element is LocalElement) {
2074 SourceRange visibleRange = element.visibleRange; 2081 SourceRange visibleRange = element.visibleRange;
2075 if (visibleRange != null && visibleRange.offset > updateOffset) { 2082 if (visibleRange != null) {
2076 int newOffset = visibleRange.offset + updateDelta; 2083 int oldOffset = visibleRange.offset;
2077 int length = visibleRange.length; 2084 int oldLength = visibleRange.length;
2078 if (element is FunctionElementImpl) { 2085 int newOffset = oldOffset;
2079 element.setVisibleRange(newOffset, length); 2086 int newLength = oldLength;
2080 } else if (element is LocalVariableElementImpl) { 2087 newOffset += oldOffset > updateOffset ? updateDelta : 0;
2081 element.setVisibleRange(newOffset, length); 2088 newLength += visibleRange.contains(updateOffset) ? updateDelta : 0;
2082 } else if (element is ParameterElementImpl) { 2089 if (newOffset != oldOffset || newLength != oldLength) {
2083 element.setVisibleRange(newOffset, length); 2090 if (element is FunctionElementImpl) {
2091 element.setVisibleRange(newOffset, newLength);
2092 } else if (element is LocalVariableElementImpl) {
2093 element.setVisibleRange(newOffset, newLength);
2094 } else if (element is ParameterElementImpl) {
2095 element.setVisibleRange(newOffset, newLength);
2096 }
2084 } 2097 }
2085 } 2098 }
2086 } 2099 }
2087 super.visitElement(element); 2100 super.visitElement(element);
2088 } 2101 }
2102
2103 void _shiftTokens(Token token) {
2104 while (token != null) {
2105 if (token.offset > updateOffset) {
2106 token.offset += updateDelta;
2107 }
2108 // comments
2109 _shiftTokens(token.precedingComments);
2110 if (token is DocumentationCommentToken) {
2111 for (Token reference in token.references) {
2112 _shiftTokens(reference);
2113 }
2114 }
2115 // next
2116 if (token.type == TokenType.EOF) {
2117 break;
2118 }
2119 token = token.next;
2120 }
2121 }
2089 } 2122 }
2090 2123
2091 class _ElementsGatherer extends GeneralizingElementVisitor { 2124 class _ElementsGatherer extends GeneralizingElementVisitor {
2092 final DeclarationMatcher matcher; 2125 final DeclarationMatcher matcher;
2093 2126
2094 _ElementsGatherer(this.matcher); 2127 _ElementsGatherer(this.matcher);
2095 2128
2096 void addElements(List<Element> elements) { 2129 void addElements(List<Element> elements) {
2097 for (Element element in elements) { 2130 for (Element element in elements) {
2098 if (!element.isSynthetic) { 2131 if (!element.isSynthetic) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2158 @override 2191 @override
2159 String toString() => name; 2192 String toString() => name;
2160 } 2193 }
2161 2194
2162 class _TokenPair { 2195 class _TokenPair {
2163 final _TokenDifferenceKind kind; 2196 final _TokenDifferenceKind kind;
2164 final Token oldToken; 2197 final Token oldToken;
2165 final Token newToken; 2198 final Token newToken;
2166 _TokenPair(this.kind, this.oldToken, this.newToken); 2199 _TokenPair(this.kind, this.oldToken, this.newToken);
2167 } 2200 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698