Remove crossdart support (#1856)
* Remove crossdart
* dartfmt
diff --git a/lib/resources/styles.css b/lib/resources/styles.css
index 8aea33d..94fbb83 100644
--- a/lib/resources/styles.css
+++ b/lib/resources/styles.css
@@ -257,22 +257,6 @@
border-radius: 3px;
}
-h2 .crossdart {
- float: right;
- font-size: 0.5em;
- margin-top: 1em;
-}
-
-.crossdart-link {
- border-bottom: 1px solid #dfdfdf;
- text-decoration: none;
-}
-
-.crossdart-link:hover {
- border-bottom: 1px solid #aaa;
- text-decoration: none;
-}
-
@media(max-width: 768px) {
nav .container {
width: 100%
diff --git a/lib/src/dartdoc_options.dart b/lib/src/dartdoc_options.dart
index 4f0d747..a199ff6 100644
--- a/lib/src/dartdoc_options.dart
+++ b/lib/src/dartdoc_options.dart
@@ -40,7 +40,6 @@
final String directoryCurrentPath =
pathLib.canonicalize(Directory.current.path);
-
class DartdocOptionError extends DartdocFailure {
DartdocOptionError(String details) : super(details);
}
@@ -1271,7 +1270,6 @@
}
// All values defined in createDartdocOptions should be exposed here.
- bool get addCrossdart => optionSet['addCrossdart'].valueAt(context);
bool get allowTools => optionSet['allowTools'].valueAt(context);
double get ambiguousReexportScorerMinConfidence =>
optionSet['ambiguousReexportScorerMinConfidence'].valueAt(context);
@@ -1331,9 +1329,6 @@
/// given command line arguments.
Future<List<DartdocOption>> createDartdocOptions() async {
return <DartdocOption>[
- new DartdocOptionArgOnly<bool>('addCrossdart', false,
- help: 'Add Crossdart links to the source code pieces.',
- negatable: true),
new DartdocOptionArgOnly<bool>('allowTools', true,
help: 'Execute user-defined tools to fill in @tool directives.',
negatable: true),
diff --git a/lib/src/model.dart b/lib/src/model.dart
index 2816a51..b7cb12d 100644
--- a/lib/src/model.dart
+++ b/lib/src/model.dart
@@ -15,7 +15,6 @@
AnnotatedNode,
AstNode,
CommentReference,
- Declaration,
Expression,
InstanceCreationExpression;
import 'package:analyzer/dart/element/element.dart';
@@ -3038,6 +3037,7 @@
}
AstNode _astNode;
+ @override
AstNode get astNode {
_astNode ??= element?.computeNode();
return _astNode;
@@ -3994,33 +3994,34 @@
});
int invocationIndex = 0;
return await _replaceAllMappedAsync(rawDocs, basicToolRegExp,
- (basicMatch) async {
- List<String> args = _splitUpQuotedArgs(basicMatch[1]).toList();
- // Tool name must come first.
- if (args.isEmpty) {
- warn(PackageWarning.toolError,
- message: 'Must specify a tool to execute for the @tool directive.');
- return Future.value('');
- }
- // Count the number of invocations of tools in this dartdoc block,
- // so that tools can differentiate different blocks from each other.
- invocationIndex++;
- return await runner.run(args,
- content: basicMatch[2],
- environment: {
- 'SOURCE_LINE': lineAndColumn?.item1?.toString(),
- 'SOURCE_COLUMN': lineAndColumn?.item2?.toString(),
- 'SOURCE_PATH': (sourceFileName == null ||
+ (basicMatch) async {
+ List<String> args = _splitUpQuotedArgs(basicMatch[1]).toList();
+ // Tool name must come first.
+ if (args.isEmpty) {
+ warn(PackageWarning.toolError,
+ message:
+ 'Must specify a tool to execute for the @tool directive.');
+ return Future.value('');
+ }
+ // Count the number of invocations of tools in this dartdoc block,
+ // so that tools can differentiate different blocks from each other.
+ invocationIndex++;
+ return await runner.run(args,
+ content: basicMatch[2],
+ environment: {
+ 'SOURCE_LINE': lineAndColumn?.item1?.toString(),
+ 'SOURCE_COLUMN': lineAndColumn?.item2?.toString(),
+ 'SOURCE_PATH': (sourceFileName == null ||
package?.packagePath == null)
- ? null
- : pathLib.relative(sourceFileName, from: package.packagePath),
- 'PACKAGE_PATH': package?.packagePath,
- 'PACKAGE_NAME': package?.name,
- 'LIBRARY_NAME': library?.fullyQualifiedName,
- 'ELEMENT_NAME': fullyQualifiedNameWithoutLibrary,
- 'INVOCATION_INDEX': invocationIndex.toString(),
- }..removeWhere((key, value) => value == null));
- }).whenComplete(runner.dispose);
+ ? null
+ : pathLib.relative(sourceFileName, from: package.packagePath),
+ 'PACKAGE_PATH': package?.packagePath,
+ 'PACKAGE_NAME': package?.name,
+ 'LIBRARY_NAME': library?.fullyQualifiedName,
+ 'ELEMENT_NAME': fullyQualifiedNameWithoutLibrary,
+ 'INVOCATION_INDEX': invocationIndex.toString(),
+ }..removeWhere((key, value) => value == null));
+ }).whenComplete(runner.dispose);
} else {
return rawDocs;
}
@@ -4730,27 +4731,6 @@
/// Dartdoc's configuration flags.
final DartdocOptionContext config;
- Map<String, Map<String, dynamic>> __crossdartJson;
- // TODO(jcollins-g): move to [Package]
- Map<String, Map<String, dynamic>> get crossdartJson {
- if (__crossdartJson == null) {
- // TODO(jcollins-g): allow crossdart.json location to be configurable
- var crossdartFile =
- new File(pathLib.join(config.inputDir, 'crossdart.json'));
- if (crossdartFile.existsSync()) {
- Map<String, dynamic> __crossdartJsonTmp =
- json.decode(crossdartFile.readAsStringSync());
- __crossdartJson = {};
- for (String key in __crossdartJsonTmp.keys) {
- __crossdartJson[pathLib.canonicalize(key)] = __crossdartJsonTmp[key];
- }
- } else {
- __crossdartJson = {};
- }
- }
- return __crossdartJson;
- }
-
Package _defaultPackage;
Package get defaultPackage {
if (_defaultPackage == null) {
@@ -6107,13 +6087,7 @@
}
abstract class SourceCodeMixin implements Documentable {
- String get crossdartHtmlTag {
- if (config.addCrossdart && _crossdartUrl != null) {
- return "<a class='crossdart' href='${_crossdartUrl}'>Link to Crossdart</a>";
- } else {
- return "";
- }
- }
+ AstNode get astNode;
Tuple2<int, int> get lineAndColumn;
@@ -6141,12 +6115,7 @@
var start = node.offset - (node.offset - i);
String source = contents.substring(start, node.end);
- if (config.addCrossdart) {
- source = crossdartifySource(config.inputDir, packageGraph.crossdartJson,
- source, element, start);
- } else {
- source = const HtmlEscape().convert(source);
- }
+ source = const HtmlEscape().convert(source);
source = stripIndentFromSource(source);
source = stripDartdocCommentsFromSource(source);
@@ -6163,54 +6132,6 @@
}
return _sourceCode;
}
-
- String get _crossdartPath {
- var node = element.computeNode();
- if (node is Declaration && node.declaredElement != null) {
- var source = node.declaredElement.source;
- var filePath = source.fullName;
- var uri = source.uri.toString();
- var packageMeta = library.packageGraph.packageMeta;
- if (uri.startsWith('package:')) {
- var splittedUri =
- uri.replaceAll(new RegExp(r'^package:'), '').split('/');
- var packageName = splittedUri.first;
- var packageVersion;
- if (packageName == packageMeta.name) {
- packageVersion = packageMeta.version;
- } else {
- var match = new RegExp(
- '.pub-cache/(hosted/pub.dartlang.org|git)/${packageName}-([^/]+)')
- .firstMatch(filePath);
- if (match != null) {
- packageVersion = match[2];
- }
- }
- if (packageVersion != null) {
- return '${packageName}/${packageVersion}/${splittedUri.skip(1).join("/")}';
- } else {
- return null;
- }
- } else if (uri.startsWith('dart:')) {
- var packageName = 'sdk';
- var packageVersion = packageGraph.sdk.sdkVersion;
- return '${packageName}/${packageVersion}/lib/${uri.replaceAll(new RegExp(r"^dart:"), "")}';
- } else {
- return null;
- }
- } else {
- return null;
- }
- }
-
- String get _crossdartUrl {
- if (lineAndColumn != null && _crossdartPath != null) {
- String url = '//www.crossdart.info/p/${_crossdartPath}.html';
- return '${url}#line-${lineAndColumn.item1}';
- } else {
- return null;
- }
- }
}
abstract class TypeParameters implements ModelElement {
diff --git a/lib/src/model_utils.dart b/lib/src/model_utils.dart
index 0331511..7382a40 100644
--- a/lib/src/model_utils.dart
+++ b/lib/src/model_utils.dart
@@ -12,7 +12,6 @@
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source_io.dart';
import 'package:dartdoc/src/model.dart';
-import 'package:path/path.dart' as pathLib;
final Map<String, String> _fileContents = <String, String>{};
@@ -133,46 +132,3 @@
return line.startsWith(indent) ? line.substring(indent.length) : line;
}).join('\n');
}
-
-/// Add links to crossdart.info to the given source fragment
-String crossdartifySource(
- String inputPath,
- Map<String, Map<String, dynamic>> json,
- String source,
- Element element,
- int start) {
- inputPath = pathLib.canonicalize(inputPath);
- var sanitizer = const HtmlEscape();
- String newSource;
- if (json.isNotEmpty) {
- var node = element.computeNode();
- var file = pathLib.canonicalize(element.source.fullName);
- var filesData = json[file];
- if (filesData != null) {
- var data = filesData["references"]
- .where((r) => r["offset"] >= start && r["end"] <= node.end);
- if (data.isNotEmpty) {
- var previousStop = 0;
- var stringBuffer = new StringBuffer();
- for (var item in data) {
- stringBuffer.write(sanitizer
- .convert(source.substring(previousStop, item["offset"] - start)));
- stringBuffer
- .write("<a class='crossdart-link' href='${item["remotePath"]}'>");
- stringBuffer.write(sanitizer.convert(
- source.substring(item["offset"] - start, item["end"] - start)));
- stringBuffer.write("</a>");
- previousStop = item["end"] - start;
- }
- stringBuffer.write(
- sanitizer.convert(source.substring(previousStop, source.length)));
-
- newSource = stringBuffer.toString();
- }
- }
- }
- if (newSource == null) {
- newSource = sanitizer.convert(source);
- }
- return newSource;
-}
\ No newline at end of file
diff --git a/lib/templates/_source_code.html b/lib/templates/_source_code.html
index a00be03..27ec420 100644
--- a/lib/templates/_source_code.html
+++ b/lib/templates/_source_code.html
@@ -1,5 +1,5 @@
{{#hasSourceCode}}
<section class="summary source-code" id="source">
- <h2><span>Implementation</span> {{{crossdartHtmlTag}}}</h2>
+ <h2><span>Implementation</span></h2>
<pre class="language-dart"><code class="language-dart">{{{ sourceCode }}}</code></pre>
</section>{{/hasSourceCode}}
diff --git a/test/compare_output_test.dart b/test/compare_output_test.dart
index bef2de7..905b2e4 100644
--- a/test/compare_output_test.dart
+++ b/test/compare_output_test.dart
@@ -249,25 +249,6 @@
File outFile = new File(pathLib.join(tempDir.path, 'index.html'));
expect(outFile.readAsStringSync(), contains('footer text include'));
});
-
- test('Check dartdoc generation with crossdart', () {
- var args = <String>[
- dartdocBin,
- '--add-crossdart',
- '--output',
- tempDir.path
- ];
-
- var result = Process.runSync(Platform.resolvedExecutable, args,
- workingDirectory: _testPackagePath);
-
- if (result.exitCode != 0) {
- print(result.exitCode);
- print(result.stdout);
- print(result.stderr);
- fail('dartdoc failed');
- }
- });
}, onPlatform: {'windows': new Skip('Avoiding parsing git output')});
}
diff --git a/test/model_test.dart b/test/model_test.dart
index 3dfe7db..53121fa 100644
--- a/test/model_test.dart
+++ b/test/model_test.dart
@@ -10,7 +10,6 @@
import 'package:dartdoc/src/model.dart';
import 'package:dartdoc/src/special_elements.dart';
import 'package:dartdoc/src/warnings.dart';
-import 'package:path/path.dart' as pathLib;
import 'package:test/test.dart';
import 'src/utils.dart' as utils;
@@ -2118,48 +2117,6 @@
test('', () {});
});
- group('Crossdart', () {
- PackageGraph crossdartPackageGraph;
- Library crossdartFakeLibrary;
- Class HasGenerics;
- Method convertToMap;
-
- setUpAll(() async {
- var fakePath = "testing/test_package/lib/fake.dart";
- var offset = new File(fakePath)
- .readAsStringSync()
- .indexOf('Map<X, Y> convertToMap');
- expect(offset, isNonNegative,
- reason: "Can't find convertToMap function in ${fakePath}");
- if (Platform.isWindows) fakePath = fakePath.replaceAll('/', r'\\');
-
- crossdartPackageGraph = await utils.bootBasicPackage(
- utils.testPackageDir.path, [],
- additionalArguments: ['--add-crossdart']);
- crossdartFakeLibrary =
- crossdartPackageGraph.libraries.firstWhere((l) => l.name == 'fake');
- HasGenerics = crossdartFakeLibrary.classes
- .singleWhere((c) => c.name == 'HasGenerics');
- convertToMap = HasGenerics.instanceMethods
- .singleWhere((m) => m.name == 'convertToMap');
- var crossDartFile =
- new File(pathLib.join(utils.testPackageDir.path, "crossdart.json"));
- crossDartFile.writeAsStringSync("""
- {"$fakePath":
- {"references":[{"offset":${offset},"end":${offset + 3},"remotePath":"http://www.example.com/fake.dart"}]}}
- """);
- // Indirectly load the file.
- crossdartPackageGraph.crossdartJson;
- if (crossDartFile.existsSync()) crossDartFile.deleteSync();
- });
-
- test('Source code crossdartifies correctly end to end', () {
- crossdartPackageGraph;
- expect(convertToMap.sourceCode,
- "<a class='crossdart-link' href='http://www.example.com/fake.dart'>Map</a><X, Y> convertToMap() => null;");
- });
- });
-
group('Method', () {
Class classB,
klass,
@@ -2325,12 +2282,6 @@
expect(convertToMap.sourceCode,
'Map<X, Y> convertToMap() => null;');
});
-
- test(
- 'crossdartHtmlTag returns an empty string when Crossdart support is disabled',
- () {
- expect(m1.crossdartHtmlTag, "");
- });
});
group('Operators', () {
diff --git a/testing/test_package_docs/static-assets/styles.css b/testing/test_package_docs/static-assets/styles.css
index 8aea33d..94fbb83 100644
--- a/testing/test_package_docs/static-assets/styles.css
+++ b/testing/test_package_docs/static-assets/styles.css
@@ -257,22 +257,6 @@
border-radius: 3px;
}
-h2 .crossdart {
- float: right;
- font-size: 0.5em;
- margin-top: 1em;
-}
-
-.crossdart-link {
- border-bottom: 1px solid #dfdfdf;
- text-decoration: none;
-}
-
-.crossdart-link:hover {
- border-bottom: 1px solid #aaa;
- text-decoration: none;
-}
-
@media(max-width: 768px) {
nav .container {
width: 100%
diff --git a/testing/test_package_docs_dev/static-assets/styles.css b/testing/test_package_docs_dev/static-assets/styles.css
index 8aea33d..94fbb83 100644
--- a/testing/test_package_docs_dev/static-assets/styles.css
+++ b/testing/test_package_docs_dev/static-assets/styles.css
@@ -257,22 +257,6 @@
border-radius: 3px;
}
-h2 .crossdart {
- float: right;
- font-size: 0.5em;
- margin-top: 1em;
-}
-
-.crossdart-link {
- border-bottom: 1px solid #dfdfdf;
- text-decoration: none;
-}
-
-.crossdart-link:hover {
- border-bottom: 1px solid #aaa;
- text-decoration: none;
-}
-
@media(max-width: 768px) {
nav .container {
width: 100%
diff --git a/tool/grind.dart b/tool/grind.dart
index a5ac8f7..1aff464 100644
--- a/tool/grind.dart
+++ b/tool/grind.dart
@@ -98,7 +98,8 @@
Directory get dartdocDocsDir => _dartdocDocsDir ??= createTempSync('dartdoc');
Directory _dartdocDocsDirRemote;
-Directory get dartdocDocsDirRemote => _dartdocDocsDirRemote ??= createTempSync('dartdoc_remote');
+Directory get dartdocDocsDirRemote =>
+ _dartdocDocsDirRemote ??= createTempSync('dartdoc_remote');
Directory _sdkDocsDir;
Directory get sdkDocsDir => _sdkDocsDir ??= createTempSync('sdkdocs');
@@ -119,7 +120,8 @@
_testPackageDocsDir ??= createTempSync('test_package');
Directory _pluginPackageDocsDir;
-Directory get pluginPackageDocsDir => _pluginPackageDocsDir ??= createTempSync('test_package_flutter_plugin');
+Directory get pluginPackageDocsDir =>
+ _pluginPackageDocsDir ??= createTempSync('test_package_flutter_plugin');
/// Version of dartdoc we should use when making comparisons.
String get dartdocOriginalBranch {