| Index: packages/analyzer/lib/src/task/html.dart
|
| diff --git a/packages/analyzer/lib/src/task/html.dart b/packages/analyzer/lib/src/task/html.dart
|
| index 1804c50f7d3f7a8f3e9738c789321c736ff04807..81587b2f4e3aeaaf89fe48e2f2417142c39a8c5f 100644
|
| --- a/packages/analyzer/lib/src/task/html.dart
|
| +++ b/packages/analyzer/lib/src/task/html.dart
|
| @@ -6,11 +6,12 @@ library analyzer.src.task.html;
|
|
|
| import 'dart:collection';
|
|
|
| +import 'package:analyzer/error/error.dart';
|
| +import 'package:analyzer/exception/exception.dart';
|
| 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/dart/scanner/scanner.dart';
|
| +import 'package:analyzer/src/generated/engine.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/plugin/engine_plugin.dart';
|
| import 'package:analyzer/src/task/general.dart';
|
| @@ -73,6 +74,9 @@ class DartScript implements Source {
|
| @override
|
| bool get isInSystemLibrary => source.isInSystemLibrary;
|
|
|
| + @override
|
| + Source get librarySource => source;
|
| +
|
| @override
|
| int get modificationStamp => source.modificationStamp;
|
|
|
| @@ -80,7 +84,8 @@ class DartScript implements Source {
|
| String get shortName => source.shortName;
|
|
|
| @override
|
| - Uri get uri => throw new StateError('uri not supported for scripts');
|
| + Uri get uri => source.uri
|
| + .replace(queryParameters: {'offset': fragments[0].offset.toString()});
|
|
|
| @override
|
| UriKind get uriKind =>
|
| @@ -88,10 +93,6 @@ class DartScript implements Source {
|
|
|
| @override
|
| bool exists() => source.exists();
|
| -
|
| - @override
|
| - Uri resolveRelativeUri(Uri relativeUri) =>
|
| - throw new StateError('resolveRelativeUri not supported for scripts');
|
| }
|
|
|
| /**
|
| @@ -170,7 +171,7 @@ class DartScriptsTask extends SourceBasedAnalysisTask {
|
| * input descriptors describing those inputs for a task with the
|
| * given [target].
|
| */
|
| - static Map<String, TaskInput> buildInputs(Source target) {
|
| + static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
|
| return <String, TaskInput>{DOCUMENT_INPUT: HTML_DOCUMENT.of(target)};
|
| }
|
|
|
| @@ -241,7 +242,7 @@ class HtmlErrorsTask extends SourceBasedAnalysisTask {
|
| * input descriptors describing those inputs for a task with the
|
| * given [target].
|
| */
|
| - static Map<String, TaskInput> buildInputs(Source target) {
|
| + static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
|
| EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin;
|
| Map<String, TaskInput> inputs = <String, TaskInput>{
|
| DART_ERRORS_INPUT: DART_SCRIPTS.of(target).toListOf(DART_ERRORS)
|
| @@ -272,6 +273,11 @@ class ParseHtmlTask extends SourceBasedAnalysisTask {
|
| */
|
| static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME';
|
|
|
| + /**
|
| + * The name of the input whose value is the modification time of the file.
|
| + */
|
| + static const String MODIFICATION_TIME_INPUT = 'MODIFICATION_TIME_INPUT';
|
| +
|
| /**
|
| * The task descriptor describing this kind of task.
|
| */
|
| @@ -279,7 +285,8 @@ class ParseHtmlTask extends SourceBasedAnalysisTask {
|
| 'ParseHtmlTask',
|
| createTask,
|
| buildInputs,
|
| - <ResultDescriptor>[HTML_DOCUMENT, HTML_DOCUMENT_ERRORS, LINE_INFO]);
|
| + <ResultDescriptor>[HTML_DOCUMENT, HTML_DOCUMENT_ERRORS, LINE_INFO],
|
| + suitabilityFor: suitabilityFor);
|
|
|
| /**
|
| * Initialize a newly created task to access the content of the source
|
| @@ -295,7 +302,8 @@ class ParseHtmlTask extends SourceBasedAnalysisTask {
|
| void internalPerform() {
|
| String content = getRequiredInput(CONTENT_INPUT_NAME);
|
|
|
| - if (context.getModificationStamp(target.source) < 0) {
|
| + int modificationTime = getRequiredInput(MODIFICATION_TIME_INPUT);
|
| + if (modificationTime < 0) {
|
| String message = 'Content could not be read';
|
| if (context is InternalAnalysisContext) {
|
| CacheEntry entry =
|
| @@ -313,22 +321,24 @@ class ParseHtmlTask extends SourceBasedAnalysisTask {
|
| ];
|
| outputs[LINE_INFO] = new LineInfo(<int>[0]);
|
| } else {
|
| - HtmlParser parser = new HtmlParser(content, generateSpans: true);
|
| + HtmlParser parser = new HtmlParser(content,
|
| + generateSpans: true, lowercaseAttrName: false);
|
| parser.compatMode = 'quirks';
|
| Document document = parser.parse();
|
| //
|
| // Convert errors.
|
| //
|
| - List<ParseError> parseErrors = parser.errors;
|
| List<AnalysisError> errors = <AnalysisError>[];
|
| - for (ParseError parseError in parseErrors) {
|
| - if (parseError.errorCode == 'expected-doctype-but-got-start-tag') {
|
| - continue;
|
| - }
|
| - SourceSpan span = parseError.span;
|
| - errors.add(new AnalysisError(target.source, span.start.offset,
|
| - span.length, HtmlErrorCode.PARSE_ERROR, [parseError.message]));
|
| - }
|
| + // TODO(scheglov) https://github.com/dart-lang/sdk/issues/24643
|
| +// List<ParseError> parseErrors = parser.errors;
|
| +// for (ParseError parseError in parseErrors) {
|
| +// if (parseError.errorCode == 'expected-doctype-but-got-start-tag') {
|
| +// continue;
|
| +// }
|
| +// SourceSpan span = parseError.span;
|
| +// errors.add(new AnalysisError(target.source, span.start.offset,
|
| +// span.length, HtmlErrorCode.PARSE_ERROR, [parseError.message]));
|
| +// }
|
| //
|
| // Record outputs.
|
| //
|
| @@ -343,8 +353,11 @@ class ParseHtmlTask extends SourceBasedAnalysisTask {
|
| * input descriptors describing those inputs for a task with the given
|
| * [source].
|
| */
|
| - static Map<String, TaskInput> buildInputs(Source source) {
|
| - return <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)};
|
| + static Map<String, TaskInput> buildInputs(AnalysisTarget source) {
|
| + return <String, TaskInput>{
|
| + CONTENT_INPUT_NAME: CONTENT.of(source),
|
| + MODIFICATION_TIME_INPUT: MODIFICATION_TIME.of(source)
|
| + };
|
| }
|
|
|
| /**
|
| @@ -356,15 +369,24 @@ class ParseHtmlTask extends SourceBasedAnalysisTask {
|
| }
|
|
|
| /**
|
| - * Compute [LineInfo] for the given [content].
|
| + * Return an indication of how suitable this task is for the given [target].
|
| */
|
| - 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);
|
| + static TaskSuitability suitabilityFor(AnalysisTarget target) {
|
| + if (target is Source) {
|
| + String name = target.shortName;
|
| + if (name.endsWith(AnalysisEngine.SUFFIX_HTML) ||
|
| + name.endsWith(AnalysisEngine.SUFFIX_HTM)) {
|
| + return TaskSuitability.HIGHEST;
|
| }
|
| }
|
| + return TaskSuitability.NONE;
|
| + }
|
| +
|
| + /**
|
| + * Compute [LineInfo] for the given [content].
|
| + */
|
| + static LineInfo _computeLineInfo(String content) {
|
| + List<int> lineStarts = StringUtilities.computeLineStarts(content);
|
| return new LineInfo(lineStarts);
|
| }
|
| }
|
|
|