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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart

Issue 1486663003: Ensure that a complete library element has constants evaluated (issue 24890) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years 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) 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.completion.dart.cache; 5 library services.completion.dart.cache;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analysis_server/src/protocol_server.dart' 10 import 'package:analysis_server/src/protocol_server.dart'
11 hide Element, ElementKind; 11 hide Element, ElementKind;
12 import 'package:analysis_server/src/services/completion/completion_manager.dart' ; 12 import 'package:analysis_server/src/services/completion/completion_manager.dart' ;
13 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 13 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
14 import 'package:analysis_server/src/services/completion/suggestion_builder.dart' ; 14 import 'package:analysis_server/src/services/completion/suggestion_builder.dart' ;
15 import 'package:analysis_server/src/services/search/search_engine.dart'; 15 import 'package:analysis_server/src/services/search/search_engine.dart';
16 import 'package:analyzer/src/generated/ast.dart'; 16 import 'package:analyzer/src/generated/ast.dart';
17 import 'package:analyzer/src/generated/element.dart'; 17 import 'package:analyzer/src/generated/element.dart';
18 import 'package:analyzer/src/generated/engine.dart'; 18 import 'package:analyzer/src/generated/engine.dart';
19 import 'package:analyzer/src/generated/resolver.dart'; 19 import 'package:analyzer/src/generated/resolver.dart';
20 import 'package:analyzer/src/generated/source.dart'; 20 import 'package:analyzer/src/generated/source.dart';
21 import 'package:analyzer/src/task/dart.dart';
21 22
22 /** 23 /**
23 * The `DartCompletionCache` contains cached information from a prior code 24 * The `DartCompletionCache` contains cached information from a prior code
24 * completion operation. 25 * completion operation.
25 */ 26 */
26 class DartCompletionCache extends CompletionCache { 27 class DartCompletionCache extends CompletionCache {
27 /** 28 /**
28 * A hash of the import directives 29 * A hash of the import directives
29 * or `null` if nothing has been cached. 30 * or `null` if nothing has been cached.
30 */ 31 */
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 * or `null` if nothing has been cached. 86 * or `null` if nothing has been cached.
86 */ 87 */
87 String get importKey => _importKey; 88 String get importKey => _importKey;
88 89
89 /** 90 /**
90 * Return the [ClassElement] for Object. 91 * Return the [ClassElement] for Object.
91 */ 92 */
92 ClassElement get objectClassElement { 93 ClassElement get objectClassElement {
93 if (_objectClassElement == null) { 94 if (_objectClassElement == null) {
94 Source coreUri = context.sourceFactory.forUri('dart:core'); 95 Source coreUri = context.sourceFactory.forUri('dart:core');
95 LibraryElement coreLib = context.getLibraryElement(coreUri); 96 LibraryElement coreLib = context.getResult(coreUri, LIBRARY_ELEMENT8);
96 _objectClassElement = coreLib.getType('Object'); 97 _objectClassElement = coreLib.getType('Object');
97 } 98 }
98 return _objectClassElement; 99 return _objectClassElement;
99 } 100 }
100 101
101 /** 102 /**
102 * Given a resolved compilation unit, compute suggestions based upon the 103 * Given a resolved compilation unit, compute suggestions based upon the
103 * imports and other dart files (e.g. "part" files) in the library containing 104 * imports and other dart files (e.g. "part" files) in the library containing
104 * the given compilation unit. The returned future completes when the cache 105 * the given compilation unit. The returned future completes when the cache
105 * is populated. 106 * is populated.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 193 }
193 } 194 }
194 } 195 }
195 } 196 }
196 197
197 /** 198 /**
198 * Add suggestions for implicitly imported elements in dart:core. 199 * Add suggestions for implicitly imported elements in dart:core.
199 */ 200 */
200 void _addDartCoreSuggestions() { 201 void _addDartCoreSuggestions() {
201 Source coreUri = context.sourceFactory.forUri('dart:core'); 202 Source coreUri = context.sourceFactory.forUri('dart:core');
202 LibraryElement coreLib = context.getLibraryElement(coreUri); 203 LibraryElement coreLib = context.getResult(coreUri, LIBRARY_ELEMENT8);
203 if (coreLib == null) { 204 if (coreLib == null) {
204 // If the core library has not been analyzed yet, then we cannot add any 205 // If the core library has not been analyzed yet, then we cannot add any
205 // suggestions from it. 206 // suggestions from it.
206 return; 207 return;
207 } 208 }
208 Namespace coreNamespace = 209 Namespace coreNamespace =
209 new NamespaceBuilder().createPublicNamespaceForLibrary(coreLib); 210 new NamespaceBuilder().createPublicNamespaceForLibrary(coreLib);
210 coreNamespace.definedNames.forEach((String name, Element elem) { 211 coreNamespace.definedNames.forEach((String name, Element elem) {
211 if (elem is ClassElement) { 212 if (elem is ClassElement) {
212 importedClassMap[name] = elem; 213 importedClassMap[name] = elem;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 * Add suggestions for all top level elements in the context 283 * Add suggestions for all top level elements in the context
283 * excluding those elemnents for which suggestions have already been added. 284 * excluding those elemnents for which suggestions have already been added.
284 */ 285 */
285 void _addNonImportedElementSuggestions( 286 void _addNonImportedElementSuggestions(
286 List<SearchMatch> matches, Set<LibraryElement> excludedLibs) { 287 List<SearchMatch> matches, Set<LibraryElement> excludedLibs) {
287 // Exclude internal Dart SDK libraries 288 // Exclude internal Dart SDK libraries
288 for (var lib in context.sourceFactory.dartSdk.sdkLibraries) { 289 for (var lib in context.sourceFactory.dartSdk.sdkLibraries) {
289 if (lib.isInternal) { 290 if (lib.isInternal) {
290 Source libUri = context.sourceFactory.forUri(lib.shortName); 291 Source libUri = context.sourceFactory.forUri(lib.shortName);
291 if (libUri != null) { 292 if (libUri != null) {
292 LibraryElement libElem = context.getLibraryElement(libUri); 293 LibraryElement libElem = context.getResult(libUri, LIBRARY_ELEMENT8);
293 if (libElem != null) { 294 if (libElem != null) {
294 excludedLibs.add(libElem); 295 excludedLibs.add(libElem);
295 } 296 }
296 } 297 }
297 } 298 }
298 } 299 }
299 300
300 AnalysisContext sdkContext = context.sourceFactory.dartSdk.context; 301 AnalysisContext sdkContext = context.sourceFactory.dartSdk.context;
301 matches.forEach((SearchMatch match) { 302 matches.forEach((SearchMatch match) {
302 if (match.kind == MatchKind.DECLARATION) { 303 if (match.kind == MatchKind.DECLARATION) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 @override 414 @override
414 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { 415 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) {
415 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); 416 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT);
416 } 417 }
417 418
418 @override 419 @override
419 void visitTopLevelVariableElement(TopLevelVariableElement element) { 420 void visitTopLevelVariableElement(TopLevelVariableElement element) {
420 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); 421 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT);
421 } 422 }
422 } 423 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698