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

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

Issue 2229603003: Extract unresolved AST parsing (PARSED_UNIT1) from full parsing, which includes UriBasedDirective(s… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update task graph. Created 4 years, 4 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
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/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT9', false); 327 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT9', false);
328 328
329 /** 329 /**
330 * All [AnalysisError]s results for [Source]s. 330 * All [AnalysisError]s results for [Source]s.
331 */ 331 */
332 final List<ListResultDescriptor<AnalysisError>> ERROR_SOURCE_RESULTS = 332 final List<ListResultDescriptor<AnalysisError>> ERROR_SOURCE_RESULTS =
333 <ListResultDescriptor<AnalysisError>>[ 333 <ListResultDescriptor<AnalysisError>>[
334 BUILD_DIRECTIVES_ERRORS, 334 BUILD_DIRECTIVES_ERRORS,
335 BUILD_LIBRARY_ERRORS, 335 BUILD_LIBRARY_ERRORS,
336 PARSE_ERRORS, 336 PARSE_ERRORS,
337 RESOLVE_DIRECTIVES_ERRORS,
337 SCAN_ERRORS, 338 SCAN_ERRORS,
338 ]; 339 ];
339 340
340 /** 341 /**
341 * All [AnalysisError]s results in for [LibrarySpecificUnit]s. 342 * All [AnalysisError]s results in for [LibrarySpecificUnit]s.
342 */ 343 */
343 final List<ListResultDescriptor<AnalysisError>> ERROR_UNIT_RESULTS = 344 final List<ListResultDescriptor<AnalysisError>> ERROR_UNIT_RESULTS =
344 <ListResultDescriptor<AnalysisError>>[ 345 <ListResultDescriptor<AnalysisError>>[
345 HINTS, 346 HINTS,
346 LIBRARY_UNIT_ERRORS, 347 LIBRARY_UNIT_ERRORS,
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 * 620 *
620 * The list will be empty if there were no errors, but will not be `null`. 621 * The list will be empty if there were no errors, but will not be `null`.
621 * 622 *
622 * The result is only available for [Source]s representing a compilation unit. 623 * The result is only available for [Source]s representing a compilation unit.
623 */ 624 */
624 final ListResultDescriptor<AnalysisError> PARSE_ERRORS = 625 final ListResultDescriptor<AnalysisError> PARSE_ERRORS =
625 new ListResultDescriptor<AnalysisError>( 626 new ListResultDescriptor<AnalysisError>(
626 'PARSE_ERRORS', AnalysisError.NO_ERRORS); 627 'PARSE_ERRORS', AnalysisError.NO_ERRORS);
627 628
628 /** 629 /**
630 * The compilation unit AST produced while parsing a compilation unit.
631 *
632 * The AST structure will not have resolution information associated with it.
633 *
634 * The result is only available for [Source]s representing a compilation unit.
635 */
636 final ResultDescriptor<CompilationUnit> PARSED_UNIT1 =
637 new ResultDescriptor<CompilationUnit>('PARSED_UNIT1', null,
638 cachingPolicy: AST_CACHING_POLICY);
639
640 /**
629 * The list of [PendingError]s for a compilation unit. 641 * The list of [PendingError]s for a compilation unit.
630 * 642 *
631 * The result is only available for [LibrarySpecificUnit]s. 643 * The result is only available for [LibrarySpecificUnit]s.
632 */ 644 */
633 final ListResultDescriptor<PendingError> PENDING_ERRORS = 645 final ListResultDescriptor<PendingError> PENDING_ERRORS =
634 new ListResultDescriptor<PendingError>( 646 new ListResultDescriptor<PendingError>(
635 'PENDING_ERRORS', const <PendingError>[]); 647 'PENDING_ERRORS', const <PendingError>[]);
636 648
637 /** 649 /**
638 * A list of the [VariableElement]s whose type should be known to propagate 650 * A list of the [VariableElement]s whose type should be known to propagate
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 /** 734 /**
723 * The list of [ConstantEvaluationTarget]s on which error verification depends. 735 * The list of [ConstantEvaluationTarget]s on which error verification depends.
724 * 736 *
725 * The result is only available for [LibrarySpecificUnit]s. 737 * The result is only available for [LibrarySpecificUnit]s.
726 */ 738 */
727 final ListResultDescriptor<ConstantEvaluationTarget> REQUIRED_CONSTANTS = 739 final ListResultDescriptor<ConstantEvaluationTarget> REQUIRED_CONSTANTS =
728 new ListResultDescriptor<ConstantEvaluationTarget>( 740 new ListResultDescriptor<ConstantEvaluationTarget>(
729 'REQUIRED_CONSTANTS', const <ConstantEvaluationTarget>[]); 741 'REQUIRED_CONSTANTS', const <ConstantEvaluationTarget>[]);
730 742
731 /** 743 /**
744 * The errors produced while resolving [UriBasedDirective]s in a unit.
745 *
746 * The list will be empty if there were no errors, but will not be `null`.
747 *
748 * The result is only available for [Source]s representing a compilation unit.
749 */
750 final ListResultDescriptor<AnalysisError> RESOLVE_DIRECTIVES_ERRORS =
751 new ListResultDescriptor<AnalysisError>(
752 'PARSE_ERRORS2', AnalysisError.NO_ERRORS);
753
754 /**
732 * The errors produced while resolving bounds of type parameters of classes, 755 * The errors produced while resolving bounds of type parameters of classes,
733 * class and function aliases. 756 * class and function aliases.
734 * 757 *
735 * The list will be empty if there were no errors, but will not be `null`. 758 * The list will be empty if there were no errors, but will not be `null`.
736 * 759 *
737 * The result is only available for [LibrarySpecificUnit]s. 760 * The result is only available for [LibrarySpecificUnit]s.
738 */ 761 */
739 final ListResultDescriptor<AnalysisError> RESOLVE_TYPE_BOUNDS_ERRORS = 762 final ListResultDescriptor<AnalysisError> RESOLVE_TYPE_BOUNDS_ERRORS =
740 new ListResultDescriptor<AnalysisError>( 763 new ListResultDescriptor<AnalysisError>(
741 'RESOLVE_TYPE_BOUNDS_ERRORS', AnalysisError.NO_ERRORS); 764 'RESOLVE_TYPE_BOUNDS_ERRORS', AnalysisError.NO_ERRORS);
(...skipping 2008 matching lines...) Expand 10 before | Expand all | Expand 10 after
2750 targetLibrary = target; 2773 targetLibrary = target;
2751 } 2774 }
2752 } 2775 }
2753 // We don't know what to do with the given target, invalidate it. 2776 // We don't know what to do with the given target, invalidate it.
2754 if (targetUnit == null || targetUnit != targetLibrary) { 2777 if (targetUnit == null || targetUnit != targetLibrary) {
2755 return DeltaResult.INVALIDATE; 2778 return DeltaResult.INVALIDATE;
2756 } 2779 }
2757 // Keep results that don't change: any library. 2780 // Keep results that don't change: any library.
2758 if (_isTaskResult(ScanDartTask.DESCRIPTOR, descriptor) || 2781 if (_isTaskResult(ScanDartTask.DESCRIPTOR, descriptor) ||
2759 _isTaskResult(ParseDartTask.DESCRIPTOR, descriptor) || 2782 _isTaskResult(ParseDartTask.DESCRIPTOR, descriptor) ||
2783 _isTaskResult(ResolveDirectivesTask.DESCRIPTOR, descriptor) ||
2760 _isTaskResult(BuildCompilationUnitElementTask.DESCRIPTOR, descriptor) || 2784 _isTaskResult(BuildCompilationUnitElementTask.DESCRIPTOR, descriptor) ||
2761 _isTaskResult(BuildLibraryElementTask.DESCRIPTOR, descriptor) || 2785 _isTaskResult(BuildLibraryElementTask.DESCRIPTOR, descriptor) ||
2762 _isTaskResult(BuildDirectiveElementsTask.DESCRIPTOR, descriptor) || 2786 _isTaskResult(BuildDirectiveElementsTask.DESCRIPTOR, descriptor) ||
2763 _isTaskResult(ResolveDirectiveElementsTask.DESCRIPTOR, descriptor) || 2787 _isTaskResult(ResolveDirectiveElementsTask.DESCRIPTOR, descriptor) ||
2764 _isTaskResult(BuildEnumMemberElementsTask.DESCRIPTOR, descriptor) || 2788 _isTaskResult(BuildEnumMemberElementsTask.DESCRIPTOR, descriptor) ||
2765 _isTaskResult(BuildSourceExportClosureTask.DESCRIPTOR, descriptor) || 2789 _isTaskResult(BuildSourceExportClosureTask.DESCRIPTOR, descriptor) ||
2766 _isTaskResult(ReadyLibraryElement2Task.DESCRIPTOR, descriptor) || 2790 _isTaskResult(ReadyLibraryElement2Task.DESCRIPTOR, descriptor) ||
2767 _isTaskResult(ComputeLibraryCycleTask.DESCRIPTOR, descriptor)) { 2791 _isTaskResult(ComputeLibraryCycleTask.DESCRIPTOR, descriptor)) {
2768 return DeltaResult.KEEP_CONTINUE; 2792 return DeltaResult.KEEP_CONTINUE;
2769 } 2793 }
(...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after
4028 /** 4052 /**
4029 * The name of the input whose value is the token stream produced for the file . 4053 * The name of the input whose value is the token stream produced for the file .
4030 */ 4054 */
4031 static const String TOKEN_STREAM_INPUT_NAME = 'TOKEN_STREAM_INPUT_NAME'; 4055 static const String TOKEN_STREAM_INPUT_NAME = 'TOKEN_STREAM_INPUT_NAME';
4032 4056
4033 /** 4057 /**
4034 * The task descriptor describing this kind of task. 4058 * The task descriptor describing this kind of task.
4035 */ 4059 */
4036 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 4060 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4037 'ParseDartTask', createTask, buildInputs, <ResultDescriptor>[ 4061 'ParseDartTask', createTask, buildInputs, <ResultDescriptor>[
4038 EXPLICITLY_IMPORTED_LIBRARIES,
4039 EXPORTED_LIBRARIES,
4040 IMPORTED_LIBRARIES,
4041 INCLUDED_PARTS,
4042 LIBRARY_SPECIFIC_UNITS,
4043 PARSE_ERRORS, 4062 PARSE_ERRORS,
4044 PARSED_UNIT, 4063 PARSED_UNIT1,
4045 REFERENCED_NAMES, 4064 REFERENCED_NAMES,
4046 REFERENCED_SOURCES,
4047 SOURCE_KIND, 4065 SOURCE_KIND,
4048 UNITS,
4049 ]); 4066 ]);
4050 4067
4051 /** 4068 /**
4052 * Initialize a newly created task to parse the content of the Dart file 4069 * Initialize a newly created task to parse the content of the Dart file
4053 * associated with the given [target] in the given [context]. 4070 * associated with the given [target] in the given [context].
4054 */ 4071 */
4055 ParseDartTask(InternalAnalysisContext context, AnalysisTarget target) 4072 ParseDartTask(InternalAnalysisContext context, AnalysisTarget target)
4056 : super(context, target); 4073 : super(context, target);
4057 4074
4058 @override 4075 @override
(...skipping 11 matching lines...) Expand all
4070 AnalysisOptions options = context.analysisOptions; 4087 AnalysisOptions options = context.analysisOptions;
4071 parser.parseAsync = options.enableAsync; 4088 parser.parseAsync = options.enableAsync;
4072 parser.parseFunctionBodies = options.analyzeFunctionBodiesPredicate(source); 4089 parser.parseFunctionBodies = options.analyzeFunctionBodiesPredicate(source);
4073 parser.parseGenericMethods = options.enableGenericMethods; 4090 parser.parseGenericMethods = options.enableGenericMethods;
4074 parser.parseGenericMethodComments = options.strongMode; 4091 parser.parseGenericMethodComments = options.strongMode;
4075 CompilationUnit unit = parser.parseCompilationUnit(tokenStream); 4092 CompilationUnit unit = parser.parseCompilationUnit(tokenStream);
4076 unit.lineInfo = lineInfo; 4093 unit.lineInfo = lineInfo;
4077 4094
4078 bool hasNonPartOfDirective = false; 4095 bool hasNonPartOfDirective = false;
4079 bool hasPartOfDirective = false; 4096 bool hasPartOfDirective = false;
4080 HashSet<Source> explicitlyImportedSourceSet = new HashSet<Source>(); 4097 List<Directive> directives = unit.directives;
4081 HashSet<Source> exportedSourceSet = new HashSet<Source>();
4082 HashSet<Source> includedSourceSet = new HashSet<Source>();
4083 NodeList<Directive> directives = unit.directives;
4084 int length = directives.length; 4098 int length = directives.length;
4085 for (int i = 0; i < length; i++) { 4099 for (int i = 0; i < length; i++) {
4086 Directive directive = directives[i]; 4100 Directive directive = directives[i];
4087 if (directive is PartOfDirective) { 4101 if (directive is PartOfDirective) {
4088 hasPartOfDirective = true; 4102 hasPartOfDirective = true;
4089 } else { 4103 } else {
4090 hasNonPartOfDirective = true; 4104 hasNonPartOfDirective = true;
4091 if (directive is UriBasedDirective) {
4092 Source referencedSource =
4093 resolveDirective(context, source, directive, errorListener);
4094 if (referencedSource != null) {
4095 if (directive is ExportDirective) {
4096 exportedSourceSet.add(referencedSource);
4097 } else if (directive is ImportDirective) {
4098 explicitlyImportedSourceSet.add(referencedSource);
4099 } else if (directive is PartDirective) {
4100 includedSourceSet.add(referencedSource);
4101 } else {
4102 throw new AnalysisException(
4103 '$runtimeType failed to handle a ${directive.runtimeType}');
4104 }
4105 }
4106 }
4107 } 4105 }
4108 } 4106 }
4109 // 4107 //
4110 // Always include "dart:core" source.
4111 //
4112 HashSet<Source> importedSourceSet =
4113 new HashSet.from(explicitlyImportedSourceSet);
4114 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE);
4115 if (coreLibrarySource == null) {
4116 String message;
4117 DartSdk sdk = context.sourceFactory.dartSdk;
4118 if (sdk == null) {
4119 message = 'Could not resolve "dart:core": SDK not defined';
4120 } else {
4121 message = 'Could not resolve "dart:core": SDK incorrectly configured';
4122 }
4123 throw new AnalysisException(message);
4124 }
4125 importedSourceSet.add(coreLibrarySource);
4126 //
4127 // Compute kind. 4108 // Compute kind.
4128 // 4109 //
4129 SourceKind sourceKind = SourceKind.LIBRARY; 4110 SourceKind sourceKind = SourceKind.LIBRARY;
4130 if (modificationTime == -1) { 4111 if (modificationTime == -1) {
4131 sourceKind = SourceKind.UNKNOWN; 4112 sourceKind = SourceKind.UNKNOWN;
4132 } else if (hasPartOfDirective && !hasNonPartOfDirective) { 4113 } else if (hasPartOfDirective && !hasNonPartOfDirective) {
4133 sourceKind = SourceKind.PART; 4114 sourceKind = SourceKind.PART;
4134 } 4115 }
4135 // 4116 //
4136 // Compute referenced names. 4117 // Compute referenced names.
4137 // 4118 //
4138 ReferencedNames referencedNames = new ReferencedNames(source); 4119 ReferencedNames referencedNames = new ReferencedNames(source);
4139 new ReferencedNamesBuilder(referencedNames).build(unit); 4120 new ReferencedNamesBuilder(referencedNames).build(unit);
4140 // 4121 //
4141 // Record outputs. 4122 // Record outputs.
4142 // 4123 //
4143 List<Source> explicitlyImportedSources =
4144 explicitlyImportedSourceSet.toList();
4145 List<Source> exportedSources = exportedSourceSet.toList();
4146 List<Source> importedSources = importedSourceSet.toList();
4147 List<Source> includedSources = includedSourceSet.toList();
4148 List<AnalysisError> parseErrors = getUniqueErrors(errorListener.errors); 4124 List<AnalysisError> parseErrors = getUniqueErrors(errorListener.errors);
4149 List<Source> unitSources = <Source>[source]..addAll(includedSourceSet);
4150 List<Source> referencedSources = (new Set<Source>()
4151 ..addAll(importedSources)
4152 ..addAll(exportedSources)
4153 ..addAll(unitSources))
4154 .toList();
4155 List<LibrarySpecificUnit> librarySpecificUnits =
4156 unitSources.map((s) => new LibrarySpecificUnit(source, s)).toList();
4157 outputs[EXPLICITLY_IMPORTED_LIBRARIES] = explicitlyImportedSources;
4158 outputs[EXPORTED_LIBRARIES] = exportedSources;
4159 outputs[IMPORTED_LIBRARIES] = importedSources;
4160 outputs[INCLUDED_PARTS] = includedSources;
4161 outputs[LIBRARY_SPECIFIC_UNITS] = librarySpecificUnits;
4162 outputs[PARSE_ERRORS] = parseErrors; 4125 outputs[PARSE_ERRORS] = parseErrors;
4163 outputs[PARSED_UNIT] = unit; 4126 outputs[PARSED_UNIT1] = unit;
4164 outputs[REFERENCED_NAMES] = referencedNames; 4127 outputs[REFERENCED_NAMES] = referencedNames;
4165 outputs[REFERENCED_SOURCES] = referencedSources;
4166 outputs[SOURCE_KIND] = sourceKind; 4128 outputs[SOURCE_KIND] = sourceKind;
4167 outputs[UNITS] = unitSources;
4168 } 4129 }
4169 4130
4170 /** 4131 /**
4171 * Return a map from the names of the inputs of this kind of task to the task 4132 * Return a map from the names of the inputs of this kind of task to the task
4172 * input descriptors describing those inputs for a task with the given 4133 * input descriptors describing those inputs for a task with the given
4173 * [target]. 4134 * [target].
4174 */ 4135 */
4175 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 4136 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4176 return <String, TaskInput>{ 4137 return <String, TaskInput>{
4177 LINE_INFO_INPUT_NAME: LINE_INFO.of(target), 4138 LINE_INFO_INPUT_NAME: LINE_INFO.of(target),
4178 MODIFICATION_TIME_INPUT_NAME: MODIFICATION_TIME.of(target), 4139 MODIFICATION_TIME_INPUT_NAME: MODIFICATION_TIME.of(target),
4179 TOKEN_STREAM_INPUT_NAME: TOKEN_STREAM.of(target, flushOnAccess: true) 4140 TOKEN_STREAM_INPUT_NAME: TOKEN_STREAM.of(target, flushOnAccess: true)
4180 }; 4141 };
4181 } 4142 }
4182 4143
4183 /** 4144 /**
4184 * Create a [ParseDartTask] based on the given [target] in the given 4145 * Create a [ParseDartTask] based on the given [target] in the given
4185 * [context]. 4146 * [context].
4186 */ 4147 */
4187 static ParseDartTask createTask( 4148 static ParseDartTask createTask(
4188 AnalysisContext context, AnalysisTarget target) { 4149 AnalysisContext context, AnalysisTarget target) {
4189 return new ParseDartTask(context, target); 4150 return new ParseDartTask(context, target);
4190 } 4151 }
4191
4192 /**
4193 * Return the result of resolving the URI of the given URI-based [directive]
4194 * against the URI of the given library, or `null` if the URI is not valid.
4195 *
4196 * Resolution is to be performed in the given [context]. Errors should be
4197 * reported to the [errorListener].
4198 */
4199 static Source resolveDirective(AnalysisContext context, Source librarySource,
4200 UriBasedDirective directive, AnalysisErrorListener errorListener) {
4201 StringLiteral uriLiteral = directive.uri;
4202 String uriContent = uriLiteral.stringValue;
4203 if (uriContent != null) {
4204 uriContent = uriContent.trim();
4205 directive.uriContent = uriContent;
4206 }
4207 UriValidationCode code = directive.validate();
4208 if (code == null) {
4209 String encodedUriContent = Uri.encodeFull(uriContent);
4210 Source source =
4211 context.sourceFactory.resolveUri(librarySource, encodedUriContent);
4212 directive.source = source;
4213 return source;
4214 }
4215 if (code == UriValidationCode.URI_WITH_DART_EXT_SCHEME) {
4216 return null;
4217 }
4218 if (code == UriValidationCode.URI_WITH_INTERPOLATION) {
4219 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset,
4220 uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION));
4221 return null;
4222 }
4223 if (code == UriValidationCode.INVALID_URI) {
4224 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset,
4225 uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent]));
4226 return null;
4227 }
4228 throw new AnalysisException('Failed to handle validation code: $code');
4229 }
4230 } 4152 }
4231 4153
4232 /** 4154 /**
4233 * A task that builds [RESOLVED_UNIT7] for a unit. 4155 * A task that builds [RESOLVED_UNIT7] for a unit.
4234 */ 4156 */
4235 class PartiallyResolveUnitReferencesTask extends SourceBasedAnalysisTask { 4157 class PartiallyResolveUnitReferencesTask extends SourceBasedAnalysisTask {
4236 /** 4158 /**
4237 * The name of the [LIBRARY_ELEMENT6] input. 4159 * The name of the [LIBRARY_ELEMENT6] input.
4238 */ 4160 */
4239 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 4161 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
5317 * Create a [ResolveDirectiveElementsTask] based on the given [target] in 5239 * Create a [ResolveDirectiveElementsTask] based on the given [target] in
5318 * the given [context]. 5240 * the given [context].
5319 */ 5241 */
5320 static ResolveDirectiveElementsTask createTask( 5242 static ResolveDirectiveElementsTask createTask(
5321 AnalysisContext context, AnalysisTarget target) { 5243 AnalysisContext context, AnalysisTarget target) {
5322 return new ResolveDirectiveElementsTask(context, target); 5244 return new ResolveDirectiveElementsTask(context, target);
5323 } 5245 }
5324 } 5246 }
5325 5247
5326 /** 5248 /**
5249 * A task that resolves URIs of [UriBasedDirective]s and reports errors.
5250 */
5251 class ResolveDirectivesTask extends SourceBasedAnalysisTask {
5252 /**
5253 * The name of the input whose value is the [PARSED_UNIT1] for the file.
5254 */
5255 static const String PARSED_UNIT_INPUT = 'PARSED_UNIT_INPUT';
5256
5257 /**
5258 * The task descriptor describing this kind of task.
5259 */
5260 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
5261 'ResolveDirectivesTask', createTask, buildInputs, <ResultDescriptor>[
5262 EXPLICITLY_IMPORTED_LIBRARIES,
5263 EXPORTED_LIBRARIES,
5264 IMPORTED_LIBRARIES,
5265 INCLUDED_PARTS,
5266 LIBRARY_SPECIFIC_UNITS,
5267 PARSED_UNIT,
5268 RESOLVE_DIRECTIVES_ERRORS,
5269 REFERENCED_SOURCES,
5270 UNITS,
5271 ]);
5272
5273 /**
5274 * Initialize a newly created task to parse the content of the Dart file
5275 * associated with the given [target] in the given [context].
5276 */
5277 ResolveDirectivesTask(InternalAnalysisContext context, AnalysisTarget target)
5278 : super(context, target);
5279
5280 @override
5281 TaskDescriptor get descriptor => DESCRIPTOR;
5282
5283 @override
5284 void internalPerform() {
5285 Source source = getRequiredSource();
5286 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT);
5287
5288 RecordingErrorListener errorListener = new RecordingErrorListener();
5289 HashSet<Source> explicitlyImportedSourceSet = new HashSet<Source>();
5290 HashSet<Source> exportedSourceSet = new HashSet<Source>();
5291 HashSet<Source> includedSourceSet = new HashSet<Source>();
5292 NodeList<Directive> directives = unit.directives;
5293 int length = directives.length;
5294 for (int i = 0; i < length; i++) {
5295 Directive directive = directives[i];
5296 if (directive is UriBasedDirective) {
5297 Source referencedSource =
5298 resolveDirective(context, source, directive, errorListener);
5299 if (referencedSource != null) {
5300 if (directive is ExportDirective) {
5301 exportedSourceSet.add(referencedSource);
5302 } else if (directive is ImportDirective) {
5303 explicitlyImportedSourceSet.add(referencedSource);
5304 } else if (directive is PartDirective) {
5305 includedSourceSet.add(referencedSource);
5306 } else {
5307 throw new AnalysisException(
5308 '$runtimeType failed to handle a ${directive.runtimeType}');
5309 }
5310 }
5311 }
5312 }
5313 //
5314 // Always include "dart:core" source.
5315 //
5316 HashSet<Source> importedSourceSet =
5317 new HashSet.from(explicitlyImportedSourceSet);
5318 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE);
5319 if (coreLibrarySource == null) {
5320 String message;
5321 DartSdk sdk = context.sourceFactory.dartSdk;
5322 if (sdk == null) {
5323 message = 'Could not resolve "dart:core": SDK not defined';
5324 } else {
5325 message = 'Could not resolve "dart:core": SDK incorrectly configured';
5326 }
5327 throw new AnalysisException(message);
5328 }
5329 importedSourceSet.add(coreLibrarySource);
5330 //
5331 // Record outputs.
5332 //
5333 List<Source> explicitlyImportedSources =
5334 explicitlyImportedSourceSet.toList();
5335 List<Source> exportedSources = exportedSourceSet.toList();
5336 List<Source> importedSources = importedSourceSet.toList();
5337 List<Source> includedSources = includedSourceSet.toList();
5338 List<AnalysisError> errors = getUniqueErrors(errorListener.errors);
5339 List<Source> unitSources = <Source>[source]..addAll(includedSourceSet);
5340 List<Source> referencedSources = (new Set<Source>()
5341 ..addAll(importedSources)
5342 ..addAll(exportedSources)
5343 ..addAll(unitSources))
5344 .toList();
5345 List<LibrarySpecificUnit> librarySpecificUnits =
5346 unitSources.map((s) => new LibrarySpecificUnit(source, s)).toList();
5347 outputs[EXPLICITLY_IMPORTED_LIBRARIES] = explicitlyImportedSources;
5348 outputs[EXPORTED_LIBRARIES] = exportedSources;
5349 outputs[IMPORTED_LIBRARIES] = importedSources;
5350 outputs[INCLUDED_PARTS] = includedSources;
5351 outputs[LIBRARY_SPECIFIC_UNITS] = librarySpecificUnits;
5352 outputs[PARSED_UNIT] = unit;
5353 outputs[RESOLVE_DIRECTIVES_ERRORS] = errors;
5354 outputs[REFERENCED_SOURCES] = referencedSources;
5355 outputs[UNITS] = unitSources;
5356 }
5357
5358 /**
5359 * Return a map from the names of the inputs of this kind of task to the task
5360 * input descriptors describing those inputs for a task with the given
5361 * [target].
5362 */
5363 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
5364 return <String, TaskInput>{
5365 PARSED_UNIT_INPUT: PARSED_UNIT1.of(target, flushOnAccess: true)
5366 };
5367 }
5368
5369 /**
5370 * Create a [ResolveDirectivesTask] based on the given [target] in the given
5371 * [context].
5372 */
5373 static ResolveDirectivesTask createTask(
5374 AnalysisContext context, AnalysisTarget target) {
5375 return new ResolveDirectivesTask(context, target);
5376 }
5377
5378 /**
5379 * Return the result of resolving the URI of the given URI-based [directive]
5380 * against the URI of the given library, or `null` if the URI is not valid.
5381 *
5382 * Resolution is to be performed in the given [context]. Errors should be
5383 * reported to the [errorListener].
5384 */
5385 static Source resolveDirective(AnalysisContext context, Source librarySource,
5386 UriBasedDirective directive, AnalysisErrorListener errorListener) {
5387 StringLiteral uriLiteral = directive.uri;
5388 String uriContent = uriLiteral.stringValue;
5389 if (uriContent != null) {
5390 uriContent = uriContent.trim();
5391 directive.uriContent = uriContent;
5392 }
5393 UriValidationCode code = directive.validate();
5394 if (code == null) {
5395 String encodedUriContent = Uri.encodeFull(uriContent);
5396 Source source =
5397 context.sourceFactory.resolveUri(librarySource, encodedUriContent);
5398 directive.source = source;
5399 return source;
5400 }
5401 if (code == UriValidationCode.URI_WITH_DART_EXT_SCHEME) {
5402 return null;
5403 }
5404 if (code == UriValidationCode.URI_WITH_INTERPOLATION) {
5405 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset,
5406 uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION));
5407 return null;
5408 }
5409 if (code == UriValidationCode.INVALID_URI) {
5410 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset,
5411 uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent]));
5412 return null;
5413 }
5414 throw new AnalysisException('Failed to handle validation code: $code');
5415 }
5416 }
5417
5418 /**
5327 * A task that ensures that all of the inferable instance members in a 5419 * A task that ensures that all of the inferable instance members in a
5328 * compilation unit have had their right hand sides re-resolved 5420 * compilation unit have had their right hand sides re-resolved
5329 */ 5421 */
5330 class ResolveInstanceFieldsInUnitTask extends SourceBasedAnalysisTask { 5422 class ResolveInstanceFieldsInUnitTask extends SourceBasedAnalysisTask {
5331 /** 5423 /**
5332 * The name of the [LIBRARY_ELEMENT6] input. 5424 * The name of the [LIBRARY_ELEMENT6] input.
5333 */ 5425 */
5334 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 5426 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
5335 5427
5336 /** 5428 /**
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
6578 6670
6579 @override 6671 @override
6580 bool moveNext() { 6672 bool moveNext() {
6581 if (_newSources.isEmpty) { 6673 if (_newSources.isEmpty) {
6582 return false; 6674 return false;
6583 } 6675 }
6584 currentTarget = _newSources.removeLast(); 6676 currentTarget = _newSources.removeLast();
6585 return true; 6677 return true;
6586 } 6678 }
6587 } 6679 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/plugin/engine_plugin.dart ('k') | pkg/analyzer/lib/src/task/dart_work_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698