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

Side by Side Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 1008433002: Task: Build Directive Elements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.task.dart; 5 library analyzer.src.task.dart;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
11 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; 11 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask;
12 import 'package:analyzer/src/generated/error.dart'; 12 import 'package:analyzer/src/generated/error.dart';
13 import 'package:analyzer/src/generated/java_engine.dart'; 13 import 'package:analyzer/src/generated/java_engine.dart';
14 import 'package:analyzer/src/generated/parser.dart'; 14 import 'package:analyzer/src/generated/parser.dart';
15 import 'package:analyzer/src/generated/resolver.dart'; 15 import 'package:analyzer/src/generated/resolver.dart';
16 import 'package:analyzer/src/generated/scanner.dart'; 16 import 'package:analyzer/src/generated/scanner.dart';
17 import 'package:analyzer/src/generated/sdk.dart'; 17 import 'package:analyzer/src/generated/sdk.dart';
18 import 'package:analyzer/src/generated/source.dart'; 18 import 'package:analyzer/src/generated/source.dart';
19 import 'package:analyzer/src/task/general.dart'; 19 import 'package:analyzer/src/task/general.dart';
20 import 'package:analyzer/src/task/inputs.dart'; 20 import 'package:analyzer/src/task/inputs.dart';
21 import 'package:analyzer/task/dart.dart'; 21 import 'package:analyzer/task/dart.dart';
22 import 'package:analyzer/task/general.dart'; 22 import 'package:analyzer/task/general.dart';
23 import 'package:analyzer/task/model.dart'; 23 import 'package:analyzer/task/model.dart';
24 24
25 /** 25 /**
26 * The errors produced while resolving a library directives.
27 *
28 * The list will be empty if there were no errors, but will not be `null`.
29 *
30 * The result is only available for targets representing a Dart library.
31 */
32 final ResultDescriptor<List<AnalysisError>> BUILD_DIRECTIVES_ERRORS =
33 new ResultDescriptor<List<AnalysisError>>(
34 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS,
35 contributesTo: ANALYSIS_ERRORS);
36
37 /**
38 * The errors produced while builing a library element.
39 *
40 * The list will be empty if there were no errors, but will not be `null`.
41 *
42 * The result is only available for targets representing a Dart library.
43 */
44 final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS =
45 new ResultDescriptor<List<AnalysisError>>(
46 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS,
47 contributesTo: ANALYSIS_ERRORS);
48
49 /**
50 * The partial [LibraryElement] associated with a library.
51 *
52 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each
53 * other. Directives 'library', 'part' and 'part of' are resolved.
54 *
55 * The result is only available for targets representing a Dart library.
56 */
57 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 =
58 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null);
59
60 /**
61 * The partially resolved [CompilationUnit] associated with a unit.
62 *
63 * All declarations bound to the element defined by the declaration.
64 *
65 * The result is only available for targets representing a unit.
66 */
67 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT1 =
68 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT1', null);
69
70 /**
71 * The partially resolved [CompilationUnit] associated with a unit.
72 *
73 * Directives 'library', 'part' and 'part of' are resolved.
74 *
75 * The result is only available for targets representing a library.
76 */
77 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT2 =
78 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT2', null);
79
80 /**
81 * The partially resolved [CompilationUnit] associated with a library.
82 *
83 * All the directives are resolved.
84 *
85 * The result is only available for targets representing a library.
86 */
87 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT3 =
88 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT3', null);
89
90 String _input(ResultDescriptor result, [String suffix]) {
Brian Wilkerson 2015/03/12 17:56:26 If this function stays, it needs a comment. But I
scheglov 2015/03/12 18:27:00 Removed.
91 if (suffix == null) {
92 return result.name;
93 }
94 return '${result.name} $suffix';
95 }
96
97 /**
26 * A task that builds a compilation unit element for a single compilation unit. 98 * A task that builds a compilation unit element for a single compilation unit.
27 */ 99 */
28 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask { 100 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask {
29 /** 101 /**
30 * The name of the input whose value is the line information for the 102 * The name of the input whose value is the line information for the
31 * compilation unit. 103 * compilation unit.
32 */ 104 */
33 static const String LINE_INFO_INPUT_NAME = "lineInfo"; 105 static final String LINE_INFO_INPUT_NAME = _input(LINE_INFO);
34 106
35 /** 107 /**
36 * The name of the input whose value is the AST for the compilation unit. 108 * The name of the input whose value is the AST for the compilation unit.
37 */ 109 */
38 static const String PARSED_UNIT_INPUT_NAME = "parsedUnit"; 110 static final String PARSED_UNIT_INPUT_NAME = _input(PARSED_UNIT);
39 111
40 /** 112 /**
41 * The task descriptor describing this kind of task. 113 * The task descriptor describing this kind of task.
42 */ 114 */
43 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 115 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
44 'BUILD_COMPILATION_UNIT_ELEMENT', createTask, buildInputs, 116 'BUILD_COMPILATION_UNIT_ELEMENT', createTask, buildInputs,
45 <ResultDescriptor>[COMPILATION_UNIT_ELEMENT, BUILT_UNIT]); 117 <ResultDescriptor>[COMPILATION_UNIT_ELEMENT, RESOLVED_UNIT1]);
46 118
47 /** 119 /**
48 * Initialize a newly created task to build a compilation unit element for 120 * Initialize a newly created task to build a compilation unit element for
49 * the given [target] in the given [context]. 121 * the given [target] in the given [context].
50 */ 122 */
51 BuildCompilationUnitElementTask( 123 BuildCompilationUnitElementTask(
52 InternalAnalysisContext context, AnalysisTarget target) 124 InternalAnalysisContext context, AnalysisTarget target)
53 : super(context, target); 125 : super(context, target);
54 126
55 @override 127 @override
56 TaskDescriptor get descriptor => DESCRIPTOR; 128 TaskDescriptor get descriptor => DESCRIPTOR;
57 129
58 @override 130 @override
59 void internalPerform() { 131 void internalPerform() {
60 Source source = getRequiredSource(); 132 Source source = getRequiredSource();
61 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME); 133 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME);
62 134
63 CompilationUnitBuilder builder = new CompilationUnitBuilder(); 135 CompilationUnitBuilder builder = new CompilationUnitBuilder();
64 CompilationUnitElement element = builder.buildCompilationUnit(source, unit); 136 CompilationUnitElement element = builder.buildCompilationUnit(source, unit);
65 137
66 outputs[COMPILATION_UNIT_ELEMENT] = element; 138 outputs[COMPILATION_UNIT_ELEMENT] = element;
67 outputs[BUILT_UNIT] = unit; 139 outputs[RESOLVED_UNIT1] = unit;
68 } 140 }
69 141
70 /** 142 /**
71 * Return a map from the names of the inputs of this kind of task to the task 143 * Return a map from the names of the inputs of this kind of task to the task
72 * input descriptors describing those inputs for a task with the given [target ]. 144 * input descriptors describing those inputs for a task with the given [target ].
73 */ 145 */
74 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 146 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
75 return <String, TaskInput>{ 147 return <String, TaskInput>{
76 PARSED_UNIT_INPUT_NAME: PARSED_UNIT.inputFor(target) 148 PARSED_UNIT_INPUT_NAME: PARSED_UNIT.inputFor(target)
77 }; 149 };
78 } 150 }
79 151
80 /** 152 /**
81 * Create a [BuildCompilationUnitElementTask] based on the given [target] in 153 * Create a [BuildCompilationUnitElementTask] based on the given [target] in
82 * the given [context]. 154 * the given [context].
83 */ 155 */
84 static BuildCompilationUnitElementTask createTask( 156 static BuildCompilationUnitElementTask createTask(
85 AnalysisContext context, AnalysisTarget target) { 157 AnalysisContext context, AnalysisTarget target) {
86 return new BuildCompilationUnitElementTask(context, target); 158 return new BuildCompilationUnitElementTask(context, target);
87 } 159 }
88 } 160 }
89 161
90 /** 162 /**
163 * A task that builds [RESOLVED_UNIT3] for a library.
164 */
165 class BuildDirectiveElementsTask extends SourceBasedAnalysisTask {
166 /**
167 * The name of the input for [RESOLVED_UNIT2] of a library unit.
168 */
169 static final String RESOLVED_UNIT2_INPUT_NAME =
170 _input(RESOLVED_UNIT2, 'defining');
171
172 /**
173 * The input with a list of [LIBRARY_ELEMENT1]s of imported libraries.
174 */
175 static final String IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME =
176 _input(LIBRARY_ELEMENT1, 'imports');
177
178 /**
179 * The input with a list of [LIBRARY_ELEMENT1]s of exported libraries.
180 */
181 static final String EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME =
182 _input(LIBRARY_ELEMENT1, 'exports');
183
184 /**
185 * The input with a list of [SOURCE_KIND]s of imported libraries.
186 */
187 static final String IMPORTS_SOURCE_KIND_INPUT_NAME =
188 _input(SOURCE_KIND, 'imports');
189
190 /**
191 * The input with a list of [SOURCE_KIND]s of exported libraries.
192 */
193 static final String EXPORTS_SOURCE_KIND_INPUT_NAME =
194 _input(SOURCE_KIND, 'exports');
195
196 /**
197 * The task descriptor describing this kind of task.
198 */
199 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
200 'BUILD_RESOLVED_UNIT3', createTask, buildInputs, <ResultDescriptor>[
201 RESOLVED_UNIT3,
202 BUILD_DIRECTIVES_ERRORS
203 ]);
204
205 BuildDirectiveElementsTask(
206 InternalAnalysisContext context, AnalysisTarget target)
207 : super(context, target);
208
209 @override
210 TaskDescriptor get descriptor => DESCRIPTOR;
211
212 @override
213 void internalPerform() {
214 List<AnalysisError> errors = <AnalysisError>[];
215 //
216 // Prepare inputs.
217 //
218 CompilationUnit libraryUnit = getRequiredInput(RESOLVED_UNIT2_INPUT_NAME);
219 Map<Source, LibraryElement> importLibraryMap =
220 getRequiredInput(IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME);
221 Map<Source, LibraryElement> exportLibraryMap =
222 getRequiredInput(EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME);
223 Map<Source, SourceKind> importSourceKindMap =
224 getRequiredInput(IMPORTS_SOURCE_KIND_INPUT_NAME);
225 Map<Source, SourceKind> exportSourceKindMap =
226 getRequiredInput(EXPORTS_SOURCE_KIND_INPUT_NAME);
227 //
228 // Process inputs.
229 //
230 LibraryElementImpl libraryElement = libraryUnit.element.library;
231 Source librarySource = libraryElement.source;
232 //
233 // Resolve directives.
234 //
235 HashMap<String, PrefixElementImpl> nameToPrefixMap =
236 new HashMap<String, PrefixElementImpl>();
237 List<ImportElement> imports = <ImportElement>[];
238 List<ExportElement> exports = <ExportElement>[];
239 bool explicitlyImportsCore = false;
240 for (Directive directive in libraryUnit.directives) {
241 if (directive is ImportDirective) {
242 ImportDirective importDirective = directive;
243 String uriContent = importDirective.uriContent;
244 if (DartUriResolver.isDartExtUri(uriContent)) {
245 libraryElement.hasExtUri = true;
246 }
247 Source importedSource = importDirective.source;
248 if (importedSource != null && context.exists(importedSource)) {
249 // The imported source will be null if the URI in the import
250 // directive was invalid.
251 LibraryElement importedLibrary = importLibraryMap[importedSource];
252 if (importedLibrary != null) {
253 ImportElementImpl importElement =
254 new ImportElementImpl(directive.offset);
255 StringLiteral uriLiteral = importDirective.uri;
256 if (uriLiteral != null) {
257 importElement.uriOffset = uriLiteral.offset;
258 importElement.uriEnd = uriLiteral.end;
259 }
260 importElement.uri = uriContent;
261 importElement.deferred = importDirective.deferredKeyword != null;
262 importElement.combinators = _buildCombinators(importDirective);
263 importElement.importedLibrary = importedLibrary;
264 SimpleIdentifier prefixNode = directive.prefix;
265 if (prefixNode != null) {
266 importElement.prefixOffset = prefixNode.offset;
267 String prefixName = prefixNode.name;
268 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
269 if (prefix == null) {
270 prefix = new PrefixElementImpl.forNode(prefixNode);
271 nameToPrefixMap[prefixName] = prefix;
272 }
273 importElement.prefix = prefix;
274 prefixNode.staticElement = prefix;
275 }
276 directive.element = importElement;
277 imports.add(importElement);
278 if (importSourceKindMap[importedSource] != SourceKind.LIBRARY) {
279 ErrorCode errorCode = (importElement.isDeferred
280 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
281 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY);
282 errors.add(new AnalysisError.con2(importedSource,
283 uriLiteral.offset, uriLiteral.length,
284 errorCode, [uriLiteral.toSource()]));
285 }
286 }
287 }
288 } else if (directive is ExportDirective) {
289 ExportDirective exportDirective = directive;
290 Source exportedSource = exportDirective.source;
291 if (exportedSource != null && context.exists(exportedSource)) {
292 // The exported source will be null if the URI in the export
293 // directive was invalid.
294 LibraryElement exportedLibrary = exportLibraryMap[exportedSource];
295 if (exportedLibrary != null) {
296 ExportElementImpl exportElement =
297 new ExportElementImpl(directive.offset);
298 StringLiteral uriLiteral = exportDirective.uri;
299 if (uriLiteral != null) {
300 exportElement.uriOffset = uriLiteral.offset;
301 exportElement.uriEnd = uriLiteral.end;
302 }
303 exportElement.uri = exportDirective.uriContent;
304 exportElement.combinators = _buildCombinators(exportDirective);
305 exportElement.exportedLibrary = exportedLibrary;
306 directive.element = exportElement;
307 exports.add(exportElement);
308 if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) {
309 errors.add(new AnalysisError.con2(exportedSource,
310 uriLiteral.offset, uriLiteral.length,
311 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, [
312 uriLiteral.toSource()
313 ]));
314 }
315 }
316 }
317 }
318 }
319 //
320 // Ensure "dart:core" import.
321 //
322 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE);
323 if (!explicitlyImportsCore && coreLibrarySource != librarySource) {
324 ImportElementImpl importElement = new ImportElementImpl(-1);
325 importElement.importedLibrary = importLibraryMap[coreLibrarySource];
326 importElement.synthetic = true;
327 imports.add(importElement);
328 }
329 //
330 // Populate the library element.
331 //
332 libraryElement.imports = imports;
333 libraryElement.exports = exports;
334 // TODO(scheglov) move after EXPORT_NAMESPACE or just this task
335 // if (libraryElement.entryPoint == null) {
336 // Namespace namespace = new NamespaceBuilder()
337 // .createExportNamespaceForLibrary(libraryElement);
338 // Element element = namespace.get(FunctionElement.MAIN_FUNCTION_NAME);
339 // if (element is FunctionElement) {
340 // libraryElement.entryPoint = element;
341 // }
342 // }
343 //
344 // Record outputs.
345 //
346 outputs[RESOLVED_UNIT3] = libraryUnit;
347 outputs[BUILD_DIRECTIVES_ERRORS] = errors;
348 }
349
350 /**
351 * Return a map from the names of the inputs of this kind of task to the task
352 * input descriptors describing those inputs for a task with the
353 * given [target].
354 */
355 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
356 return <String, TaskInput>{
357 RESOLVED_UNIT2_INPUT_NAME: RESOLVED_UNIT2.inputFor(target),
358 IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME:
359 new MapBasedTaskInput<Source, LibraryElement>(
360 new SimpleTaskInput<List<Source>>(target, IMPORTED_LIBRARIES),
Brian Wilkerson 2015/03/12 17:56:26 Personally, I like IMPORTED_LIBRARIES.inputFor
scheglov 2015/03/12 18:27:00 Thank you. My inputs look much better now!
361 (Source includedSource) => new SimpleTaskInput<LibraryElement>(
362 includedSource, LIBRARY_ELEMENT1)),
363 EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME:
364 new MapBasedTaskInput<Source, LibraryElement>(
365 new SimpleTaskInput<List<Source>>(target, EXPORTED_LIBRARIES),
366 (Source includedSource) => new SimpleTaskInput<LibraryElement>(
367 includedSource, LIBRARY_ELEMENT1)),
368 IMPORTS_SOURCE_KIND_INPUT_NAME: new MapBasedTaskInput<Source, SourceKind>(
369 new SimpleTaskInput<List<Source>>(target, IMPORTED_LIBRARIES),
370 (Source includedSource) =>
371 new SimpleTaskInput<SourceKind>(includedSource, SOURCE_KIND)),
372 EXPORTS_SOURCE_KIND_INPUT_NAME: new MapBasedTaskInput<Source, SourceKind>(
373 new SimpleTaskInput<List<Source>>(target, EXPORTED_LIBRARIES),
374 (Source includedSource) =>
375 new SimpleTaskInput<SourceKind>(includedSource, SOURCE_KIND))
376 };
377 }
378
379 /**
380 * Create a [BuildDirectiveElementsTask] based on the given [target] in
381 * the given [context].
382 */
383 static BuildDirectiveElementsTask createTask(
384 AnalysisContext context, AnalysisTarget target) {
385 return new BuildDirectiveElementsTask(context, target);
386 }
387
388 /**
389 * Build the element model representing the combinators declared by
390 * the given [directive].
391 */
392 static List<NamespaceCombinator> _buildCombinators(
393 NamespaceDirective directive) {
394 List<NamespaceCombinator> combinators = <NamespaceCombinator>[];
395 for (Combinator combinator in directive.combinators) {
396 if (combinator is ShowCombinator) {
397 ShowElementCombinatorImpl show = new ShowElementCombinatorImpl();
398 show.offset = combinator.offset;
399 show.end = combinator.end;
400 show.shownNames = _getIdentifiers(combinator.shownNames);
401 combinators.add(show);
402 } else if (combinator is HideCombinator) {
403 HideElementCombinatorImpl hide = new HideElementCombinatorImpl();
404 hide.hiddenNames = _getIdentifiers(combinator.hiddenNames);
405 combinators.add(hide);
406 }
407 }
408 return combinators;
409 }
410
411 /**
412 * Return the lexical identifiers associated with the given [identifiers].
413 */
414 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) {
415 return identifiers.map((identifier) => identifier.name).toList();
416 }
417 }
418
419 /**
91 * A task that builds a library element for a Dart library. 420 * A task that builds a library element for a Dart library.
92 */ 421 */
93 class BuildLibraryElementTask extends SourceBasedAnalysisTask { 422 class BuildLibraryElementTask extends SourceBasedAnalysisTask {
94 /** 423 /**
95 * The name of the input whose value is the built compilation unit of the 424 * The name of the input whose value is the defining [RESOLVED_UNIT1].
96 * defining compilation unit of a library. 425 */
97 */ 426 static final String DEFINING_RESOLVER_UNIT1_INPUT_NAME =
98 static const String DEFINING_BUILT_UNIT_INPUT_NAME = 'definingBuiltUnit'; 427 _input(RESOLVED_UNIT1, 'defining');
99 428
100 /** 429 /**
101 * The name of the input whose value is a list of built compilation units 430 * The name of the input whose value is a list of built [RESOLVED_UNIT1]s
102 * of the parts sourced by a library. 431 * of the parts sourced by a library.
103 */ 432 */
104 static const String PART_BUILT_UNITS_INPUT_NAME = 'partBuiltUnits'; 433 static final String PARTS_RESOLVED_UNIT1_INPUT_NAME =
434 _input(RESOLVED_UNIT1, 'parts');
105 435
106 /** 436 /**
107 * The task descriptor describing this kind of task. 437 * The task descriptor describing this kind of task.
108 */ 438 */
109 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 439 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
110 'BUILD_LIBRARY_ELEMENT', createTask, buildInputs, <ResultDescriptor>[ 440 'BUILD_LIBRARY_ELEMENT', createTask, buildInputs, <ResultDescriptor>[
111 BUILD_LIBRARY_ERRORS, 441 BUILD_LIBRARY_ERRORS,
112 BUILT_LIBRARY_ELEMENT, 442 RESOLVED_UNIT2,
443 LIBRARY_ELEMENT1,
113 IS_LAUNCHABLE, 444 IS_LAUNCHABLE,
114 HAS_HTML_IMPORT 445 HAS_HTML_IMPORT
115 ]); 446 ]);
116 447
117 /** 448 /**
118 * Initialize a newly created task to build a library element for the given 449 * Initialize a newly created task to build a library element for the given
119 * [target] in the given [context]. 450 * [target] in the given [context].
120 */ 451 */
121 BuildLibraryElementTask( 452 BuildLibraryElementTask(
122 InternalAnalysisContext context, AnalysisTarget target) 453 InternalAnalysisContext context, AnalysisTarget target)
123 : super(context, target); 454 : super(context, target);
124 455
125 @override 456 @override
126 TaskDescriptor get descriptor => DESCRIPTOR; 457 TaskDescriptor get descriptor => DESCRIPTOR;
127 458
128 @override 459 @override
129 void internalPerform() { 460 void internalPerform() {
130 List<AnalysisError> errors = <AnalysisError>[]; 461 List<AnalysisError> errors = <AnalysisError>[];
131 // 462 //
132 // Prepare inputs. 463 // Prepare inputs.
133 // 464 //
134 Source librarySource = getRequiredSource(); 465 Source librarySource = getRequiredSource();
135 CompilationUnit definingCompilationUnit = 466 CompilationUnit definingCompilationUnit =
136 getRequiredInput(DEFINING_BUILT_UNIT_INPUT_NAME); 467 getRequiredInput(DEFINING_RESOLVER_UNIT1_INPUT_NAME);
137 List<CompilationUnit> partUnits = 468 List<CompilationUnit> partUnits =
138 getRequiredInput(PART_BUILT_UNITS_INPUT_NAME); 469 getRequiredInput(PARTS_RESOLVED_UNIT1_INPUT_NAME);
139 // 470 //
140 // Process inputs. 471 // Process inputs.
141 // 472 //
142 CompilationUnitElementImpl definingCompilationUnitElement = 473 CompilationUnitElementImpl definingCompilationUnitElement =
143 definingCompilationUnit.element; 474 definingCompilationUnit.element;
144 Map<Source, CompilationUnit> partUnitMap = 475 Map<Source, CompilationUnit> partUnitMap =
145 new HashMap<Source, CompilationUnit>(); 476 new HashMap<Source, CompilationUnit>();
146 for (CompilationUnit partUnit in partUnits) { 477 for (CompilationUnit partUnit in partUnits) {
147 Source partSource = partUnit.element.source; 478 Source partSource = partUnit.element.source;
148 partUnitMap[partSource] = partUnit; 479 partUnitMap[partSource] = partUnit;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 for (Directive directive in directivesToResolve) { 555 for (Directive directive in directivesToResolve) {
225 directive.element = libraryElement; 556 directive.element = libraryElement;
226 } 557 }
227 if (sourcedCompilationUnits.isNotEmpty) { 558 if (sourcedCompilationUnits.isNotEmpty) {
228 _patchTopLevelAccessors(libraryElement); 559 _patchTopLevelAccessors(libraryElement);
229 } 560 }
230 // 561 //
231 // Record outputs. 562 // Record outputs.
232 // 563 //
233 outputs[BUILD_LIBRARY_ERRORS] = errors; 564 outputs[BUILD_LIBRARY_ERRORS] = errors;
234 outputs[BUILT_LIBRARY_ELEMENT] = libraryElement; 565 outputs[RESOLVED_UNIT2] = definingCompilationUnit;
566 outputs[LIBRARY_ELEMENT1] = libraryElement;
235 outputs[IS_LAUNCHABLE] = entryPoint != null; 567 outputs[IS_LAUNCHABLE] = entryPoint != null;
236 outputs[HAS_HTML_IMPORT] = hasHtmlImport; 568 outputs[HAS_HTML_IMPORT] = hasHtmlImport;
237 } 569 }
238 570
239 /** 571 /**
240 * Add all of the non-synthetic [getters] and [setters] defined in the given 572 * Add all of the non-synthetic [getters] and [setters] defined in the given
241 * [unit] that have no corresponding accessor to one of the given collections. 573 * [unit] that have no corresponding accessor to one of the given collections.
242 */ 574 */
243 void _collectAccessors(Map<String, PropertyAccessorElement> getters, 575 void _collectAccessors(Map<String, PropertyAccessorElement> getters,
244 List<PropertyAccessorElement> setters, CompilationUnitElement unit) { 576 List<PropertyAccessorElement> setters, CompilationUnitElement unit) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 645 }
314 } 646 }
315 647
316 /** 648 /**
317 * Return a map from the names of the inputs of this kind of task to the task 649 * Return a map from the names of the inputs of this kind of task to the task
318 * input descriptors describing those inputs for a task with the given 650 * input descriptors describing those inputs for a task with the given
319 * [target]. 651 * [target].
320 */ 652 */
321 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 653 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
322 return <String, TaskInput>{ 654 return <String, TaskInput>{
323 DEFINING_BUILT_UNIT_INPUT_NAME: new SimpleTaskInput(target, BUILT_UNIT), 655 DEFINING_RESOLVER_UNIT1_INPUT_NAME:
324 PART_BUILT_UNITS_INPUT_NAME: 656 new SimpleTaskInput(target, RESOLVED_UNIT1),
657 PARTS_RESOLVED_UNIT1_INPUT_NAME:
325 new ListBasedTaskInput<Source, CompilationUnit>( 658 new ListBasedTaskInput<Source, CompilationUnit>(
326 new SimpleTaskInput<List<Source>>(target, INCLUDED_PARTS), 659 new SimpleTaskInput<List<Source>>(target, INCLUDED_PARTS),
327 (Source includedSource) => new SimpleTaskInput<CompilationUnit>( 660 (Source includedSource) => new SimpleTaskInput<CompilationUnit>(
328 includedSource, BUILT_UNIT)) 661 includedSource, RESOLVED_UNIT1))
329 }; 662 };
330 } 663 }
331 664
332 /** 665 /**
333 * Create a [BuildLibraryElementTask] based on the given [target] in the 666 * Create a [BuildLibraryElementTask] based on the given [target] in the
334 * given [context]. 667 * given [context].
335 */ 668 */
336 static BuildLibraryElementTask createTask( 669 static BuildLibraryElementTask createTask(
337 AnalysisContext context, AnalysisTarget target) { 670 AnalysisContext context, AnalysisTarget target) {
338 return new BuildLibraryElementTask(context, target); 671 return new BuildLibraryElementTask(context, target);
339 } 672 }
340 } 673 }
341 674
342 /** 675 /**
343 * A task that builds [PUBLIC_NAMESPACE] for a library. 676 * A task that builds [PUBLIC_NAMESPACE] for a library.
344 */ 677 */
345 class BuildPublicNamespaceTask extends SourceBasedAnalysisTask { 678 class BuildPublicNamespaceTask extends SourceBasedAnalysisTask {
346 /** 679 /**
347 * The name of the [BUILT_LIBRARY_ELEMENT] input. 680 * The name of the input for [LIBRARY_ELEMENT1] of a library.
348 */ 681 */
349 static const String BUILT_LIBRARY_ELEMENT_INPUT_NAME = "builtLibraryElement"; 682 static final String BUILT_LIBRARY_ELEMENT_INPUT_NAME =
683 _input(LIBRARY_ELEMENT1);
350 684
351 /** 685 /**
352 * The task descriptor describing this kind of task. 686 * The task descriptor describing this kind of task.
353 */ 687 */
354 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 688 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
355 'BUILD_PUBLIC_NAMESPACE', createTask, buildInputs, <ResultDescriptor>[ 689 'BUILD_PUBLIC_NAMESPACE', createTask, buildInputs, <ResultDescriptor>[
356 PUBLIC_NAMESPACE 690 PUBLIC_NAMESPACE
357 ]); 691 ]);
358 692
359 BuildPublicNamespaceTask( 693 BuildPublicNamespaceTask(
(...skipping 13 matching lines...) Expand all
373 outputs[PUBLIC_NAMESPACE] = namespace; 707 outputs[PUBLIC_NAMESPACE] = namespace;
374 } 708 }
375 709
376 /** 710 /**
377 * Return a map from the names of the inputs of this kind of task to the task 711 * Return a map from the names of the inputs of this kind of task to the task
378 * input descriptors describing those inputs for a task with the 712 * input descriptors describing those inputs for a task with the
379 * given [target]. 713 * given [target].
380 */ 714 */
381 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 715 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
382 return <String, TaskInput>{ 716 return <String, TaskInput>{
383 BUILT_LIBRARY_ELEMENT_INPUT_NAME: BUILT_LIBRARY_ELEMENT.inputFor(target) 717 BUILT_LIBRARY_ELEMENT_INPUT_NAME: LIBRARY_ELEMENT1.inputFor(target)
384 }; 718 };
385 } 719 }
386 720
387 /** 721 /**
388 * Create a [BuildPublicNamespaceTask] based on the given [target] in 722 * Create a [BuildPublicNamespaceTask] based on the given [target] in
389 * the given [context]. 723 * the given [context].
390 */ 724 */
391 static BuildPublicNamespaceTask createTask( 725 static BuildPublicNamespaceTask createTask(
392 AnalysisContext context, AnalysisTarget target) { 726 AnalysisContext context, AnalysisTarget target) {
393 return new BuildPublicNamespaceTask(context, target); 727 return new BuildPublicNamespaceTask(context, target);
394 } 728 }
395 } 729 }
396 730
397 /** 731 /**
398 * A task that parses the content of a Dart file, producing an AST structure. 732 * A task that parses the content of a Dart file, producing an AST structure.
399 */ 733 */
400 class ParseDartTask extends SourceBasedAnalysisTask { 734 class ParseDartTask extends SourceBasedAnalysisTask {
401 /** 735 /**
402 * The name of the input whose value is the line information produced for the 736 * The name of the input whose value is the line information produced for the
403 * file. 737 * file.
404 */ 738 */
405 static const String LINE_INFO_INPUT_NAME = "lineInfo"; 739 static final String LINE_INFO_INPUT_NAME = _input(LINE_INFO);
406 740
407 /** 741 /**
408 * The name of the input whose value is the token stream produced for the file . 742 * The name of the input whose value is the token stream produced for the file .
409 */ 743 */
410 static const String TOKEN_STREAM_INPUT_NAME = "tokenStream"; 744 static final String TOKEN_STREAM_INPUT_NAME = _input(TOKEN_STREAM);
411 745
412 /** 746 /**
413 * The task descriptor describing this kind of task. 747 * The task descriptor describing this kind of task.
414 */ 748 */
415 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('PARSE_DART', 749 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('PARSE_DART',
416 createTask, buildInputs, <ResultDescriptor>[ 750 createTask, buildInputs, <ResultDescriptor>[
417 EXPORTED_LIBRARIES, 751 EXPORTED_LIBRARIES,
418 IMPORTED_LIBRARIES, 752 IMPORTED_LIBRARIES,
419 INCLUDED_PARTS, 753 INCLUDED_PARTS,
420 PARSE_ERRORS, 754 PARSE_ERRORS,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 includedSources.add(referencedSource); 802 includedSources.add(referencedSource);
469 } 803 }
470 } else { 804 } else {
471 throw new AnalysisException( 805 throw new AnalysisException(
472 "$runtimeType failed to handle a ${directive.runtimeType}"); 806 "$runtimeType failed to handle a ${directive.runtimeType}");
473 } 807 }
474 } 808 }
475 } 809 }
476 } 810 }
477 } 811 }
812 //
813 // Always include "dart:core" source.
814 //
815 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE);
816 importedSources.add(coreLibrarySource);
817 //
818 // Compute kind.
819 //
478 SourceKind sourceKind = SourceKind.LIBRARY; 820 SourceKind sourceKind = SourceKind.LIBRARY;
479 if (!hasNonPartOfDirective && hasPartOfDirective) { 821 if (!hasNonPartOfDirective && hasPartOfDirective) {
480 sourceKind = SourceKind.PART; 822 sourceKind = SourceKind.PART;
481 } 823 }
482 824 //
825 // Record outputs.
826 //
483 outputs[EXPORTED_LIBRARIES] = exportedSources.toList(); 827 outputs[EXPORTED_LIBRARIES] = exportedSources.toList();
484 outputs[IMPORTED_LIBRARIES] = importedSources.toList(); 828 outputs[IMPORTED_LIBRARIES] = importedSources.toList();
485 outputs[INCLUDED_PARTS] = includedSources.toList(); 829 outputs[INCLUDED_PARTS] = includedSources.toList();
486 outputs[PARSE_ERRORS] = errorListener.getErrorsForSource(source); 830 outputs[PARSE_ERRORS] = errorListener.getErrorsForSource(source);
487 outputs[PARSED_UNIT] = unit; 831 outputs[PARSED_UNIT] = unit;
488 outputs[SOURCE_KIND] = sourceKind; 832 outputs[SOURCE_KIND] = sourceKind;
489 } 833 }
490 834
491 /** 835 /**
492 * Return a map from the names of the inputs of this kind of task to the task 836 * Return a map from the names of the inputs of this kind of task to the task
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 } 894 }
551 } 895 }
552 896
553 /** 897 /**
554 * A task that scans the content of a file, producing a set of Dart tokens. 898 * A task that scans the content of a file, producing a set of Dart tokens.
555 */ 899 */
556 class ScanDartTask extends SourceBasedAnalysisTask { 900 class ScanDartTask extends SourceBasedAnalysisTask {
557 /** 901 /**
558 * The name of the input whose value is the content of the file. 902 * The name of the input whose value is the content of the file.
559 */ 903 */
560 static const String CONTENT_INPUT_NAME = "content"; 904 static final String CONTENT_INPUT_NAME = _input(CONTENT);
561 905
562 /** 906 /**
563 * The task descriptor describing this kind of task. 907 * The task descriptor describing this kind of task.
564 */ 908 */
565 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('SCAN_DART', 909 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('SCAN_DART',
566 createTask, buildInputs, <ResultDescriptor>[ 910 createTask, buildInputs, <ResultDescriptor>[
567 LINE_INFO, 911 LINE_INFO,
568 SCAN_ERRORS, 912 SCAN_ERRORS,
569 TOKEN_STREAM 913 TOKEN_STREAM
570 ]); 914 ]);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 } 946 }
603 947
604 /** 948 /**
605 * Create a [ScanDartTask] based on the given [target] in the given [context]. 949 * Create a [ScanDartTask] based on the given [target] in the given [context].
606 */ 950 */
607 static ScanDartTask createTask( 951 static ScanDartTask createTask(
608 AnalysisContext context, AnalysisTarget target) { 952 AnalysisContext context, AnalysisTarget target) {
609 return new ScanDartTask(context, target); 953 return new ScanDartTask(context, target);
610 } 954 }
611 } 955 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/testing/element_factory.dart ('k') | pkg/analyzer/lib/task/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698