Skip to content

Commit 0957f65

Browse files
authored
Remove crossdart support (#1856)
* Remove crossdart * dartfmt
1 parent 9730e67 commit 0957f65

File tree

10 files changed

+35
-277
lines changed

10 files changed

+35
-277
lines changed

lib/resources/styles.css

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -257,22 +257,6 @@ code {
257257
border-radius: 3px;
258258
}
259259

260-
h2 .crossdart {
261-
float: right;
262-
font-size: 0.5em;
263-
margin-top: 1em;
264-
}
265-
266-
.crossdart-link {
267-
border-bottom: 1px solid #dfdfdf;
268-
text-decoration: none;
269-
}
270-
271-
.crossdart-link:hover {
272-
border-bottom: 1px solid #aaa;
273-
text-decoration: none;
274-
}
275-
276260
@media(max-width: 768px) {
277261
nav .container {
278262
width: 100%

lib/src/dartdoc_options.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ final Directory directoryCurrent = Directory.current;
4040
final String directoryCurrentPath =
4141
pathLib.canonicalize(Directory.current.path);
4242

43-
4443
class DartdocOptionError extends DartdocFailure {
4544
DartdocOptionError(String details) : super(details);
4645
}
@@ -1271,7 +1270,6 @@ class DartdocOptionContext {
12711270
}
12721271

12731272
// All values defined in createDartdocOptions should be exposed here.
1274-
bool get addCrossdart => optionSet['addCrossdart'].valueAt(context);
12751273
bool get allowTools => optionSet['allowTools'].valueAt(context);
12761274
double get ambiguousReexportScorerMinConfidence =>
12771275
optionSet['ambiguousReexportScorerMinConfidence'].valueAt(context);
@@ -1331,9 +1329,6 @@ class DartdocOptionContext {
13311329
/// given command line arguments.
13321330
Future<List<DartdocOption>> createDartdocOptions() async {
13331331
return <DartdocOption>[
1334-
new DartdocOptionArgOnly<bool>('addCrossdart', false,
1335-
help: 'Add Crossdart links to the source code pieces.',
1336-
negatable: true),
13371332
new DartdocOptionArgOnly<bool>('allowTools', true,
13381333
help: 'Execute user-defined tools to fill in @tool directives.',
13391334
negatable: true),

lib/src/model.dart

Lines changed: 30 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import 'package:analyzer/dart/ast/ast.dart'
1515
AnnotatedNode,
1616
AstNode,
1717
CommentReference,
18-
Declaration,
1918
Expression,
2019
InstanceCreationExpression;
2120
import 'package:analyzer/dart/element/element.dart';
@@ -3038,6 +3037,7 @@ abstract class ModelElement extends Canonicalization
30383037
}
30393038

30403039
AstNode _astNode;
3040+
@override
30413041
AstNode get astNode {
30423042
_astNode ??= element?.computeNode();
30433043
return _astNode;
@@ -3994,33 +3994,34 @@ abstract class ModelElement extends Canonicalization
39943994
});
39953995
int invocationIndex = 0;
39963996
return await _replaceAllMappedAsync(rawDocs, basicToolRegExp,
3997-
(basicMatch) async {
3998-
List<String> args = _splitUpQuotedArgs(basicMatch[1]).toList();
3999-
// Tool name must come first.
4000-
if (args.isEmpty) {
4001-
warn(PackageWarning.toolError,
4002-
message: 'Must specify a tool to execute for the @tool directive.');
4003-
return Future.value('');
4004-
}
4005-
// Count the number of invocations of tools in this dartdoc block,
4006-
// so that tools can differentiate different blocks from each other.
4007-
invocationIndex++;
4008-
return await runner.run(args,
4009-
content: basicMatch[2],
4010-
environment: {
4011-
'SOURCE_LINE': lineAndColumn?.item1?.toString(),
4012-
'SOURCE_COLUMN': lineAndColumn?.item2?.toString(),
4013-
'SOURCE_PATH': (sourceFileName == null ||
3997+
(basicMatch) async {
3998+
List<String> args = _splitUpQuotedArgs(basicMatch[1]).toList();
3999+
// Tool name must come first.
4000+
if (args.isEmpty) {
4001+
warn(PackageWarning.toolError,
4002+
message:
4003+
'Must specify a tool to execute for the @tool directive.');
4004+
return Future.value('');
4005+
}
4006+
// Count the number of invocations of tools in this dartdoc block,
4007+
// so that tools can differentiate different blocks from each other.
4008+
invocationIndex++;
4009+
return await runner.run(args,
4010+
content: basicMatch[2],
4011+
environment: {
4012+
'SOURCE_LINE': lineAndColumn?.item1?.toString(),
4013+
'SOURCE_COLUMN': lineAndColumn?.item2?.toString(),
4014+
'SOURCE_PATH': (sourceFileName == null ||
40144015
package?.packagePath == null)
4015-
? null
4016-
: pathLib.relative(sourceFileName, from: package.packagePath),
4017-
'PACKAGE_PATH': package?.packagePath,
4018-
'PACKAGE_NAME': package?.name,
4019-
'LIBRARY_NAME': library?.fullyQualifiedName,
4020-
'ELEMENT_NAME': fullyQualifiedNameWithoutLibrary,
4021-
'INVOCATION_INDEX': invocationIndex.toString(),
4022-
}..removeWhere((key, value) => value == null));
4023-
}).whenComplete(runner.dispose);
4016+
? null
4017+
: pathLib.relative(sourceFileName, from: package.packagePath),
4018+
'PACKAGE_PATH': package?.packagePath,
4019+
'PACKAGE_NAME': package?.name,
4020+
'LIBRARY_NAME': library?.fullyQualifiedName,
4021+
'ELEMENT_NAME': fullyQualifiedNameWithoutLibrary,
4022+
'INVOCATION_INDEX': invocationIndex.toString(),
4023+
}..removeWhere((key, value) => value == null));
4024+
}).whenComplete(runner.dispose);
40244025
} else {
40254026
return rawDocs;
40264027
}
@@ -4730,27 +4731,6 @@ class PackageGraph {
47304731
/// Dartdoc's configuration flags.
47314732
final DartdocOptionContext config;
47324733

4733-
Map<String, Map<String, dynamic>> __crossdartJson;
4734-
// TODO(jcollins-g): move to [Package]
4735-
Map<String, Map<String, dynamic>> get crossdartJson {
4736-
if (__crossdartJson == null) {
4737-
// TODO(jcollins-g): allow crossdart.json location to be configurable
4738-
var crossdartFile =
4739-
new File(pathLib.join(config.inputDir, 'crossdart.json'));
4740-
if (crossdartFile.existsSync()) {
4741-
Map<String, dynamic> __crossdartJsonTmp =
4742-
json.decode(crossdartFile.readAsStringSync());
4743-
__crossdartJson = {};
4744-
for (String key in __crossdartJsonTmp.keys) {
4745-
__crossdartJson[pathLib.canonicalize(key)] = __crossdartJsonTmp[key];
4746-
}
4747-
} else {
4748-
__crossdartJson = {};
4749-
}
4750-
}
4751-
return __crossdartJson;
4752-
}
4753-
47544734
Package _defaultPackage;
47554735
Package get defaultPackage {
47564736
if (_defaultPackage == null) {
@@ -6107,13 +6087,7 @@ class Parameter extends ModelElement implements EnclosedElement {
61076087
}
61086088

61096089
abstract class SourceCodeMixin implements Documentable {
6110-
String get crossdartHtmlTag {
6111-
if (config.addCrossdart && _crossdartUrl != null) {
6112-
return "<a class='crossdart' href='${_crossdartUrl}'>Link to Crossdart</a>";
6113-
} else {
6114-
return "";
6115-
}
6116-
}
6090+
AstNode get astNode;
61176091

61186092
Tuple2<int, int> get lineAndColumn;
61196093

@@ -6141,12 +6115,7 @@ abstract class SourceCodeMixin implements Documentable {
61416115
var start = node.offset - (node.offset - i);
61426116
String source = contents.substring(start, node.end);
61436117

6144-
if (config.addCrossdart) {
6145-
source = crossdartifySource(config.inputDir, packageGraph.crossdartJson,
6146-
source, element, start);
6147-
} else {
6148-
source = const HtmlEscape().convert(source);
6149-
}
6118+
source = const HtmlEscape().convert(source);
61506119
source = stripIndentFromSource(source);
61516120
source = stripDartdocCommentsFromSource(source);
61526121

@@ -6163,54 +6132,6 @@ abstract class SourceCodeMixin implements Documentable {
61636132
}
61646133
return _sourceCode;
61656134
}
6166-
6167-
String get _crossdartPath {
6168-
var node = element.computeNode();
6169-
if (node is Declaration && node.declaredElement != null) {
6170-
var source = node.declaredElement.source;
6171-
var filePath = source.fullName;
6172-
var uri = source.uri.toString();
6173-
var packageMeta = library.packageGraph.packageMeta;
6174-
if (uri.startsWith('package:')) {
6175-
var splittedUri =
6176-
uri.replaceAll(new RegExp(r'^package:'), '').split('/');
6177-
var packageName = splittedUri.first;
6178-
var packageVersion;
6179-
if (packageName == packageMeta.name) {
6180-
packageVersion = packageMeta.version;
6181-
} else {
6182-
var match = new RegExp(
6183-
'.pub-cache/(hosted/pub.dartlang.org|git)/${packageName}-([^/]+)')
6184-
.firstMatch(filePath);
6185-
if (match != null) {
6186-
packageVersion = match[2];
6187-
}
6188-
}
6189-
if (packageVersion != null) {
6190-
return '${packageName}/${packageVersion}/${splittedUri.skip(1).join("/")}';
6191-
} else {
6192-
return null;
6193-
}
6194-
} else if (uri.startsWith('dart:')) {
6195-
var packageName = 'sdk';
6196-
var packageVersion = packageGraph.sdk.sdkVersion;
6197-
return '${packageName}/${packageVersion}/lib/${uri.replaceAll(new RegExp(r"^dart:"), "")}';
6198-
} else {
6199-
return null;
6200-
}
6201-
} else {
6202-
return null;
6203-
}
6204-
}
6205-
6206-
String get _crossdartUrl {
6207-
if (lineAndColumn != null && _crossdartPath != null) {
6208-
String url = '//www.crossdart.info/p/${_crossdartPath}.html';
6209-
return '${url}#line-${lineAndColumn.item1}';
6210-
} else {
6211-
return null;
6212-
}
6213-
}
62146135
}
62156136

62166137
abstract class TypeParameters implements ModelElement {

lib/src/model_utils.dart

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'package:analyzer/src/generated/engine.dart';
1212
import 'package:analyzer/src/generated/sdk.dart';
1313
import 'package:analyzer/src/generated/source_io.dart';
1414
import 'package:dartdoc/src/model.dart';
15-
import 'package:path/path.dart' as pathLib;
1615

1716
final Map<String, String> _fileContents = <String, String>{};
1817

@@ -133,46 +132,3 @@ String stripIndentFromSource(String source) {
133132
return line.startsWith(indent) ? line.substring(indent.length) : line;
134133
}).join('\n');
135134
}
136-
137-
/// Add links to crossdart.info to the given source fragment
138-
String crossdartifySource(
139-
String inputPath,
140-
Map<String, Map<String, dynamic>> json,
141-
String source,
142-
Element element,
143-
int start) {
144-
inputPath = pathLib.canonicalize(inputPath);
145-
var sanitizer = const HtmlEscape();
146-
String newSource;
147-
if (json.isNotEmpty) {
148-
var node = element.computeNode();
149-
var file = pathLib.canonicalize(element.source.fullName);
150-
var filesData = json[file];
151-
if (filesData != null) {
152-
var data = filesData["references"]
153-
.where((r) => r["offset"] >= start && r["end"] <= node.end);
154-
if (data.isNotEmpty) {
155-
var previousStop = 0;
156-
var stringBuffer = new StringBuffer();
157-
for (var item in data) {
158-
stringBuffer.write(sanitizer
159-
.convert(source.substring(previousStop, item["offset"] - start)));
160-
stringBuffer
161-
.write("<a class='crossdart-link' href='${item["remotePath"]}'>");
162-
stringBuffer.write(sanitizer.convert(
163-
source.substring(item["offset"] - start, item["end"] - start)));
164-
stringBuffer.write("</a>");
165-
previousStop = item["end"] - start;
166-
}
167-
stringBuffer.write(
168-
sanitizer.convert(source.substring(previousStop, source.length)));
169-
170-
newSource = stringBuffer.toString();
171-
}
172-
}
173-
}
174-
if (newSource == null) {
175-
newSource = sanitizer.convert(source);
176-
}
177-
return newSource;
178-
}

lib/templates/_source_code.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{#hasSourceCode}}
22
<section class="summary source-code" id="source">
3-
<h2><span>Implementation</span> {{{crossdartHtmlTag}}}</h2>
3+
<h2><span>Implementation</span></h2>
44
<pre class="language-dart"><code class="language-dart">{{{ sourceCode }}}</code></pre>
55
</section>{{/hasSourceCode}}

test/compare_output_test.dart

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -249,25 +249,6 @@ void main() {
249249
File outFile = new File(pathLib.join(tempDir.path, 'index.html'));
250250
expect(outFile.readAsStringSync(), contains('footer text include'));
251251
});
252-
253-
test('Check dartdoc generation with crossdart', () {
254-
var args = <String>[
255-
dartdocBin,
256-
'--add-crossdart',
257-
'--output',
258-
tempDir.path
259-
];
260-
261-
var result = Process.runSync(Platform.resolvedExecutable, args,
262-
workingDirectory: _testPackagePath);
263-
264-
if (result.exitCode != 0) {
265-
print(result.exitCode);
266-
print(result.stdout);
267-
print(result.stderr);
268-
fail('dartdoc failed');
269-
}
270-
});
271252
}, onPlatform: {'windows': new Skip('Avoiding parsing git output')});
272253
}
273254

test/model_test.dart

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'package:dartdoc/dartdoc.dart';
1010
import 'package:dartdoc/src/model.dart';
1111
import 'package:dartdoc/src/special_elements.dart';
1212
import 'package:dartdoc/src/warnings.dart';
13-
import 'package:path/path.dart' as pathLib;
1413
import 'package:test/test.dart';
1514

1615
import 'src/utils.dart' as utils;
@@ -2118,48 +2117,6 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
21182117
test('', () {});
21192118
});
21202119

