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

Side by Side Diff: pkg/analyzer/lib/src/summary/index_unit.dart

Issue 1896023005: Issue 26207. Fix for renaming top-level functions with offset 0. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/token.dart'; 6 import 'package:analyzer/dart/ast/token.dart';
7 import 'package:analyzer/dart/ast/visitor.dart'; 7 import 'package:analyzer/dart/ast/visitor.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart'; 9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/src/dart/element/member.dart'; 10 import 'package:analyzer/src/dart/element/member.dart';
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 197 }
198 } 198 }
199 throw new StateError(element.toString()); 199 throw new StateError(element.toString());
200 } 200 }
201 201
202 /** 202 /**
203 * Return a new [ElementInfo] for the given [element] in the given [unitId]. 203 * Return a new [ElementInfo] for the given [element] in the given [unitId].
204 * This method is static, so it cannot add any information to the index. 204 * This method is static, so it cannot add any information to the index.
205 */ 205 */
206 static ElementInfo newElementInfo(int unitId, Element element) { 206 static ElementInfo newElementInfo(int unitId, Element element) {
207 int offset = null;
207 IndexSyntheticElementKind kind = IndexSyntheticElementKind.notSynthetic; 208 IndexSyntheticElementKind kind = IndexSyntheticElementKind.notSynthetic;
208 if (element.isSynthetic) { 209 if (element.isSynthetic) {
209 if (element is ConstructorElement) { 210 if (element is ConstructorElement) {
210 kind = IndexSyntheticElementKind.constructor; 211 kind = IndexSyntheticElementKind.constructor;
211 element = element.enclosingElement; 212 element = element.enclosingElement;
212 } else if (element is FunctionElement && element.name == 'loadLibrary') { 213 } else if (element is FunctionElement && element.name == 'loadLibrary') {
213 kind = IndexSyntheticElementKind.loadLibrary; 214 kind = IndexSyntheticElementKind.loadLibrary;
214 element = element.library; 215 element = element.library;
215 } else if (element is FieldElement) { 216 } else if (element is FieldElement) {
216 FieldElement field = element; 217 FieldElement field = element;
(...skipping 18 matching lines...) Expand all
235 } 236 }
236 } else if (element is TopLevelVariableElement) { 237 } else if (element is TopLevelVariableElement) {
237 TopLevelVariableElement property = element; 238 TopLevelVariableElement property = element;
238 kind = IndexSyntheticElementKind.topLevelVariable; 239 kind = IndexSyntheticElementKind.topLevelVariable;
239 element = property.getter; 240 element = property.getter;
240 element ??= property.setter; 241 element ??= property.setter;
241 } else { 242 } else {
242 throw new ArgumentError( 243 throw new ArgumentError(
243 'Unsupported synthetic element ${element.runtimeType}'); 244 'Unsupported synthetic element ${element.runtimeType}');
244 } 245 }
245 } 246 } else if (element is LibraryElement || element is CompilationUnitElement) {
246 int offset = element.nameOffset; 247 kind = IndexSyntheticElementKind.unit;
247 if (element is LibraryElement || element is CompilationUnitElement) {
248 offset = 0; 248 offset = 0;
249 } 249 }
250 offset ??= element.nameOffset;
250 return new ElementInfo(unitId, offset, kind); 251 return new ElementInfo(unitId, offset, kind);
251 } 252 }
252 } 253 }
253 254
254 /** 255 /**
255 * Information about a single defined name. Any [_DefinedNameInfo] is always 256 * Information about a single defined name. Any [_DefinedNameInfo] is always
256 * part of a [_UnitIndexAssembler], so [offset] should be understood within the 257 * part of a [_UnitIndexAssembler], so [offset] should be understood within the
257 * context of the compilation unit pointed to by the [_UnitIndexAssembler]. 258 * context of the compilation unit pointed to by the [_UnitIndexAssembler].
258 */ 259 */
259 class _DefinedNameInfo { 260 class _DefinedNameInfo {
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 usedNameOffsets: nameRelations.map((r) => r.offset).toList(), 828 usedNameOffsets: nameRelations.map((r) => r.offset).toList(),
828 usedNameIsQualifiedFlags: 829 usedNameIsQualifiedFlags:
829 nameRelations.map((r) => r.isQualified).toList()); 830 nameRelations.map((r) => r.isQualified).toList());
830 } 831 }
831 832
832 void defineName(String name, IndexNameKind kind, int offset) { 833 void defineName(String name, IndexNameKind kind, int offset) {
833 _StringInfo nameInfo = pkg._getStringInfo(name); 834 _StringInfo nameInfo = pkg._getStringInfo(name);
834 definedNames.add(new _DefinedNameInfo(nameInfo, kind, offset)); 835 definedNames.add(new _DefinedNameInfo(nameInfo, kind, offset));
835 } 836 }
836 } 837 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/idl.dart ('k') | pkg/analyzer/test/src/summary/index_unit_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698