Index: packages/analyzer/lib/src/task/html.dart |
diff --git a/analyzer/lib/src/task/html.dart b/packages/analyzer/lib/src/task/html.dart |
similarity index 82% |
rename from analyzer/lib/src/task/html.dart |
rename to packages/analyzer/lib/src/task/html.dart |
index 0722ed4288a8c845cd874b535a91a83a8f8d3012..0ab546a9c56b0653417ba65cb0f6456378d1b628 100644 |
--- a/analyzer/lib/src/task/html.dart |
+++ b/packages/analyzer/lib/src/task/html.dart |
@@ -6,10 +6,13 @@ library analyzer.src.task.html; |
import 'dart:collection'; |
+import 'package:analyzer/src/context/cache.dart'; |
import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; |
import 'package:analyzer/src/generated/error.dart'; |
+import 'package:analyzer/src/generated/java_engine.dart'; |
+import 'package:analyzer/src/generated/scanner.dart'; |
import 'package:analyzer/src/generated/source.dart'; |
-import 'package:analyzer/src/task/dart.dart'; |
+import 'package:analyzer/src/plugin/engine_plugin.dart'; |
import 'package:analyzer/src/task/general.dart'; |
import 'package:analyzer/task/dart.dart'; |
import 'package:analyzer/task/general.dart'; |
@@ -18,9 +21,6 @@ import 'package:analyzer/task/model.dart'; |
import 'package:html/dom.dart'; |
import 'package:html/parser.dart'; |
import 'package:source_span/source_span.dart'; |
-import 'package:analyzer/src/context/cache.dart'; |
-import 'package:analyzer/src/generated/java_engine.dart'; |
-import 'package:analyzer/src/generated/scanner.dart'; |
/** |
* The Dart scripts that are embedded in an HTML file. |
@@ -107,11 +107,11 @@ class DartScriptsTask extends SourceBasedAnalysisTask { |
/** |
* The task descriptor describing this kind of task. |
*/ |
- static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('DartScriptsTask', |
- createTask, buildInputs, <ResultDescriptor>[ |
- DART_SCRIPTS, |
- REFERENCED_LIBRARIES |
- ]); |
+ static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
+ 'DartScriptsTask', |
+ createTask, |
+ buildInputs, |
+ <ResultDescriptor>[DART_SCRIPTS, REFERENCED_LIBRARIES]); |
DartScriptsTask(InternalAnalysisContext context, AnalysisTarget target) |
: super(context, target); |
@@ -190,15 +190,15 @@ class DartScriptsTask extends SourceBasedAnalysisTask { |
*/ |
class HtmlErrorsTask extends SourceBasedAnalysisTask { |
/** |
- * The name of the input that is a list of errors from each of the embedded |
- * Dart scripts. |
+ * The suffix to add to the names of contributed error results. |
*/ |
- static const String DART_ERRORS_INPUT = 'DART_ERRORS'; |
+ static const String INPUT_SUFFIX = '_input'; |
/** |
- * The name of the [HTML_DOCUMENT_ERRORS] input. |
+ * The name of the input that is a list of errors from each of the embedded |
+ * Dart scripts. |
*/ |
- static const String DOCUMENT_ERRORS_INPUT = 'DOCUMENT_ERRORS'; |
+ static const String DART_ERRORS_INPUT = 'DART_ERRORS'; |
/** |
* The task descriptor describing this kind of task. |
@@ -214,24 +214,26 @@ class HtmlErrorsTask extends SourceBasedAnalysisTask { |
@override |
void internalPerform() { |
+ EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin; |
// |
// Prepare inputs. |
// |
List<List<AnalysisError>> dartErrors = getRequiredInput(DART_ERRORS_INPUT); |
- List<AnalysisError> documentErrors = |
- getRequiredInput(DOCUMENT_ERRORS_INPUT); |
+ List<List<AnalysisError>> htmlErrors = <List<AnalysisError>>[]; |
+ for (ResultDescriptor result in enginePlugin.htmlErrors) { |
+ String inputName = result.name + INPUT_SUFFIX; |
+ htmlErrors.add(getRequiredInput(inputName)); |
+ } |
// |
// Compute the error list. |
// |
- List<AnalysisError> errors = <AnalysisError>[]; |
- errors.addAll(documentErrors); |
- for (List<AnalysisError> scriptErrors in dartErrors) { |
- errors.addAll(scriptErrors); |
- } |
+ List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; |
+ errorLists.addAll(dartErrors); |
+ errorLists.addAll(htmlErrors); |
// |
// Record outputs. |
// |
- outputs[HTML_ERRORS] = removeDuplicateErrors(errors); |
+ outputs[HTML_ERRORS] = AnalysisError.mergeLists(errorLists); |
} |
/** |
@@ -240,10 +242,15 @@ class HtmlErrorsTask extends SourceBasedAnalysisTask { |
* given [target]. |
*/ |
static Map<String, TaskInput> buildInputs(Source target) { |
- return <String, TaskInput>{ |
- DOCUMENT_ERRORS_INPUT: HTML_DOCUMENT_ERRORS.of(target), |
+ EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin; |
+ Map<String, TaskInput> inputs = <String, TaskInput>{ |
DART_ERRORS_INPUT: DART_SCRIPTS.of(target).toListOf(DART_ERRORS) |
}; |
+ for (ResultDescriptor result in enginePlugin.htmlErrors) { |
+ String inputName = result.name + INPUT_SUFFIX; |
+ inputs[inputName] = result.of(target); |
+ } |
+ return inputs; |
} |
/** |
@@ -268,11 +275,11 @@ class ParseHtmlTask extends SourceBasedAnalysisTask { |
/** |
* The task descriptor describing this kind of task. |
*/ |
- static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('ParseHtmlTask', |
- createTask, buildInputs, <ResultDescriptor>[ |
- HTML_DOCUMENT, |
- HTML_DOCUMENT_ERRORS |
- ]); |
+ static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
+ 'ParseHtmlTask', |
+ createTask, |
+ buildInputs, |
+ <ResultDescriptor>[HTML_DOCUMENT, HTML_DOCUMENT_ERRORS, LINE_INFO]); |
/** |
* Initialize a newly created task to access the content of the source |
@@ -291,7 +298,8 @@ class ParseHtmlTask extends SourceBasedAnalysisTask { |
if (context.getModificationStamp(target.source) < 0) { |
String message = 'Content could not be read'; |
if (context is InternalAnalysisContext) { |
- CacheEntry entry = (context as InternalAnalysisContext).getCacheEntry(target); |
+ CacheEntry entry = |
+ (context as InternalAnalysisContext).getCacheEntry(target); |
CaughtException exception = entry.exception; |
if (exception != null) { |
message = exception.toString(); |
@@ -299,12 +307,18 @@ class ParseHtmlTask extends SourceBasedAnalysisTask { |
} |
outputs[HTML_DOCUMENT] = new Document(); |
- outputs[HTML_DOCUMENT_ERRORS] = <AnalysisError>[new AnalysisError( |
- target.source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [message])]; |
+ outputs[HTML_DOCUMENT_ERRORS] = <AnalysisError>[ |
+ new AnalysisError( |
+ target.source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [message]) |
+ ]; |
+ outputs[LINE_INFO] = new LineInfo(<int>[0]); |
} else { |
HtmlParser parser = new HtmlParser(content, generateSpans: true); |
parser.compatMode = 'quirks'; |
Document document = parser.parse(); |
+ // |
+ // Convert errors. |
+ // |
List<ParseError> parseErrors = parser.errors; |
List<AnalysisError> errors = <AnalysisError>[]; |
for (ParseError parseError in parseErrors) { |
@@ -312,9 +326,12 @@ class ParseHtmlTask extends SourceBasedAnalysisTask { |
errors.add(new AnalysisError(target.source, span.start.offset, |
span.length, HtmlErrorCode.PARSE_ERROR, [parseError.message])); |
} |
- |
+ // |
+ // Record outputs. |
+ // |
outputs[HTML_DOCUMENT] = document; |
outputs[HTML_DOCUMENT_ERRORS] = errors; |
+ outputs[LINE_INFO] = _computeLineInfo(content); |
} |
} |
@@ -334,6 +351,19 @@ class ParseHtmlTask extends SourceBasedAnalysisTask { |
AnalysisContext context, AnalysisTarget target) { |
return new ParseHtmlTask(context, target); |
} |
+ |
+ /** |
+ * Compute [LineInfo] for the given [content]. |
+ */ |
+ static LineInfo _computeLineInfo(String content) { |
+ List<int> lineStarts = <int>[0]; |
+ for (int index = 0; index < content.length; index++) { |
+ if (content.codeUnitAt(index) == 0x0A) { |
+ lineStarts.add(index + 1); |
+ } |
+ } |
+ return new LineInfo(lineStarts); |
+ } |
} |
/** |