| 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/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 * | 670 * |
| 671 * The list will be empty if there were no errors, but will not be `null`. | 671 * The list will be empty if there were no errors, but will not be `null`. |
| 672 * | 672 * |
| 673 * The result is only available for [LibrarySpecificUnit]s. | 673 * The result is only available for [LibrarySpecificUnit]s. |
| 674 */ | 674 */ |
| 675 final ListResultDescriptor<AnalysisError> VERIFY_ERRORS = | 675 final ListResultDescriptor<AnalysisError> VERIFY_ERRORS = |
| 676 new ListResultDescriptor<AnalysisError>( | 676 new ListResultDescriptor<AnalysisError>( |
| 677 'VERIFY_ERRORS', AnalysisError.NO_ERRORS); | 677 'VERIFY_ERRORS', AnalysisError.NO_ERRORS); |
| 678 | 678 |
| 679 /** | 679 /** |
| 680 * Return a list of unique errors for the [Source] of the given [target]. |
| 681 */ |
| 682 List<AnalysisError> getTargetSourceErrors( |
| 683 RecordingErrorListener listener, AnalysisTarget target) { |
| 684 Source source = target.source; |
| 685 List<AnalysisError> errors = listener.getErrorsForSource(source); |
| 686 return getUniqueErrors(errors); |
| 687 } |
| 688 |
| 689 /** |
| 680 * Return a list of errors containing the errors from the given [errors] list | 690 * Return a list of errors containing the errors from the given [errors] list |
| 681 * but with duplications removed. | 691 * but with duplications removed. |
| 682 */ | 692 */ |
| 683 List<AnalysisError> removeDuplicateErrors(List<AnalysisError> errors) { | 693 List<AnalysisError> getUniqueErrors(List<AnalysisError> errors) { |
| 684 if (errors.isEmpty) { | 694 if (errors.isEmpty) { |
| 685 return errors; | 695 return errors; |
| 686 } | 696 } |
| 687 return errors.toSet().toList(); | 697 return errors.toSet().toList(); |
| 688 } | 698 } |
| 689 | 699 |
| 690 /** | 700 /** |
| 691 * A task that builds a compilation unit element for a single compilation unit. | 701 * A task that builds a compilation unit element for a single compilation unit. |
| 692 */ | 702 */ |
| 693 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask { | 703 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask { |
| (...skipping 2775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3469 sourceKind = SourceKind.PART; | 3479 sourceKind = SourceKind.PART; |
| 3470 } | 3480 } |
| 3471 // | 3481 // |
| 3472 // Record outputs. | 3482 // Record outputs. |
| 3473 // | 3483 // |
| 3474 List<Source> explicitlyImportedSources = | 3484 List<Source> explicitlyImportedSources = |
| 3475 explicitlyImportedSourceSet.toList(); | 3485 explicitlyImportedSourceSet.toList(); |
| 3476 List<Source> exportedSources = exportedSourceSet.toList(); | 3486 List<Source> exportedSources = exportedSourceSet.toList(); |
| 3477 List<Source> importedSources = importedSourceSet.toList(); | 3487 List<Source> importedSources = importedSourceSet.toList(); |
| 3478 List<Source> includedSources = includedSourceSet.toList(); | 3488 List<Source> includedSources = includedSourceSet.toList(); |
| 3479 List<AnalysisError> parseErrors = | 3489 List<AnalysisError> parseErrors = getUniqueErrors(errorListener.errors); |
| 3480 removeDuplicateErrors(errorListener.errors); | |
| 3481 List<Source> unitSources = <Source>[source]..addAll(includedSourceSet); | 3490 List<Source> unitSources = <Source>[source]..addAll(includedSourceSet); |
| 3482 List<LibrarySpecificUnit> librarySpecificUnits = | 3491 List<LibrarySpecificUnit> librarySpecificUnits = |
| 3483 unitSources.map((s) => new LibrarySpecificUnit(source, s)).toList(); | 3492 unitSources.map((s) => new LibrarySpecificUnit(source, s)).toList(); |
| 3484 outputs[EXPLICITLY_IMPORTED_LIBRARIES] = explicitlyImportedSources; | 3493 outputs[EXPLICITLY_IMPORTED_LIBRARIES] = explicitlyImportedSources; |
| 3485 outputs[EXPORTED_LIBRARIES] = exportedSources; | 3494 outputs[EXPORTED_LIBRARIES] = exportedSources; |
| 3486 outputs[IMPORTED_LIBRARIES] = importedSources; | 3495 outputs[IMPORTED_LIBRARIES] = importedSources; |
| 3487 outputs[INCLUDED_PARTS] = includedSources; | 3496 outputs[INCLUDED_PARTS] = includedSources; |
| 3488 outputs[LIBRARY_SPECIFIC_UNITS] = librarySpecificUnits; | 3497 outputs[LIBRARY_SPECIFIC_UNITS] = librarySpecificUnits; |
| 3489 outputs[PARSE_ERRORS] = parseErrors; | 3498 outputs[PARSE_ERRORS] = parseErrors; |
| 3490 outputs[PARSED_UNIT] = unit; | 3499 outputs[PARSED_UNIT] = unit; |
| (...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4643 ResolverVisitor visitor = new ResolverVisitor( | 4652 ResolverVisitor visitor = new ResolverVisitor( |
| 4644 libraryElement, unitElement.source, typeProvider, errorListener); | 4653 libraryElement, unitElement.source, typeProvider, errorListener); |
| 4645 unit.accept(visitor); | 4654 unit.accept(visitor); |
| 4646 // | 4655 // |
| 4647 // Record outputs. | 4656 // Record outputs. |
| 4648 // | 4657 // |
| 4649 // TODO(brianwilkerson) This task modifies the element model (by copying the | 4658 // TODO(brianwilkerson) This task modifies the element model (by copying the |
| 4650 // AST's for constructor initializers into it) but does not produce an | 4659 // AST's for constructor initializers into it) but does not produce an |
| 4651 // updated version of the element model. | 4660 // updated version of the element model. |
| 4652 // | 4661 // |
| 4653 outputs[RESOLVE_UNIT_ERRORS] = errorListener.errors; | 4662 outputs[RESOLVE_UNIT_ERRORS] = getTargetSourceErrors(errorListener, target); |
| 4654 outputs[RESOLVED_UNIT10] = unit; | 4663 outputs[RESOLVED_UNIT10] = unit; |
| 4655 } | 4664 } |
| 4656 | 4665 |
| 4657 /** | 4666 /** |
| 4658 * Return a map from the names of the inputs of this kind of task to the task | 4667 * Return a map from the names of the inputs of this kind of task to the task |
| 4659 * input descriptors describing those inputs for a task with the given | 4668 * input descriptors describing those inputs for a task with the given |
| 4660 * [target]. | 4669 * [target]. |
| 4661 */ | 4670 */ |
| 4662 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 4671 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 4663 LibrarySpecificUnit unit = target; | 4672 LibrarySpecificUnit unit = target; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4734 // Resolve TypeName nodes. | 4743 // Resolve TypeName nodes. |
| 4735 // | 4744 // |
| 4736 RecordingErrorListener errorListener = new RecordingErrorListener(); | 4745 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 4737 TypeResolverVisitor visitor = new TypeResolverVisitor( | 4746 TypeResolverVisitor visitor = new TypeResolverVisitor( |
| 4738 library, unitElement.source, typeProvider, errorListener); | 4747 library, unitElement.source, typeProvider, errorListener); |
| 4739 unit.accept(visitor); | 4748 unit.accept(visitor); |
| 4740 // | 4749 // |
| 4741 // Record outputs. | 4750 // Record outputs. |
| 4742 // | 4751 // |
| 4743 outputs[RESOLVE_TYPE_NAMES_ERRORS] = | 4752 outputs[RESOLVE_TYPE_NAMES_ERRORS] = |
| 4744 removeDuplicateErrors(errorListener.errors); | 4753 getTargetSourceErrors(errorListener, target); |
| 4745 outputs[RESOLVED_UNIT3] = unit; | 4754 outputs[RESOLVED_UNIT3] = unit; |
| 4746 } | 4755 } |
| 4747 | 4756 |
| 4748 /** | 4757 /** |
| 4749 * Return a map from the names of the inputs of this kind of task to the task | 4758 * Return a map from the names of the inputs of this kind of task to the task |
| 4750 * input descriptors describing those inputs for a task with the | 4759 * input descriptors describing those inputs for a task with the |
| 4751 * given [target]. | 4760 * given [target]. |
| 4752 */ | 4761 */ |
| 4753 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 4762 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 4754 // TODO(brianwilkerson) This task updates the element model to have type | 4763 // TODO(brianwilkerson) This task updates the element model to have type |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4825 Scope nameScope = new LibraryScope(libraryElement, errorListener); | 4834 Scope nameScope = new LibraryScope(libraryElement, errorListener); |
| 4826 VariableResolverVisitor visitor = new VariableResolverVisitor( | 4835 VariableResolverVisitor visitor = new VariableResolverVisitor( |
| 4827 libraryElement, unitElement.source, typeProvider, errorListener, | 4836 libraryElement, unitElement.source, typeProvider, errorListener, |
| 4828 nameScope: nameScope); | 4837 nameScope: nameScope); |
| 4829 unit.accept(visitor); | 4838 unit.accept(visitor); |
| 4830 // | 4839 // |
| 4831 // Record outputs. | 4840 // Record outputs. |
| 4832 // | 4841 // |
| 4833 outputs[RESOLVED_UNIT4] = unit; | 4842 outputs[RESOLVED_UNIT4] = unit; |
| 4834 outputs[VARIABLE_REFERENCE_ERRORS] = | 4843 outputs[VARIABLE_REFERENCE_ERRORS] = |
| 4835 removeDuplicateErrors(errorListener.errors); | 4844 getTargetSourceErrors(errorListener, target); |
| 4836 } | 4845 } |
| 4837 | 4846 |
| 4838 /** | 4847 /** |
| 4839 * Return a map from the names of the inputs of this kind of task to the task | 4848 * Return a map from the names of the inputs of this kind of task to the task |
| 4840 * input descriptors describing those inputs for a task with the | 4849 * input descriptors describing those inputs for a task with the |
| 4841 * given [target]. | 4850 * given [target]. |
| 4842 */ | 4851 */ |
| 4843 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 4852 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 4844 LibrarySpecificUnit unit = target; | 4853 LibrarySpecificUnit unit = target; |
| 4845 return <String, TaskInput>{ | 4854 return <String, TaskInput>{ |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4922 Scanner scanner = new Scanner( | 4931 Scanner scanner = new Scanner( |
| 4923 source, | 4932 source, |
| 4924 new SubSequenceReader(fragment.content, fragment.offset), | 4933 new SubSequenceReader(fragment.content, fragment.offset), |
| 4925 errorListener); | 4934 errorListener); |
| 4926 scanner.setSourceStart(fragment.line, fragment.column); | 4935 scanner.setSourceStart(fragment.line, fragment.column); |
| 4927 scanner.preserveComments = context.analysisOptions.preserveComments; | 4936 scanner.preserveComments = context.analysisOptions.preserveComments; |
| 4928 scanner.scanGenericMethodComments = context.analysisOptions.strongMode; | 4937 scanner.scanGenericMethodComments = context.analysisOptions.strongMode; |
| 4929 | 4938 |
| 4930 outputs[TOKEN_STREAM] = scanner.tokenize(); | 4939 outputs[TOKEN_STREAM] = scanner.tokenize(); |
| 4931 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); | 4940 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); |
| 4932 outputs[SCAN_ERRORS] = removeDuplicateErrors(errorListener.errors); | 4941 outputs[SCAN_ERRORS] = getUniqueErrors(errorListener.errors); |
| 4933 } else if (target is Source) { | 4942 } else if (target is Source) { |
| 4934 String content = getRequiredInput(CONTENT_INPUT_NAME); | 4943 String content = getRequiredInput(CONTENT_INPUT_NAME); |
| 4935 | 4944 |
| 4936 Scanner scanner = | 4945 Scanner scanner = |
| 4937 new Scanner(source, new CharSequenceReader(content), errorListener); | 4946 new Scanner(source, new CharSequenceReader(content), errorListener); |
| 4938 scanner.preserveComments = context.analysisOptions.preserveComments; | 4947 scanner.preserveComments = context.analysisOptions.preserveComments; |
| 4939 scanner.scanGenericMethodComments = context.analysisOptions.strongMode; | 4948 scanner.scanGenericMethodComments = context.analysisOptions.strongMode; |
| 4940 | 4949 |
| 4941 outputs[TOKEN_STREAM] = scanner.tokenize(); | 4950 outputs[TOKEN_STREAM] = scanner.tokenize(); |
| 4942 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); | 4951 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); |
| 4943 outputs[SCAN_ERRORS] = removeDuplicateErrors(errorListener.errors); | 4952 outputs[SCAN_ERRORS] = getUniqueErrors(errorListener.errors); |
| 4944 } else { | 4953 } else { |
| 4945 throw new AnalysisException( | 4954 throw new AnalysisException( |
| 4946 'Cannot scan Dart code from a ${target.runtimeType}'); | 4955 'Cannot scan Dart code from a ${target.runtimeType}'); |
| 4947 } | 4956 } |
| 4948 } | 4957 } |
| 4949 | 4958 |
| 4950 /** | 4959 /** |
| 4951 * Return a map from the names of the inputs of this kind of task to the task | 4960 * Return a map from the names of the inputs of this kind of task to the task |
| 4952 * input descriptors describing those inputs for a task with the given | 4961 * input descriptors describing those inputs for a task with the given |
| 4953 * [source]. | 4962 * [source]. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5013 // | 5022 // |
| 5014 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); | 5023 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); |
| 5015 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | 5024 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
| 5016 if (context.analysisOptions.strongMode) { | 5025 if (context.analysisOptions.strongMode) { |
| 5017 unit.accept(new CodeChecker(new TypeRules(typeProvider), errorListener)); | 5026 unit.accept(new CodeChecker(new TypeRules(typeProvider), errorListener)); |
| 5018 } | 5027 } |
| 5019 | 5028 |
| 5020 // | 5029 // |
| 5021 // Record outputs. | 5030 // Record outputs. |
| 5022 // | 5031 // |
| 5023 outputs[STRONG_MODE_ERRORS] = removeDuplicateErrors(errorListener.errors); | 5032 outputs[STRONG_MODE_ERRORS] = getUniqueErrors(errorListener.errors); |
| 5024 outputs[RESOLVED_UNIT] = unit; | 5033 outputs[RESOLVED_UNIT] = unit; |
| 5025 } | 5034 } |
| 5026 | 5035 |
| 5027 /** | 5036 /** |
| 5028 * Return a map from the names of the inputs of this kind of task to the task | 5037 * Return a map from the names of the inputs of this kind of task to the task |
| 5029 * input descriptors describing those inputs for a task with the | 5038 * input descriptors describing those inputs for a task with the |
| 5030 * given [target]. | 5039 * given [target]. |
| 5031 */ | 5040 */ |
| 5032 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 5041 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 5033 LibrarySpecificUnit unit = target; | 5042 LibrarySpecificUnit unit = target; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5108 errorReporter, | 5117 errorReporter, |
| 5109 libraryElement, | 5118 libraryElement, |
| 5110 typeProvider, | 5119 typeProvider, |
| 5111 new InheritanceManager(libraryElement), | 5120 new InheritanceManager(libraryElement), |
| 5112 context.analysisOptions.enableSuperMixins); | 5121 context.analysisOptions.enableSuperMixins); |
| 5113 unit.accept(errorVerifier); | 5122 unit.accept(errorVerifier); |
| 5114 | 5123 |
| 5115 // | 5124 // |
| 5116 // Record outputs. | 5125 // Record outputs. |
| 5117 // | 5126 // |
| 5118 outputs[VERIFY_ERRORS] = removeDuplicateErrors(errorListener.errors); | 5127 outputs[VERIFY_ERRORS] = getUniqueErrors(errorListener.errors); |
| 5119 } | 5128 } |
| 5120 | 5129 |
| 5121 /** | 5130 /** |
| 5122 * Check each directive in the given [unit] to see if the referenced source | 5131 * Check each directive in the given [unit] to see if the referenced source |
| 5123 * exists and report an error if it does not. | 5132 * exists and report an error if it does not. |
| 5124 */ | 5133 */ |
| 5125 void validateDirectives(CompilationUnit unit) { | 5134 void validateDirectives(CompilationUnit unit) { |
| 5126 for (Directive directive in unit.directives) { | 5135 for (Directive directive in unit.directives) { |
| 5127 if (directive is UriBasedDirective) { | 5136 if (directive is UriBasedDirective) { |
| 5128 validateReferencedSource(directive); | 5137 validateReferencedSource(directive); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5273 | 5282 |
| 5274 @override | 5283 @override |
| 5275 bool moveNext() { | 5284 bool moveNext() { |
| 5276 if (_newSources.isEmpty) { | 5285 if (_newSources.isEmpty) { |
| 5277 return false; | 5286 return false; |
| 5278 } | 5287 } |
| 5279 currentTarget = _newSources.removeLast(); | 5288 currentTarget = _newSources.removeLast(); |
| 5280 return true; | 5289 return true; |
| 5281 } | 5290 } |
| 5282 } | 5291 } |
| OLD | NEW |