| OLD | NEW |
| 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'; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 * The list will be empty if there were no errors, but will not be `null`. | 54 * The list will be empty if there were no errors, but will not be `null`. |
| 55 * | 55 * |
| 56 * The result is only available for targets representing a Dart library. | 56 * The result is only available for targets representing a Dart library. |
| 57 */ | 57 */ |
| 58 final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS = | 58 final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS = |
| 59 new ResultDescriptor<List<AnalysisError>>( | 59 new ResultDescriptor<List<AnalysisError>>( |
| 60 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS, | 60 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS, |
| 61 contributesTo: DART_ERRORS); | 61 contributesTo: DART_ERRORS); |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * The [ClassElement]s of a [LibraryUnitTarget]. |
| 65 */ |
| 66 final ResultDescriptor<List<ClassElement>> CLASS_ELEMENTS = |
| 67 new ResultDescriptor<List<ClassElement>>('CLASS_ELEMENTS', null); |
| 68 |
| 69 /** |
| 64 * The sources representing the export closure of a library. | 70 * The sources representing the export closure of a library. |
| 65 * | 71 * |
| 66 * The result is only available for targets representing a Dart library. | 72 * The result is only available for targets representing a Dart library. |
| 67 */ | 73 */ |
| 68 final ResultDescriptor<List<Source>> EXPORT_SOURCE_CLOSURE = | 74 final ResultDescriptor<List<Source>> EXPORT_SOURCE_CLOSURE = |
| 69 new ResultDescriptor<List<Source>>('EXPORT_SOURCE_CLOSURE', null); | 75 new ResultDescriptor<List<Source>>('EXPORT_SOURCE_CLOSURE', null); |
| 70 | 76 |
| 71 /** | 77 /** |
| 72 * The partial [LibraryElement] associated with a library. | 78 * The partial [LibraryElement] associated with a library. |
| 73 * | 79 * |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 /** | 201 /** |
| 196 * The name of the input whose value is the AST for the compilation unit. | 202 * The name of the input whose value is the AST for the compilation unit. |
| 197 */ | 203 */ |
| 198 static const String PARSED_UNIT_INPUT_NAME = 'PARSED_UNIT_INPUT_NAME'; | 204 static const String PARSED_UNIT_INPUT_NAME = 'PARSED_UNIT_INPUT_NAME'; |
| 199 | 205 |
| 200 /** | 206 /** |
| 201 * The task descriptor describing this kind of task. | 207 * The task descriptor describing this kind of task. |
| 202 */ | 208 */ |
| 203 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 209 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 204 'BuildCompilationUnitElementTask', createTask, buildInputs, | 210 'BuildCompilationUnitElementTask', createTask, buildInputs, |
| 205 <ResultDescriptor>[COMPILATION_UNIT_ELEMENT, RESOLVED_UNIT1]); | 211 <ResultDescriptor>[ |
| 212 CLASS_ELEMENTS, |
| 213 COMPILATION_UNIT_ELEMENT, |
| 214 RESOLVED_UNIT1 |
| 215 ]); |
| 206 | 216 |
| 207 /** | 217 /** |
| 208 * Initialize a newly created task to build a compilation unit element for | 218 * Initialize a newly created task to build a compilation unit element for |
| 209 * the given [target] in the given [context]. | 219 * the given [target] in the given [context]. |
| 210 */ | 220 */ |
| 211 BuildCompilationUnitElementTask( | 221 BuildCompilationUnitElementTask( |
| 212 InternalAnalysisContext context, AnalysisTarget target) | 222 InternalAnalysisContext context, AnalysisTarget target) |
| 213 : super(context, target); | 223 : super(context, target); |
| 214 | 224 |
| 215 @override | 225 @override |
| 216 TaskDescriptor get descriptor => DESCRIPTOR; | 226 TaskDescriptor get descriptor => DESCRIPTOR; |
| 217 | 227 |
| 218 @override | 228 @override |
| 219 void internalPerform() { | 229 void internalPerform() { |
| 220 // | 230 // |
| 221 // Prepare inputs. | 231 // Prepare inputs. |
| 222 // | 232 // |
| 223 Source source = getRequiredSource(); | 233 Source source = getRequiredSource(); |
| 224 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME); | 234 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME); |
| 225 // | 235 // |
| 226 // Process inputs. | 236 // Process inputs. |
| 227 // | 237 // |
| 228 unit = AstCloner.clone(unit); | 238 unit = AstCloner.clone(unit); |
| 229 CompilationUnitBuilder builder = new CompilationUnitBuilder(); | 239 CompilationUnitBuilder builder = new CompilationUnitBuilder(); |
| 230 CompilationUnitElement element = builder.buildCompilationUnit(source, unit); | 240 CompilationUnitElement element = builder.buildCompilationUnit(source, unit); |
| 231 // | 241 // |
| 232 // Record outputs. | 242 // Record outputs. |
| 233 // | 243 // |
| 244 outputs[CLASS_ELEMENTS] = element.types; |
| 234 outputs[COMPILATION_UNIT_ELEMENT] = element; | 245 outputs[COMPILATION_UNIT_ELEMENT] = element; |
| 235 outputs[RESOLVED_UNIT1] = unit; | 246 outputs[RESOLVED_UNIT1] = unit; |
| 236 } | 247 } |
| 237 | 248 |
| 238 /** | 249 /** |
| 239 * Return a map from the names of the inputs of this kind of task to the task | 250 * Return a map from the names of the inputs of this kind of task to the task |
| 240 * input descriptors describing those inputs for a task with the given | 251 * input descriptors describing those inputs for a task with the given |
| 241 * [target]. | 252 * [target]. |
| 242 */ | 253 */ |
| 243 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { | 254 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { |
| (...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 /** | 1333 /** |
| 1323 * The task descriptor describing this kind of task. | 1334 * The task descriptor describing this kind of task. |
| 1324 */ | 1335 */ |
| 1325 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('ParseDartTask', | 1336 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('ParseDartTask', |
| 1326 createTask, buildInputs, <ResultDescriptor>[ | 1337 createTask, buildInputs, <ResultDescriptor>[ |
| 1327 EXPORTED_LIBRARIES, | 1338 EXPORTED_LIBRARIES, |
| 1328 IMPORTED_LIBRARIES, | 1339 IMPORTED_LIBRARIES, |
| 1329 INCLUDED_PARTS, | 1340 INCLUDED_PARTS, |
| 1330 PARSE_ERRORS, | 1341 PARSE_ERRORS, |
| 1331 PARSED_UNIT, | 1342 PARSED_UNIT, |
| 1332 SOURCE_KIND | 1343 SOURCE_KIND, |
| 1344 UNITS |
| 1333 ]); | 1345 ]); |
| 1334 | 1346 |
| 1335 /** | 1347 /** |
| 1336 * Initialize a newly created task to parse the content of the Dart file | 1348 * Initialize a newly created task to parse the content of the Dart file |
| 1337 * associated with the given [target] in the given [context]. | 1349 * associated with the given [target] in the given [context]. |
| 1338 */ | 1350 */ |
| 1339 ParseDartTask(InternalAnalysisContext context, AnalysisTarget target) | 1351 ParseDartTask(InternalAnalysisContext context, AnalysisTarget target) |
| 1340 : super(context, target); | 1352 : super(context, target); |
| 1341 | 1353 |
| 1342 @override | 1354 @override |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1399 } | 1411 } |
| 1400 // | 1412 // |
| 1401 // Record outputs. | 1413 // Record outputs. |
| 1402 // | 1414 // |
| 1403 outputs[EXPORTED_LIBRARIES] = exportedSources.toList(); | 1415 outputs[EXPORTED_LIBRARIES] = exportedSources.toList(); |
| 1404 outputs[IMPORTED_LIBRARIES] = importedSources.toList(); | 1416 outputs[IMPORTED_LIBRARIES] = importedSources.toList(); |
| 1405 outputs[INCLUDED_PARTS] = includedSources.toList(); | 1417 outputs[INCLUDED_PARTS] = includedSources.toList(); |
| 1406 outputs[PARSE_ERRORS] = errorListener.getErrorsForSource(source); | 1418 outputs[PARSE_ERRORS] = errorListener.getErrorsForSource(source); |
| 1407 outputs[PARSED_UNIT] = unit; | 1419 outputs[PARSED_UNIT] = unit; |
| 1408 outputs[SOURCE_KIND] = sourceKind; | 1420 outputs[SOURCE_KIND] = sourceKind; |
| 1421 outputs[UNITS] = <Source>[source]..addAll(includedSources); |
| 1409 } | 1422 } |
| 1410 | 1423 |
| 1411 /** | 1424 /** |
| 1412 * Return a map from the names of the inputs of this kind of task to the task | 1425 * Return a map from the names of the inputs of this kind of task to the task |
| 1413 * input descriptors describing those inputs for a task with the given | 1426 * input descriptors describing those inputs for a task with the given |
| 1414 * [source]. | 1427 * [source]. |
| 1415 */ | 1428 */ |
| 1416 static Map<String, TaskInput> buildInputs(Source source) { | 1429 static Map<String, TaskInput> buildInputs(Source source) { |
| 1417 return <String, TaskInput>{ | 1430 return <String, TaskInput>{ |
| 1418 LINE_INFO_INPUT_NAME: LINE_INFO.inputFor(source), | 1431 LINE_INFO_INPUT_NAME: LINE_INFO.inputFor(source), |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 } | 1554 } |
| 1542 | 1555 |
| 1543 /** | 1556 /** |
| 1544 * Return a map from the names of the inputs of this kind of task to the task | 1557 * Return a map from the names of the inputs of this kind of task to the task |
| 1545 * input descriptors describing those inputs for a task with the | 1558 * input descriptors describing those inputs for a task with the |
| 1546 * given [target]. | 1559 * given [target]. |
| 1547 */ | 1560 */ |
| 1548 static Map<String, TaskInput> buildInputs(Source libSource) { | 1561 static Map<String, TaskInput> buildInputs(Source libSource) { |
| 1549 return <String, TaskInput>{ | 1562 return <String, TaskInput>{ |
| 1550 LIBRARY_INPUT: LIBRARY_ELEMENT4.inputFor(libSource), | 1563 LIBRARY_INPUT: LIBRARY_ELEMENT4.inputFor(libSource), |
| 1551 'resolvedDefiningUnit': | 1564 'resolvedUnits': new ListToMapTaskInput<Source, CompilationUnit>( |
| 1552 RESOLVED_UNIT4.inputFor(new LibraryUnitTarget(libSource, libSource)), | 1565 UNITS.inputFor(libSource), (Source source) => |
| 1553 'resolvedPartsUnit': new ListToMapTaskInput<Source, CompilationUnit>( | 1566 RESOLVED_UNIT4.inputFor(new LibraryUnitTarget(libSource, source))) |
| 1554 INCLUDED_PARTS.inputFor(libSource), (Source source) => RESOLVED_UNIT4 | |
| 1555 .inputFor(new LibraryUnitTarget(libSource, source))), | |
| 1556 }; | 1567 }; |
| 1557 } | 1568 } |
| 1558 | 1569 |
| 1559 /** | 1570 /** |
| 1560 * Create a [ResolveLibraryTypeNamesTask] based on the given [target] in | 1571 * Create a [ResolveLibraryTypeNamesTask] based on the given [target] in |
| 1561 * the given [context]. | 1572 * the given [context]. |
| 1562 */ | 1573 */ |
| 1563 static ResolveLibraryTypeNamesTask createTask( | 1574 static ResolveLibraryTypeNamesTask createTask( |
| 1564 AnalysisContext context, AnalysisTarget target) { | 1575 AnalysisContext context, AnalysisTarget target) { |
| 1565 return new ResolveLibraryTypeNamesTask(context, target); | 1576 return new ResolveLibraryTypeNamesTask(context, target); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1685 } | 1696 } |
| 1686 | 1697 |
| 1687 /** | 1698 /** |
| 1688 * Create a [ScanDartTask] based on the given [target] in the given [context]. | 1699 * Create a [ScanDartTask] based on the given [target] in the given [context]. |
| 1689 */ | 1700 */ |
| 1690 static ScanDartTask createTask( | 1701 static ScanDartTask createTask( |
| 1691 AnalysisContext context, AnalysisTarget target) { | 1702 AnalysisContext context, AnalysisTarget target) { |
| 1692 return new ScanDartTask(context, target); | 1703 return new ScanDartTask(context, target); |
| 1693 } | 1704 } |
| 1694 } | 1705 } |
| OLD | NEW |