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

Side by Side Diff: pkg/analyzer/lib/src/context/builder.dart

Issue 2380573006: ContextBuilder can configure contexts to use summaries (Closed)
Patch Set: Created 4 years, 2 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 | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | no next file » | 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) 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 library analyzer.src.context.context_builder; 5 library analyzer.src.context.context_builder;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:core'; 8 import 'dart:core';
9 9
10 import 'package:analyzer/context/declared_variables.dart'; 10 import 'package:analyzer/context/declared_variables.dart';
11 import 'package:analyzer/file_system/file_system.dart'; 11 import 'package:analyzer/file_system/file_system.dart';
12 import 'package:analyzer/plugin/options.dart'; 12 import 'package:analyzer/plugin/options.dart';
13 import 'package:analyzer/plugin/resolver_provider.dart'; 13 import 'package:analyzer/plugin/resolver_provider.dart';
14 import 'package:analyzer/source/analysis_options_provider.dart'; 14 import 'package:analyzer/source/analysis_options_provider.dart';
15 import 'package:analyzer/source/package_map_resolver.dart'; 15 import 'package:analyzer/source/package_map_resolver.dart';
16 import 'package:analyzer/src/dart/sdk/sdk.dart'; 16 import 'package:analyzer/src/dart/sdk/sdk.dart';
17 import 'package:analyzer/src/generated/engine.dart'; 17 import 'package:analyzer/src/generated/engine.dart';
18 import 'package:analyzer/src/generated/sdk.dart'; 18 import 'package:analyzer/src/generated/sdk.dart';
19 import 'package:analyzer/src/generated/source.dart'; 19 import 'package:analyzer/src/generated/source.dart';
20 import 'package:analyzer/src/summary/package_bundle_reader.dart';
21 import 'package:analyzer/src/summary/pub_summary.dart';
20 import 'package:analyzer/src/task/options.dart'; 22 import 'package:analyzer/src/task/options.dart';
21 import 'package:package_config/packages.dart'; 23 import 'package:package_config/packages.dart';
22 import 'package:package_config/packages_file.dart'; 24 import 'package:package_config/packages_file.dart';
23 import 'package:package_config/src/packages_impl.dart'; 25 import 'package:package_config/src/packages_impl.dart';
24 import 'package:path/src/context.dart'; 26 import 'package:path/src/context.dart';
25 import 'package:yaml/yaml.dart'; 27 import 'package:yaml/yaml.dart';
26 28
27 /** 29 /**
28 * A utility class used to build an analysis context for a given directory. 30 * A utility class used to build an analysis context for a given directory.
29 * 31 *
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 */ 106 */
105 AnalysisOptions defaultOptions; 107 AnalysisOptions defaultOptions;
106 108
107 /** 109 /**
108 * A table mapping variable names to values for the declared variables, or 110 * A table mapping variable names to values for the declared variables, or
109 * `null` if no additional variables should be declared. 111 * `null` if no additional variables should be declared.
110 */ 112 */
111 Map<String, String> declaredVariables; 113 Map<String, String> declaredVariables;
112 114
113 /** 115 /**
116 * The manager of pub package summaries.
117 */
118 PubSummaryManager pubSummaryManager;
119
120 /**
114 * Initialize a newly created builder to be ready to build a context rooted in 121 * Initialize a newly created builder to be ready to build a context rooted in
115 * the directory with the given [rootDirectoryPath]. 122 * the directory with the given [rootDirectoryPath].
116 */ 123 */
117 ContextBuilder(this.resourceProvider, this.sdkManager, this.contentCache); 124 ContextBuilder(this.resourceProvider, this.sdkManager, this.contentCache);
118 125
119 /** 126 /**
120 * Return an analysis context that is configured correctly to analyze code in 127 * Return an analysis context that is configured correctly to analyze code in
121 * the directory with the given [path]. 128 * the directory with the given [path].
122 * 129 *
123 * *Note:* This method is not yet fully implemented and should not be used. 130 * *Note:* This method is not yet fully implemented and should not be used.
124 */ 131 */
125 AnalysisContext buildContext(String path) { 132 AnalysisContext buildContext(String path) {
126 InternalAnalysisContext context = 133 InternalAnalysisContext context =
127 AnalysisEngine.instance.createAnalysisContext(); 134 AnalysisEngine.instance.createAnalysisContext();
128 AnalysisOptions options = getAnalysisOptions(context, path); 135 AnalysisOptions options = getAnalysisOptions(context, path);
129 context.contentCache = contentCache; 136 context.contentCache = contentCache;
130 context.sourceFactory = createSourceFactory(path, options); 137 context.sourceFactory = createSourceFactory(path, options);
131 context.analysisOptions = options; 138 context.analysisOptions = options;
132 context.name = path; 139 context.name = path;
133 //_processAnalysisOptions(context, optionMap); 140 //_processAnalysisOptions(context, optionMap);
134 declareVariables(context); 141 declareVariables(context);
142 configureSummaries(context);
135 return context; 143 return context;
136 } 144 }
137 145
146 /**
147 * Configure the context to make use of summaries.
148 */
149 void configureSummaries(InternalAnalysisContext context) {
150 if (pubSummaryManager != null) {
151 List<LinkedPubPackage> linkedBundles =
152 pubSummaryManager.getLinkedBundles(context);
153 if (linkedBundles.isNotEmpty) {
154 SummaryDataStore store = new SummaryDataStore([]);
155 for (LinkedPubPackage package in linkedBundles) {
156 store.addBundle(null, package.unlinked);
157 store.addBundle(null, package.linked);
158 }
159 context.resultProvider =
160 new InputPackagesResultProvider(context, store);
161 }
162 }
163 }
164
138 Map<String, List<Folder>> convertPackagesToMap(Packages packages) { 165 Map<String, List<Folder>> convertPackagesToMap(Packages packages) {
139 Map<String, List<Folder>> folderMap = new HashMap<String, List<Folder>>(); 166 Map<String, List<Folder>> folderMap = new HashMap<String, List<Folder>>();
140 if (packages != null && packages != Packages.noPackages) { 167 if (packages != null && packages != Packages.noPackages) {
141 packages.asMap().forEach((String packageName, Uri uri) { 168 packages.asMap().forEach((String packageName, Uri uri) {
142 String path = resourceProvider.pathContext.fromUri(uri); 169 String path = resourceProvider.pathContext.fromUri(uri);
143 folderMap[packageName] = [resourceProvider.getFolder(path)]; 170 folderMap[packageName] = [resourceProvider.getFolder(path)];
144 }); 171 });
145 } 172 }
146 return folderMap; 173 return folderMap;
147 } 174 }
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 String _readEmbedderYaml(Folder libDir) { 591 String _readEmbedderYaml(Folder libDir) {
565 File file = libDir.getChild(EMBEDDER_FILE_NAME); 592 File file = libDir.getChild(EMBEDDER_FILE_NAME);
566 try { 593 try {
567 return file.readAsStringSync(); 594 return file.readAsStringSync();
568 } on FileSystemException { 595 } on FileSystemException {
569 // File can't be read. 596 // File can't be read.
570 return null; 597 return null;
571 } 598 }
572 } 599 }
573 } 600 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698