2121-
group('Crossdart', () {
2122-
PackageGraph crossdartPackageGraph;
2123-
Library crossdartFakeLibrary;
2124-
Class HasGenerics;
2125-
Method convertToMap;
2126-
2127-
setUpAll(() async {
2128-
var fakePath = "testing/test_package/lib/fake.dart";
2129-
var offset = new File(fakePath)
2130-
.readAsStringSync()
2131-
.indexOf('Map<X, Y> convertToMap');
2132-
expect(offset, isNonNegative,
2133-
reason: "Can't find convertToMap function in ${fakePath}");
2134-
if (Platform.isWindows) fakePath = fakePath.replaceAll('/', r'\\');
2135-
2136-
crossdartPackageGraph = await utils.bootBasicPackage(
2137-
utils.testPackageDir.path, [],
2138-
additionalArguments: ['--add-crossdart']);
2139-
crossdartFakeLibrary =
2140-
crossdartPackageGraph.libraries.firstWhere((l) => l.name == 'fake');
2141-
HasGenerics = crossdartFakeLibrary.classes
2142-
.singleWhere((c) => c.name == 'HasGenerics');
2143-
convertToMap = HasGenerics.instanceMethods
2144-
.singleWhere((m) => m.name == 'convertToMap');
2145-
var crossDartFile =
2146-
new File(pathLib.join(utils.testPackageDir.path, "crossdart.json"));
2147-
crossDartFile.writeAsStringSync("""
2148-
{"$fakePath":
2149-
{"references":[{"offset":${offset},"end":${offset + 3},"remotePath":"http://www.example.com/fake.dart"}]}}
2150-
""");
2151-
// Indirectly load the file.
2152-
crossdartPackageGraph.crossdartJson;
2153-
if (crossDartFile.existsSync()) crossDartFile.deleteSync();
2154-
});
2155-
2156-
test('Source code crossdartifies correctly end to end', () {
2157-
crossdartPackageGraph;
2158-
expect(convertToMap.sourceCode,
2159-
"<a class='crossdart-link' href='http://www.example.com/fake.dart'>Map</a>&lt;X, Y&gt; convertToMap() =&gt; null;");
2160-
});
2161-
});
2162-
21632120
group('Method', () {
21642121
Class classB,
21652122
klass,
@@ -2325,12 +2282,6 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
23252282
expect(convertToMap.sourceCode,
23262283
'Map&lt;X, Y&gt; convertToMap() =&gt; null;');
23272284
});
2328-
2329-
test(
2330-
'crossdartHtmlTag returns an empty string when Crossdart support is disabled',
2331-
() {
2332-
expect(m1.crossdartHtmlTag, "");
2333-
});
23342285
});
23352286

23362287
group('Operators', () {

0 commit comments

Comments
 (0)