| 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 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 new ImportElementImpl(directive.offset); | 805 new ImportElementImpl(directive.offset); |
| 806 StringLiteral uriLiteral = importDirective.uri; | 806 StringLiteral uriLiteral = importDirective.uri; |
| 807 if (uriLiteral != null) { | 807 if (uriLiteral != null) { |
| 808 importElement.uriOffset = uriLiteral.offset; | 808 importElement.uriOffset = uriLiteral.offset; |
| 809 importElement.uriEnd = uriLiteral.end; | 809 importElement.uriEnd = uriLiteral.end; |
| 810 } | 810 } |
| 811 importElement.uri = uriContent; | 811 importElement.uri = uriContent; |
| 812 importElement.deferred = importDirective.deferredKeyword != null; | 812 importElement.deferred = importDirective.deferredKeyword != null; |
| 813 importElement.combinators = _buildCombinators(importDirective); | 813 importElement.combinators = _buildCombinators(importDirective); |
| 814 importElement.importedLibrary = importedLibrary; | 814 importElement.importedLibrary = importedLibrary; |
| 815 _setDocRange(importElement, importDirective); |
| 815 SimpleIdentifier prefixNode = directive.prefix; | 816 SimpleIdentifier prefixNode = directive.prefix; |
| 816 if (prefixNode != null) { | 817 if (prefixNode != null) { |
| 817 importElement.prefixOffset = prefixNode.offset; | 818 importElement.prefixOffset = prefixNode.offset; |
| 818 String prefixName = prefixNode.name; | 819 String prefixName = prefixNode.name; |
| 819 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; | 820 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; |
| 820 if (prefix == null) { | 821 if (prefix == null) { |
| 821 prefix = new PrefixElementImpl.forNode(prefixNode); | 822 prefix = new PrefixElementImpl.forNode(prefixNode); |
| 822 nameToPrefixMap[prefixName] = prefix; | 823 nameToPrefixMap[prefixName] = prefix; |
| 823 } | 824 } |
| 824 importElement.prefix = prefix; | 825 importElement.prefix = prefix; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 846 ExportElementImpl exportElement = | 847 ExportElementImpl exportElement = |
| 847 new ExportElementImpl(directive.offset); | 848 new ExportElementImpl(directive.offset); |
| 848 StringLiteral uriLiteral = exportDirective.uri; | 849 StringLiteral uriLiteral = exportDirective.uri; |
| 849 if (uriLiteral != null) { | 850 if (uriLiteral != null) { |
| 850 exportElement.uriOffset = uriLiteral.offset; | 851 exportElement.uriOffset = uriLiteral.offset; |
| 851 exportElement.uriEnd = uriLiteral.end; | 852 exportElement.uriEnd = uriLiteral.end; |
| 852 } | 853 } |
| 853 exportElement.uri = exportDirective.uriContent; | 854 exportElement.uri = exportDirective.uriContent; |
| 854 exportElement.combinators = _buildCombinators(exportDirective); | 855 exportElement.combinators = _buildCombinators(exportDirective); |
| 855 exportElement.exportedLibrary = exportedLibrary; | 856 exportElement.exportedLibrary = exportedLibrary; |
| 857 _setDocRange(exportElement, exportDirective); |
| 856 directive.element = exportElement; | 858 directive.element = exportElement; |
| 857 exports.add(exportElement); | 859 exports.add(exportElement); |
| 858 if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) { | 860 if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) { |
| 859 errors.add(new AnalysisError( | 861 errors.add(new AnalysisError( |
| 860 exportedSource, | 862 exportedSource, |
| 861 uriLiteral.offset, | 863 uriLiteral.offset, |
| 862 uriLiteral.length, | 864 uriLiteral.length, |
| 863 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, | 865 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, |
| 864 [uriLiteral.toSource()])); | 866 [uriLiteral.toSource()])); |
| 865 } | 867 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 886 // for details on library cycle invalidation. | 888 // for details on library cycle invalidation. |
| 887 libraryElement.invalidateLibraryCycles(); | 889 libraryElement.invalidateLibraryCycles(); |
| 888 // | 890 // |
| 889 // Record outputs. | 891 // Record outputs. |
| 890 // | 892 // |
| 891 outputs[LIBRARY_ELEMENT2] = libraryElement; | 893 outputs[LIBRARY_ELEMENT2] = libraryElement; |
| 892 outputs[BUILD_DIRECTIVES_ERRORS] = errors; | 894 outputs[BUILD_DIRECTIVES_ERRORS] = errors; |
| 893 } | 895 } |
| 894 | 896 |
| 895 /** | 897 /** |
| 898 * If the given [node] has a documentation comment, remember its range |
| 899 * into the given [element]. |
| 900 */ |
| 901 void _setDocRange(ElementImpl element, AnnotatedNode node) { |
| 902 Comment comment = node.documentationComment; |
| 903 if (comment != null && comment.isDocumentation) { |
| 904 element.setDocRange(comment.offset, comment.length); |
| 905 } |
| 906 } |
| 907 |
| 908 /** |
| 896 * Return a map from the names of the inputs of this kind of task to the task | 909 * Return a map from the names of the inputs of this kind of task to the task |
| 897 * input descriptors describing those inputs for a task with the | 910 * input descriptors describing those inputs for a task with the |
| 898 * given library [libSource]. | 911 * given library [libSource]. |
| 899 */ | 912 */ |
| 900 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 913 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 901 Source source = target; | 914 Source source = target; |
| 902 return <String, TaskInput>{ | 915 return <String, TaskInput>{ |
| 903 LIBRARY_INPUT: LIBRARY_ELEMENT1.of(source), | 916 LIBRARY_INPUT: LIBRARY_ELEMENT1.of(source), |
| 904 UNIT_INPUT_NAME: | 917 UNIT_INPUT_NAME: |
| 905 RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, source)), | 918 RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, source)), |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 definingCompilationUnit.element; | 1167 definingCompilationUnit.element; |
| 1155 Map<Source, CompilationUnit> partUnitMap = | 1168 Map<Source, CompilationUnit> partUnitMap = |
| 1156 new HashMap<Source, CompilationUnit>(); | 1169 new HashMap<Source, CompilationUnit>(); |
| 1157 for (CompilationUnit partUnit in partUnits) { | 1170 for (CompilationUnit partUnit in partUnits) { |
| 1158 Source partSource = partUnit.element.source; | 1171 Source partSource = partUnit.element.source; |
| 1159 partUnitMap[partSource] = partUnit; | 1172 partUnitMap[partSource] = partUnit; |
| 1160 } | 1173 } |
| 1161 // | 1174 // |
| 1162 // Update "part" directives. | 1175 // Update "part" directives. |
| 1163 // | 1176 // |
| 1177 LibraryDirective libraryDirective = null; |
| 1164 LibraryIdentifier libraryNameNode = null; | 1178 LibraryIdentifier libraryNameNode = null; |
| 1165 String partsLibraryName = _UNKNOWN_LIBRARY_NAME; | 1179 String partsLibraryName = _UNKNOWN_LIBRARY_NAME; |
| 1166 bool hasPartDirective = false; | 1180 bool hasPartDirective = false; |
| 1167 FunctionElement entryPoint = | 1181 FunctionElement entryPoint = |
| 1168 _findEntryPoint(definingCompilationUnitElement); | 1182 _findEntryPoint(definingCompilationUnitElement); |
| 1169 List<Directive> directivesToResolve = <Directive>[]; | 1183 List<Directive> directivesToResolve = <Directive>[]; |
| 1170 List<CompilationUnitElementImpl> sourcedCompilationUnits = | 1184 List<CompilationUnitElementImpl> sourcedCompilationUnits = |
| 1171 <CompilationUnitElementImpl>[]; | 1185 <CompilationUnitElementImpl>[]; |
| 1172 for (Directive directive in definingCompilationUnit.directives) { | 1186 for (Directive directive in definingCompilationUnit.directives) { |
| 1173 if (directive is LibraryDirective) { | 1187 if (directive is LibraryDirective) { |
| 1174 if (libraryNameNode == null) { | 1188 if (libraryDirective == null) { |
| 1189 libraryDirective = directive; |
| 1175 libraryNameNode = directive.name; | 1190 libraryNameNode = directive.name; |
| 1176 directivesToResolve.add(directive); | 1191 directivesToResolve.add(directive); |
| 1177 } | 1192 } |
| 1178 } else if (directive is PartDirective) { | 1193 } else if (directive is PartDirective) { |
| 1179 PartDirective partDirective = directive; | 1194 PartDirective partDirective = directive; |
| 1180 StringLiteral partUri = partDirective.uri; | 1195 StringLiteral partUri = partDirective.uri; |
| 1181 Source partSource = partDirective.source; | 1196 Source partSource = partDirective.source; |
| 1182 hasPartDirective = true; | 1197 hasPartDirective = true; |
| 1183 CompilationUnit partUnit = partUnitMap[partSource]; | 1198 CompilationUnit partUnit = partUnitMap[partSource]; |
| 1184 if (partUnit != null) { | 1199 if (partUnit != null) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 new LibraryElementImpl.forNode(owningContext, libraryNameNode); | 1263 new LibraryElementImpl.forNode(owningContext, libraryNameNode); |
| 1249 libraryElement.definingCompilationUnit = definingCompilationUnitElement; | 1264 libraryElement.definingCompilationUnit = definingCompilationUnitElement; |
| 1250 libraryElement.entryPoint = entryPoint; | 1265 libraryElement.entryPoint = entryPoint; |
| 1251 libraryElement.parts = sourcedCompilationUnits; | 1266 libraryElement.parts = sourcedCompilationUnits; |
| 1252 for (Directive directive in directivesToResolve) { | 1267 for (Directive directive in directivesToResolve) { |
| 1253 directive.element = libraryElement; | 1268 directive.element = libraryElement; |
| 1254 } | 1269 } |
| 1255 if (sourcedCompilationUnits.isNotEmpty) { | 1270 if (sourcedCompilationUnits.isNotEmpty) { |
| 1256 _patchTopLevelAccessors(libraryElement); | 1271 _patchTopLevelAccessors(libraryElement); |
| 1257 } | 1272 } |
| 1273 if (libraryDirective != null) { |
| 1274 _setDocRange(libraryElement, libraryDirective); |
| 1275 } |
| 1258 // | 1276 // |
| 1259 // Record outputs. | 1277 // Record outputs. |
| 1260 // | 1278 // |
| 1261 outputs[BUILD_LIBRARY_ERRORS] = errors; | 1279 outputs[BUILD_LIBRARY_ERRORS] = errors; |
| 1262 outputs[LIBRARY_ELEMENT1] = libraryElement; | 1280 outputs[LIBRARY_ELEMENT1] = libraryElement; |
| 1263 outputs[IS_LAUNCHABLE] = entryPoint != null; | 1281 outputs[IS_LAUNCHABLE] = entryPoint != null; |
| 1264 } | 1282 } |
| 1265 | 1283 |
| 1266 /** | 1284 /** |
| 1267 * Add all of the non-synthetic [getters] and [setters] defined in the given | 1285 * Add all of the non-synthetic [getters] and [setters] defined in the given |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 TopLevelVariableElementImpl setterVariable = setter.variable; | 1352 TopLevelVariableElementImpl setterVariable = setter.variable; |
| 1335 CompilationUnitElementImpl setterUnit = setterVariable.enclosingElement; | 1353 CompilationUnitElementImpl setterUnit = setterVariable.enclosingElement; |
| 1336 setterUnit.replaceTopLevelVariable(setterVariable, variable); | 1354 setterUnit.replaceTopLevelVariable(setterVariable, variable); |
| 1337 variable.setter = setter; | 1355 variable.setter = setter; |
| 1338 (setter as PropertyAccessorElementImpl).variable = variable; | 1356 (setter as PropertyAccessorElementImpl).variable = variable; |
| 1339 } | 1357 } |
| 1340 } | 1358 } |
| 1341 } | 1359 } |
| 1342 | 1360 |
| 1343 /** | 1361 /** |
| 1362 * If the given [node] has a documentation comment, remember its range |
| 1363 * into the given [element]. |
| 1364 */ |
| 1365 void _setDocRange(ElementImpl element, AnnotatedNode node) { |
| 1366 Comment comment = node.documentationComment; |
| 1367 if (comment != null && comment.isDocumentation) { |
| 1368 element.setDocRange(comment.offset, comment.length); |
| 1369 } |
| 1370 } |
| 1371 |
| 1372 /** |
| 1344 * Return a map from the names of the inputs of this kind of task to the task | 1373 * Return a map from the names of the inputs of this kind of task to the task |
| 1345 * input descriptors describing those inputs for a task with the given | 1374 * input descriptors describing those inputs for a task with the given |
| 1346 * [libSource]. | 1375 * [libSource]. |
| 1347 */ | 1376 */ |
| 1348 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 1377 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 1349 Source source = target; | 1378 Source source = target; |
| 1350 return <String, TaskInput>{ | 1379 return <String, TaskInput>{ |
| 1351 DEFINING_UNIT_INPUT: | 1380 DEFINING_UNIT_INPUT: |
| 1352 RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, source)), | 1381 RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, source)), |
| 1353 PARTS_UNIT_INPUT: INCLUDED_PARTS.of(source).toList((Source unit) { | 1382 PARTS_UNIT_INPUT: INCLUDED_PARTS.of(source).toList((Source unit) { |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2118 | 2147 |
| 2119 // | 2148 // |
| 2120 // Gather error filters. | 2149 // Gather error filters. |
| 2121 // | 2150 // |
| 2122 List<ErrorFilter> filters = | 2151 List<ErrorFilter> filters = |
| 2123 context.getConfigurationData(CONFIGURED_ERROR_FILTERS); | 2152 context.getConfigurationData(CONFIGURED_ERROR_FILTERS); |
| 2124 for (ResultDescriptor result in enginePlugin.dartErrorsForUnit) { | 2153 for (ResultDescriptor result in enginePlugin.dartErrorsForUnit) { |
| 2125 String inputName = result.name + '_input'; | 2154 String inputName = result.name + '_input'; |
| 2126 Map<Source, List<AnalysisError>> errorMap = getRequiredInput(inputName); | 2155 Map<Source, List<AnalysisError>> errorMap = getRequiredInput(inputName); |
| 2127 for (List<AnalysisError> errors in errorMap.values) { | 2156 for (List<AnalysisError> errors in errorMap.values) { |
| 2128 errorLists.add(errors | 2157 errorLists.add(errors.where((AnalysisError error) { |
| 2129 .where((AnalysisError error) { | 2158 return !filters.any((ErrorFilter filter) => filter(error)); |
| 2130 return !filters.any((ErrorFilter filter) => filter(error)); | 2159 }).toList()); |
| 2131 }) | |
| 2132 .toList()); | |
| 2133 } | 2160 } |
| 2134 } | 2161 } |
| 2135 // | 2162 // |
| 2136 // Record outputs. | 2163 // Record outputs. |
| 2137 // | 2164 // |
| 2138 outputs[DART_ERRORS] = AnalysisError.mergeLists(errorLists); | 2165 outputs[DART_ERRORS] = AnalysisError.mergeLists(errorLists); |
| 2139 } | 2166 } |
| 2140 | 2167 |
| 2141 /** | 2168 /** |
| 2142 * Return a map from the names of the inputs of this kind of task to the task | 2169 * Return a map from the names of the inputs of this kind of task to the task |
| (...skipping 2613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4756 | 4783 |
| 4757 @override | 4784 @override |
| 4758 bool moveNext() { | 4785 bool moveNext() { |
| 4759 if (_newSources.isEmpty) { | 4786 if (_newSources.isEmpty) { |
| 4760 return false; | 4787 return false; |
| 4761 } | 4788 } |
| 4762 currentTarget = _newSources.removeLast(); | 4789 currentTarget = _newSources.removeLast(); |
| 4763 return true; | 4790 return true; |
| 4764 } | 4791 } |
| 4765 } | 4792 } |
| OLD | NEW |