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.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'; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 11 import 'package:analyzer/src/generated/source.dart'; |
| 12 import 'package:analyzer/src/task/dart.dart'; | 12 import 'package:analyzer/src/task/dart.dart'; |
| 13 import 'package:analyzer/src/task/general.dart'; | 13 import 'package:analyzer/src/task/general.dart'; |
| 14 import 'package:analyzer/task/dart.dart'; | 14 import 'package:analyzer/task/dart.dart'; |
| 15 import 'package:analyzer/task/general.dart'; | 15 import 'package:analyzer/task/general.dart'; |
| 16 import 'package:analyzer/task/html.dart'; | 16 import 'package:analyzer/task/html.dart'; |
| 17 import 'package:analyzer/task/model.dart'; | 17 import 'package:analyzer/task/model.dart'; |
| 18 import 'package:html/dom.dart'; | 18 import 'package:html/dom.dart'; |
| 19 import 'package:html/parser.dart'; | 19 import 'package:html/parser.dart'; |
| 20 import 'package:source_span/source_span.dart'; | 20 import 'package:source_span/source_span.dart'; |
| 21 import 'package:analyzer/src/context/cache.dart'; | 21 import 'package:analyzer/src/context/cache.dart'; |
| 22 import 'package:analyzer/src/generated/java_engine.dart'; | 22 import 'package:analyzer/src/generated/java_engine.dart'; |
| 23 import 'package:analyzer/src/generated/scanner.dart'; | 23 import 'package:analyzer/src/generated/scanner.dart'; |
| 24 import 'package:analyzer/src/plugin/engine_plugin.dart'; | |
| 24 | 25 |
| 25 /** | 26 /** |
| 26 * The Dart scripts that are embedded in an HTML file. | 27 * The Dart scripts that are embedded in an HTML file. |
| 27 */ | 28 */ |
| 28 final ListResultDescriptor<DartScript> DART_SCRIPTS = | 29 final ListResultDescriptor<DartScript> DART_SCRIPTS = |
| 29 new ListResultDescriptor<DartScript>('DART_SCRIPTS', DartScript.EMPTY_LIST); | 30 new ListResultDescriptor<DartScript>('DART_SCRIPTS', DartScript.EMPTY_LIST); |
| 30 | 31 |
| 31 /** | 32 /** |
| 32 * The errors found while parsing an HTML file. | 33 * The errors found while parsing an HTML file. |
| 33 */ | 34 */ |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 * of errors. | 190 * of errors. |
| 190 */ | 191 */ |
| 191 class HtmlErrorsTask extends SourceBasedAnalysisTask { | 192 class HtmlErrorsTask extends SourceBasedAnalysisTask { |
| 192 /** | 193 /** |
| 193 * The name of the input that is a list of errors from each of the embedded | 194 * The name of the input that is a list of errors from each of the embedded |
| 194 * Dart scripts. | 195 * Dart scripts. |
| 195 */ | 196 */ |
| 196 static const String DART_ERRORS_INPUT = 'DART_ERRORS'; | 197 static const String DART_ERRORS_INPUT = 'DART_ERRORS'; |
| 197 | 198 |
| 198 /** | 199 /** |
| 199 * The name of the [HTML_DOCUMENT_ERRORS] input. | |
| 200 */ | |
| 201 static const String DOCUMENT_ERRORS_INPUT = 'DOCUMENT_ERRORS'; | |
| 202 | |
| 203 /** | |
| 204 * The task descriptor describing this kind of task. | 200 * The task descriptor describing this kind of task. |
| 205 */ | 201 */ |
| 206 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('HtmlErrorsTask', | 202 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('HtmlErrorsTask', |
| 207 createTask, buildInputs, <ResultDescriptor>[HTML_ERRORS]); | 203 createTask, buildInputs, <ResultDescriptor>[HTML_ERRORS]); |
| 208 | 204 |
| 209 HtmlErrorsTask(InternalAnalysisContext context, AnalysisTarget target) | 205 HtmlErrorsTask(InternalAnalysisContext context, AnalysisTarget target) |
| 210 : super(context, target); | 206 : super(context, target); |
| 211 | 207 |
| 212 @override | 208 @override |
| 213 TaskDescriptor get descriptor => DESCRIPTOR; | 209 TaskDescriptor get descriptor => DESCRIPTOR; |
| 214 | 210 |
| 215 @override | 211 @override |
| 216 void internalPerform() { | 212 void internalPerform() { |
| 213 EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin; | |
| 217 // | 214 // |
| 218 // Prepare inputs. | 215 // Prepare inputs. |
| 219 // | 216 // |
| 220 List<List<AnalysisError>> dartErrors = getRequiredInput(DART_ERRORS_INPUT); | 217 List<List<AnalysisError>> dartErrors = getRequiredInput(DART_ERRORS_INPUT); |
| 221 List<AnalysisError> documentErrors = | 218 List<List<AnalysisError>> htmlErrors = <List<AnalysisError>>[]; |
| 222 getRequiredInput(DOCUMENT_ERRORS_INPUT); | 219 for (ResultDescriptor result in enginePlugin.htmlErrors) { |
| 220 String inputName = result.name + '_input'; | |
|
Brian Wilkerson
2015/09/14 18:55:35
'_input' should be a constant
| |
| 221 htmlErrors.add(getRequiredInput(inputName)); | |
| 222 } | |
| 223 // | 223 // |
| 224 // Compute the error list. | 224 // Compute the error list. |
| 225 // | 225 // |
| 226 List<AnalysisError> errors = <AnalysisError>[]; | 226 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; |
| 227 errors.addAll(documentErrors); | 227 errorLists.addAll(dartErrors); |
| 228 for (List<AnalysisError> scriptErrors in dartErrors) { | 228 errorLists.addAll(htmlErrors); |
| 229 errors.addAll(scriptErrors); | |
| 230 } | |
| 231 // | 229 // |
| 232 // Record outputs. | 230 // Record outputs. |
| 233 // | 231 // |
| 234 outputs[HTML_ERRORS] = removeDuplicateErrors(errors); | 232 outputs[HTML_ERRORS] = AnalysisError.mergeLists(errorLists); |
| 235 } | 233 } |
| 236 | 234 |
| 237 /** | 235 /** |
| 238 * Return a map from the names of the inputs of this kind of task to the task | 236 * Return a map from the names of the inputs of this kind of task to the task |
| 239 * input descriptors describing those inputs for a task with the | 237 * input descriptors describing those inputs for a task with the |
| 240 * given [target]. | 238 * given [target]. |
| 241 */ | 239 */ |
| 242 static Map<String, TaskInput> buildInputs(Source target) { | 240 static Map<String, TaskInput> buildInputs(Source target) { |
| 243 return <String, TaskInput>{ | 241 EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin; |
| 244 DOCUMENT_ERRORS_INPUT: HTML_DOCUMENT_ERRORS.of(target), | 242 Map<String, TaskInput> inputs = <String, TaskInput>{ |
| 245 DART_ERRORS_INPUT: DART_SCRIPTS.of(target).toListOf(DART_ERRORS) | 243 DART_ERRORS_INPUT: DART_SCRIPTS.of(target).toListOf(DART_ERRORS) |
| 246 }; | 244 }; |
| 245 for (ResultDescriptor result in enginePlugin.htmlErrors) { | |
| 246 String inputName = result.name + '_input'; | |
| 247 inputs[inputName] = result.of(target); | |
| 248 } | |
| 249 return inputs; | |
| 247 } | 250 } |
| 248 | 251 |
| 249 /** | 252 /** |
| 250 * Create an [HtmlErrorsTask] based on the given [target] in the given | 253 * Create an [HtmlErrorsTask] based on the given [target] in the given |
| 251 * [context]. | 254 * [context]. |
| 252 */ | 255 */ |
| 253 static HtmlErrorsTask createTask( | 256 static HtmlErrorsTask createTask( |
| 254 AnalysisContext context, AnalysisTarget target) { | 257 AnalysisContext context, AnalysisTarget target) { |
| 255 return new HtmlErrorsTask(context, target); | 258 return new HtmlErrorsTask(context, target); |
| 256 } | 259 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 * The content of the fragment. | 367 * The content of the fragment. |
| 365 */ | 368 */ |
| 366 final String content; | 369 final String content; |
| 367 | 370 |
| 368 /** | 371 /** |
| 369 * Initialize a newly created script fragment to have the given [offset] and | 372 * Initialize a newly created script fragment to have the given [offset] and |
| 370 * [content]. | 373 * [content]. |
| 371 */ | 374 */ |
| 372 ScriptFragment(this.offset, this.line, this.column, this.content); | 375 ScriptFragment(this.offset, this.line, this.column, this.content); |
| 373 } | 376 } |
| OLD | NEW |