| 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 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 2225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2236 @override | 2236 @override |
| 2237 TaskDescriptor get descriptor => DESCRIPTOR; | 2237 TaskDescriptor get descriptor => DESCRIPTOR; |
| 2238 | 2238 |
| 2239 @override | 2239 @override |
| 2240 void internalPerform() { | 2240 void internalPerform() { |
| 2241 RecordingErrorListener errorListener = new RecordingErrorListener(); | 2241 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 2242 Source source = getRequiredSource(); | 2242 Source source = getRequiredSource(); |
| 2243 errorReporter = new ErrorReporter(errorListener, source); | 2243 errorReporter = new ErrorReporter(errorListener, source); |
| 2244 TypeProvider typeProvider = context.typeProvider; | 2244 TypeProvider typeProvider = context.typeProvider; |
| 2245 // | 2245 // |
| 2246 // Prepare inputs. TODO | 2246 // Prepare inputs. |
| 2247 // | 2247 // |
| 2248 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | 2248 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
| 2249 CompilationUnitElement unitElement = unit.element; | 2249 CompilationUnitElement unitElement = unit.element; |
| 2250 LibraryElement libraryElement = unitElement.library; | 2250 LibraryElement libraryElement = unitElement.library; |
| 2251 // | 2251 // |
| 2252 // Validate the directives | 2252 // Use the ErrorVerifier to compute errors. |
| 2253 // | |
| 2254 _validateDirectives(unit); | |
| 2255 // | |
| 2256 // Use the ErrorVerifier to compute the rest of the errors. | |
| 2257 // | 2253 // |
| 2258 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, | 2254 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, |
| 2259 libraryElement, typeProvider, new InheritanceManager(libraryElement)); | 2255 libraryElement, typeProvider, new InheritanceManager(libraryElement)); |
| 2260 unit.accept(errorVerifier); | 2256 unit.accept(errorVerifier); |
| 2261 // | 2257 // |
| 2262 // Record outputs. | 2258 // Record outputs. |
| 2263 // | 2259 // |
| 2264 outputs[VERIFY_ERRORS] = errorListener.errors; | 2260 outputs[VERIFY_ERRORS] = errorListener.errors; |
| 2265 } | 2261 } |
| 2266 | 2262 |
| 2267 /** | 2263 /** |
| 2268 * Check each directive in the given [unit] to see if the referenced source | |
| 2269 * exists and report an error if it does not. | |
| 2270 */ | |
| 2271 void _validateDirectives(CompilationUnit unit) { | |
| 2272 for (Directive directive in unit.directives) { | |
| 2273 if (directive is UriBasedDirective) { | |
| 2274 _validateReferencedSource(directive); | |
| 2275 } | |
| 2276 } | |
| 2277 } | |
| 2278 | |
| 2279 /** | |
| 2280 * Check the given [directive] to see if the referenced source exists and | |
| 2281 * report an error if it does not. | |
| 2282 */ | |
| 2283 void _validateReferencedSource(UriBasedDirective directive) { | |
| 2284 Source source = directive.source; | |
| 2285 if (source != null) { | |
| 2286 if (context.exists(source)) { | |
| 2287 return; | |
| 2288 } | |
| 2289 } else { | |
| 2290 // Don't report errors already reported by ParseDartTask.resolveDirective | |
| 2291 if (directive.validate() != null) { | |
| 2292 return; | |
| 2293 } | |
| 2294 } | |
| 2295 StringLiteral uriLiteral = directive.uri; | |
| 2296 errorReporter.reportErrorForNode(CompileTimeErrorCode.URI_DOES_NOT_EXIST, | |
| 2297 uriLiteral, [directive.uriContent]); | |
| 2298 } | |
| 2299 | |
| 2300 /** | |
| 2301 * Return a map from the names of the inputs of this kind of task to the task | 2264 * Return a map from the names of the inputs of this kind of task to the task |
| 2302 * input descriptors describing those inputs for a task with the | 2265 * input descriptors describing those inputs for a task with the |
| 2303 * given [target]. | 2266 * given [target]. |
| 2304 */ | 2267 */ |
| 2305 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { | 2268 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { |
| 2306 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT.of(target)}; | 2269 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT.of(target)}; |
| 2307 } | 2270 } |
| 2308 | 2271 |
| 2309 /** | 2272 /** |
| 2310 * Create a [VerifyUnitTask] based on the given [target] in | 2273 * Create a [VerifyUnitTask] based on the given [target] in |
| 2311 * the given [context]. | 2274 * the given [context]. |
| 2312 */ | 2275 */ |
| 2313 static VerifyUnitTask createTask( | 2276 static VerifyUnitTask createTask( |
| 2314 AnalysisContext context, AnalysisTarget target) { | 2277 AnalysisContext context, AnalysisTarget target) { |
| 2315 return new VerifyUnitTask(context, target); | 2278 return new VerifyUnitTask(context, target); |
| 2316 } | 2279 } |
| 2317 } | 2280 } |
| OLD | NEW |