Chromium Code Reviews| 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'; |
| 11 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; | 12 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; |
| 13 import 'package:analyzer/src/generated/error.dart'; | 13 import 'package:analyzer/src/generated/error.dart'; |
| 14 import 'package:analyzer/src/generated/error_verifier.dart'; | |
| 14 import 'package:analyzer/src/generated/java_engine.dart'; | 15 import 'package:analyzer/src/generated/java_engine.dart'; |
| 15 import 'package:analyzer/src/generated/parser.dart'; | 16 import 'package:analyzer/src/generated/parser.dart'; |
| 16 import 'package:analyzer/src/generated/resolver.dart'; | 17 import 'package:analyzer/src/generated/resolver.dart'; |
| 17 import 'package:analyzer/src/generated/scanner.dart'; | 18 import 'package:analyzer/src/generated/scanner.dart'; |
| 18 import 'package:analyzer/src/generated/sdk.dart'; | 19 import 'package:analyzer/src/generated/sdk.dart'; |
| 19 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 20 import 'package:analyzer/src/generated/utilities_general.dart'; | 21 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 21 import 'package:analyzer/src/task/driver.dart'; | 22 import 'package:analyzer/src/task/driver.dart'; |
| 22 import 'package:analyzer/src/task/general.dart'; | 23 import 'package:analyzer/src/task/general.dart'; |
| 23 import 'package:analyzer/task/dart.dart'; | 24 import 'package:analyzer/task/dart.dart'; |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 new ResultDescriptor<List<AnalysisError>>( | 263 new ResultDescriptor<List<AnalysisError>>( |
| 263 'SCAN_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); | 264 'SCAN_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); |
| 264 | 265 |
| 265 /** | 266 /** |
| 266 * The [TypeProvider] of the context. | 267 * The [TypeProvider] of the context. |
| 267 */ | 268 */ |
| 268 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = | 269 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = |
| 269 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); | 270 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); |
| 270 | 271 |
| 271 /** | 272 /** |
| 273 * The errors produced while verifying a compilation unit. | |
| 274 * | |
| 275 * The list will be empty if there were no errors, but will not be `null`. | |
| 276 * | |
| 277 * The result is only available for targets representing a Dart compilation unit . | |
| 278 */ | |
| 279 final ResultDescriptor<List<AnalysisError>> VERIFY_ERRORS = | |
| 280 new ResultDescriptor<List<AnalysisError>>( | |
| 281 'VERIFY_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); | |
| 282 | |
| 283 /** | |
| 272 * A task that builds implicit constructors for a [ClassElement], or keeps | 284 * A task that builds implicit constructors for a [ClassElement], or keeps |
| 273 * the existing explicit constructors if the class has them. | 285 * the existing explicit constructors if the class has them. |
| 274 */ | 286 */ |
| 275 class BuildClassConstructorsTask extends SourceBasedAnalysisTask { | 287 class BuildClassConstructorsTask extends SourceBasedAnalysisTask { |
| 276 /** | 288 /** |
| 277 * The name of the [CONSTRUCTORS] input for the superclass. | 289 * The name of the [CONSTRUCTORS] input for the superclass. |
| 278 */ | 290 */ |
| 279 static const String SUPER_CONSTRUCTORS = 'SUPER_CONSTRUCTORS'; | 291 static const String SUPER_CONSTRUCTORS = 'SUPER_CONSTRUCTORS'; |
| 280 | 292 |
| 281 /** | 293 /** |
| (...skipping 1908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2190 } | 2202 } |
| 2191 | 2203 |
| 2192 /** | 2204 /** |
| 2193 * Create a [ScanDartTask] based on the given [target] in the given [context]. | 2205 * Create a [ScanDartTask] based on the given [target] in the given [context]. |
| 2194 */ | 2206 */ |
| 2195 static ScanDartTask createTask( | 2207 static ScanDartTask createTask( |
| 2196 AnalysisContext context, AnalysisTarget target) { | 2208 AnalysisContext context, AnalysisTarget target) { |
| 2197 return new ScanDartTask(context, target); | 2209 return new ScanDartTask(context, target); |
| 2198 } | 2210 } |
| 2199 } | 2211 } |
| 2212 | |
| 2213 /** | |
| 2214 * A task that builds [VERIFY_ERRORS] for a unit. | |
| 2215 */ | |
| 2216 class VerifyUnitTask extends SourceBasedAnalysisTask { | |
| 2217 /** | |
| 2218 * The name of the [RESOLVED_UNIT] input. | |
| 2219 */ | |
| 2220 static const String UNIT_INPUT = 'UNIT_INPUT'; | |
| 2221 | |
| 2222 /** | |
| 2223 * The task descriptor describing this kind of task. | |
| 2224 */ | |
| 2225 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('VerifyUnitTask', | |
| 2226 createTask, buildInputs, <ResultDescriptor>[VERIFY_ERRORS]); | |
| 2227 | |
| 2228 /** | |
| 2229 * The [ErrorReporter] to report errors to. | |
| 2230 */ | |
| 2231 ErrorReporter errorReporter; | |
| 2232 | |
| 2233 VerifyUnitTask(InternalAnalysisContext context, AnalysisTarget target) | |
| 2234 : super(context, target); | |
| 2235 | |
| 2236 @override | |
| 2237 TaskDescriptor get descriptor => DESCRIPTOR; | |
| 2238 | |
| 2239 @override | |
| 2240 void internalPerform() { | |
| 2241 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
| 2242 Source source = getRequiredSource(); | |
| 2243 errorReporter = new ErrorReporter(errorListener, source); | |
| 2244 TypeProvider typeProvider = context.typeProvider; | |
| 2245 // | |
| 2246 // Prepare inputs. TODO | |
|
Brian Wilkerson
2015/03/30 21:03:04
"TODO"?
| |
| 2247 // | |
| 2248 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | |
| 2249 CompilationUnitElement unitElement = unit.element; | |
| 2250 LibraryElement libraryElement = unitElement.library; | |
| 2251 // | |
| 2252 // Validate the directives | |
| 2253 // | |
| 2254 _validateDirectives(unit); | |
| 2255 // | |
| 2256 // Use the ErrorVerifier to compute the rest of the errors. | |
| 2257 // | |
| 2258 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, | |
| 2259 libraryElement, typeProvider, new InheritanceManager(libraryElement)); | |
| 2260 unit.accept(errorVerifier); | |
| 2261 // | |
| 2262 // Record outputs. | |
| 2263 // | |
| 2264 outputs[VERIFY_ERRORS] = errorListener.errors; | |
| 2265 } | |
| 2266 | |
| 2267 /** | |
| 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 | |
| 2302 * input descriptors describing those inputs for a task with the | |
| 2303 * given [target]. | |
| 2304 */ | |
| 2305 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { | |
| 2306 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT.of(target)}; | |
| 2307 } | |
| 2308 | |
| 2309 /** | |
| 2310 * Create a [VerifyUnitTask] based on the given [target] in | |
| 2311 * the given [context]. | |
| 2312 */ | |
| 2313 static VerifyUnitTask createTask( | |
| 2314 AnalysisContext context, AnalysisTarget target) { | |
| 2315 return new VerifyUnitTask(context, target); | |
| 2316 } | |
| 2317 } | |
| OLD | NEW |