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

Side by Side Diff: pkg/analysis_server/lib/src/services/index/store/codec.dart

Issue 1080503003: Move getElementAt() to CompilationUnitElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/element.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 services.src.index.store.codec; 5 library services.src.index.store.codec;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analysis_server/src/services/index/index.dart'; 9 import 'package:analysis_server/src/services/index/index.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 /** 75 /**
76 * Returns an [Element] that corresponds to the given identifiers. 76 * Returns an [Element] that corresponds to the given identifiers.
77 */ 77 */
78 Element decode(AnalysisContext context, int fileId, int offset, int kindId) { 78 Element decode(AnalysisContext context, int fileId, int offset, int kindId) {
79 String filePath = _stringCodec.decode(fileId); 79 String filePath = _stringCodec.decode(fileId);
80 List<Source> unitSources = context.getSourcesWithFullName(filePath); 80 List<Source> unitSources = context.getSourcesWithFullName(filePath);
81 for (Source unitSource in unitSources) { 81 for (Source unitSource in unitSources) {
82 List<Source> libSources = context.getLibrariesContaining(unitSource); 82 List<Source> libSources = context.getLibrariesContaining(unitSource);
83 for (Source libSource in libSources) { 83 for (Source libSource in libSources) {
84 LibraryElement libraryElement = context.getLibraryElement(libSource); 84 CompilationUnitElement unitElement =
85 if (libraryElement == null) { 85 context.getCompilationUnitElement(unitSource, libSource);
86 if (unitElement == null) {
86 return null; 87 return null;
87 } 88 }
88 if (kindId == ElementKind.LIBRARY.ordinal) { 89 if (kindId == ElementKind.LIBRARY.ordinal) {
89 return libraryElement; 90 return unitElement.library;
90 } else if (kindId == ElementKind.COMPILATION_UNIT.ordinal) { 91 } else if (kindId == ElementKind.COMPILATION_UNIT.ordinal) {
91 for (CompilationUnitElement unit in libraryElement.units) { 92 return unitElement;
92 if (unit.source.fullName == filePath) {
93 return unit;
94 }
95 }
96 return null;
97 } else { 93 } else {
98 Element element = libraryElement.getElementAt(offset); 94 Element element = unitElement.getElementAt(offset);
99 if (element == null) { 95 if (element == null) {
100 return null; 96 return null;
101 } 97 }
102 if (element is ClassElement && kindId <= _CONSTRUCTOR_KIND_BASE) { 98 if (element is ClassElement && kindId <= _CONSTRUCTOR_KIND_BASE) {
103 int constructorIndex = -1 * (kindId - _CONSTRUCTOR_KIND_BASE); 99 int constructorIndex = -1 * (kindId - _CONSTRUCTOR_KIND_BASE);
104 return element.constructors[constructorIndex]; 100 return element.constructors[constructorIndex];
105 } 101 }
106 if (element is PropertyInducingElement) { 102 if (element is PropertyInducingElement) {
107 if (kindId == ElementKind.GETTER.ordinal) { 103 if (kindId == ElementKind.GETTER.ordinal) {
108 return element.getter; 104 return element.getter;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 int encode(String name) { 217 int encode(String name) {
222 int index = nameToIndex[name]; 218 int index = nameToIndex[name];
223 if (index == null) { 219 if (index == null) {
224 index = _indexToName.length; 220 index = _indexToName.length;
225 nameToIndex[name] = index; 221 nameToIndex[name] = index;
226 _indexToName.add(name); 222 _indexToName.add(name);
227 } 223 }
228 return index; 224 return index;
229 } 225 }
230 } 226 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698