| 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.html; | 5 library analyzer.src.task.html; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; | 9 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; |
| 10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 */ | 100 */ |
| 101 class DartScriptsTask extends SourceBasedAnalysisTask { | 101 class DartScriptsTask extends SourceBasedAnalysisTask { |
| 102 /** | 102 /** |
| 103 * The name of the [HTML_DOCUMENT] input. | 103 * The name of the [HTML_DOCUMENT] input. |
| 104 */ | 104 */ |
| 105 static const String DOCUMENT_INPUT = 'DOCUMENT'; | 105 static const String DOCUMENT_INPUT = 'DOCUMENT'; |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * The task descriptor describing this kind of task. | 108 * The task descriptor describing this kind of task. |
| 109 */ | 109 */ |
| 110 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('DartScriptsTask', | 110 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 111 createTask, buildInputs, <ResultDescriptor>[ | 111 'DartScriptsTask', |
| 112 DART_SCRIPTS, | 112 createTask, |
| 113 REFERENCED_LIBRARIES | 113 buildInputs, |
| 114 ]); | 114 <ResultDescriptor>[DART_SCRIPTS, REFERENCED_LIBRARIES]); |
| 115 | 115 |
| 116 DartScriptsTask(InternalAnalysisContext context, AnalysisTarget target) | 116 DartScriptsTask(InternalAnalysisContext context, AnalysisTarget target) |
| 117 : super(context, target); | 117 : super(context, target); |
| 118 | 118 |
| 119 @override | 119 @override |
| 120 TaskDescriptor get descriptor => DESCRIPTOR; | 120 TaskDescriptor get descriptor => DESCRIPTOR; |
| 121 | 121 |
| 122 @override | 122 @override |
| 123 void internalPerform() { | 123 void internalPerform() { |
| 124 // | 124 // |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 */ | 261 */ |
| 262 class ParseHtmlTask extends SourceBasedAnalysisTask { | 262 class ParseHtmlTask extends SourceBasedAnalysisTask { |
| 263 /** | 263 /** |
| 264 * The name of the input whose value is the content of the file. | 264 * The name of the input whose value is the content of the file. |
| 265 */ | 265 */ |
| 266 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; | 266 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; |
| 267 | 267 |
| 268 /** | 268 /** |
| 269 * The task descriptor describing this kind of task. | 269 * The task descriptor describing this kind of task. |
| 270 */ | 270 */ |
| 271 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('ParseHtmlTask', | 271 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 272 createTask, buildInputs, <ResultDescriptor>[ | 272 'ParseHtmlTask', |
| 273 HTML_DOCUMENT, | 273 createTask, |
| 274 HTML_DOCUMENT_ERRORS | 274 buildInputs, |
| 275 ]); | 275 <ResultDescriptor>[HTML_DOCUMENT, HTML_DOCUMENT_ERRORS]); |
| 276 | 276 |
| 277 /** | 277 /** |
| 278 * Initialize a newly created task to access the content of the source | 278 * Initialize a newly created task to access the content of the source |
| 279 * associated with the given [target] in the given [context]. | 279 * associated with the given [target] in the given [context]. |
| 280 */ | 280 */ |
| 281 ParseHtmlTask(InternalAnalysisContext context, AnalysisTarget target) | 281 ParseHtmlTask(InternalAnalysisContext context, AnalysisTarget target) |
| 282 : super(context, target); | 282 : super(context, target); |
| 283 | 283 |
| 284 @override | 284 @override |
| 285 TaskDescriptor get descriptor => DESCRIPTOR; | 285 TaskDescriptor get descriptor => DESCRIPTOR; |
| 286 | 286 |
| 287 @override | 287 @override |
| 288 void internalPerform() { | 288 void internalPerform() { |
| 289 String content = getRequiredInput(CONTENT_INPUT_NAME); | 289 String content = getRequiredInput(CONTENT_INPUT_NAME); |
| 290 | 290 |
| 291 if (context.getModificationStamp(target.source) < 0) { | 291 if (context.getModificationStamp(target.source) < 0) { |
| 292 String message = 'Content could not be read'; | 292 String message = 'Content could not be read'; |
| 293 if (context is InternalAnalysisContext) { | 293 if (context is InternalAnalysisContext) { |
| 294 CacheEntry entry = (context as InternalAnalysisContext).getCacheEntry(ta
rget); | 294 CacheEntry entry = |
| 295 (context as InternalAnalysisContext).getCacheEntry(target); |
| 295 CaughtException exception = entry.exception; | 296 CaughtException exception = entry.exception; |
| 296 if (exception != null) { | 297 if (exception != null) { |
| 297 message = exception.toString(); | 298 message = exception.toString(); |
| 298 } | 299 } |
| 299 } | 300 } |
| 300 | 301 |
| 301 outputs[HTML_DOCUMENT] = new Document(); | 302 outputs[HTML_DOCUMENT] = new Document(); |
| 302 outputs[HTML_DOCUMENT_ERRORS] = <AnalysisError>[new AnalysisError( | 303 outputs[HTML_DOCUMENT_ERRORS] = <AnalysisError>[ |
| 303 target.source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [message])]; | 304 new AnalysisError( |
| 305 target.source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [message]) |
| 306 ]; |
| 304 } else { | 307 } else { |
| 305 HtmlParser parser = new HtmlParser(content, generateSpans: true); | 308 HtmlParser parser = new HtmlParser(content, generateSpans: true); |
| 306 parser.compatMode = 'quirks'; | 309 parser.compatMode = 'quirks'; |
| 307 Document document = parser.parse(); | 310 Document document = parser.parse(); |
| 308 List<ParseError> parseErrors = parser.errors; | 311 List<ParseError> parseErrors = parser.errors; |
| 309 List<AnalysisError> errors = <AnalysisError>[]; | 312 List<AnalysisError> errors = <AnalysisError>[]; |
| 310 for (ParseError parseError in parseErrors) { | 313 for (ParseError parseError in parseErrors) { |
| 311 SourceSpan span = parseError.span; | 314 SourceSpan span = parseError.span; |
| 312 errors.add(new AnalysisError(target.source, span.start.offset, | 315 errors.add(new AnalysisError(target.source, span.start.offset, |
| 313 span.length, HtmlErrorCode.PARSE_ERROR, [parseError.message])); | 316 span.length, HtmlErrorCode.PARSE_ERROR, [parseError.message])); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 * The content of the fragment. | 364 * The content of the fragment. |
| 362 */ | 365 */ |
| 363 final String content; | 366 final String content; |
| 364 | 367 |
| 365 /** | 368 /** |
| 366 * Initialize a newly created script fragment to have the given [offset] and | 369 * Initialize a newly created script fragment to have the given [offset] and |
| 367 * [content]. | 370 * [content]. |
| 368 */ | 371 */ |
| 369 ScriptFragment(this.offset, this.line, this.column, this.content); | 372 ScriptFragment(this.offset, this.line, this.column, this.content); |
| 370 } | 373 } |
| OLD | NEW |