Skip to content

Commit 0c8b0bd

Browse files
authored
Cleanup unused interfaces (#1871)
* Delete unused code and add a trivial test * dartfmt
1 parent 4a14687 commit 0c8b0bd

File tree

5 files changed

+17
-252
lines changed

5 files changed

+17
-252
lines changed

lib/src/html/template_data.dart

Lines changed: 1 addition & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,15 @@ abstract class HtmlOptions {
99
String get toolVersion;
1010
}
1111

12-
class Subnav {
13-
final String name;
14-
final String href;
15-
16-
Subnav(this.name, this.href);
17-
18-
@override
19-
String toString() => name;
20-
}
21-
2212
abstract class TemplateData<T extends Documentable> {
2313
final PackageGraph packageGraph;
2414
final HtmlOptions htmlOptions;
2515

26-
List<Subnav> _subNameItemCache;
27-
2816
TemplateData(this.htmlOptions, this.packageGraph);
2917

30-
List<Category> get displayedCategories => <Category>[];
31-
String get documentation => self.documentation;
32-
String get oneLineDoc => self.oneLineDoc;
3318
String get title;
3419
String get layoutTitle;
3520
String get metaDescription;
36-
String get name => self.name;
37-
String get kind => self is ModelElement ? (self as ModelElement).kind : null;
3821

3922
List get navLinks;
4023
List get navLinksWithGenerics => [];
@@ -48,39 +31,19 @@ abstract class TemplateData<T extends Documentable> {
4831
bool get includeVersion => false;
4932

5033
bool get hasHomepage => false;
51-
String get homepage => null;
52-
53-
bool get hasSubNav => subnavItems.isNotEmpty;
54-
55-
List<Subnav> get subnavItems {
56-
if (_subNameItemCache == null) {
57-
_subNameItemCache = getSubNavItems().toList();
58-
}
59-
return _subNameItemCache;
60-
}
6134

6235
String get htmlBase;
6336
T get self;
6437
String get version => htmlOptions.toolVersion;
6538
String get relCanonicalPrefix => htmlOptions.relCanonicalPrefix;
6639

67-
Iterable<Subnav> getSubNavItems() => <Subnav>[];
68-
6940
String _layoutTitle(String name, String kind, bool isDeprecated) {
7041
if (isDeprecated) {
7142
return '<span class="deprecated">${name}</span> ${kind}';
7243
} else {
7344
return '${name} ${kind}';
7445
}
7546
}
76-
77-
Iterable<Subnav> _gatherSubnavForInvokable(ModelElement element) {
78-
if (element.hasSourceCode) {
79-
return [new Subnav('Source', '${element.href}#source')];
80-
} else {
81-
return <Subnav>[];
82-
}
83-
}
8447
}
8548

8649
class PackageTemplateData extends TemplateData<Package> {
@@ -98,21 +61,14 @@ class PackageTemplateData extends TemplateData<Package> {
9861
@override
9962
Package get self => package;
10063
@override
101-
String get layoutTitle => _layoutTitle(package.name, kind, false);
64+
String get layoutTitle => _layoutTitle(package.name, package.kind, false);
10265
@override
10366
String get metaDescription =>
10467
'${package.name} API docs, for the Dart programming language.';
105-
@override
106-
Iterable<Subnav> getSubNavItems() {
107-
return [new Subnav('Libraries', '${package.href}#libraries')];
108-
}
10968

11069
@override
11170
bool get hasHomepage => package.hasHomepage;
112-
@override
11371
String get homepage => package.homepage;
114-
@override
115-
String get kind => package.kind;
11672

11773
/// `null` for packages because they are at the root – not needed
11874
@override
@@ -141,25 +97,6 @@ class CategoryTemplateData extends TemplateData<Category> {
14197

14298
@override
14399
List get navLinks => [category.package];
144-
@override
145-
Iterable<Subnav> getSubNavItems() sync* {
146-
if (category.hasPublicClasses)
147-
yield new Subnav('Libraries', '${category.href}#libraries');
148-
if (category.hasPublicClasses)
149-
yield new Subnav('Classes', '${category.href}#classes');
150-
if (category.hasPublicConstants)
151-
yield new Subnav('Constants', '${category.href}#constants');
152-
if (category.hasPublicProperties)
153-
yield new Subnav('Properties', '${category.href}#properties');
154-
if (category.hasPublicFunctions)
155-
yield new Subnav('Functions', '${category.href}#functions');
156-
if (category.hasPublicEnums)
157-
yield new Subnav('Enums', '${category.href}#enums');
158-
if (category.hasPublicTypedefs)
159-
yield new Subnav('Typedefs', '${category.href}#typedefs');
160-
if (category.hasPublicExceptions)
161-
yield new Subnav('Exceptions', '${category.href}#exceptions');
162-
}
163100

164101
@override
165102
Category get self => category;
@@ -175,31 +112,12 @@ class LibraryTemplateData extends TemplateData<Library> {
175112
@override
176113
String get title => '${library.name} library - Dart API';
177114
@override
178-
String get documentation => library.documentation;
179-
@override
180115
String get htmlBase => '..';
181116
@override
182117
String get metaDescription =>
183118
'${library.name} library API docs, for the Dart programming language.';
184119
@override
185120
List get navLinks => [packageGraph.defaultPackage];
186-
@override
187-
Iterable<Subnav> getSubNavItems() sync* {
188-
if (library.hasPublicClasses)
189-
yield new Subnav('Classes', '${library.href}#classes');
190-
if (library.hasPublicConstants)
191-
yield new Subnav('Constants', '${library.href}#constants');
192-
if (library.hasPublicProperties)
193-
yield new Subnav('Properties', '${library.href}#properties');
194-
if (library.hasPublicFunctions)
195-
yield new Subnav('Functions', '${library.href}#functions');
196-
if (library.hasPublicEnums)
197-
yield new Subnav('Enums', '${library.href}#enums');
198-
if (library.hasPublicTypedefs)
199-
yield new Subnav('Typedefs', '${library.href}#typedefs');
200-
if (library.hasPublicExceptions)
201-
yield new Subnav('Exceptions', '${library.href}#exceptions');
202-
}
203121

204122
@override
205123
String get layoutTitle =>
@@ -250,23 +168,6 @@ class ClassTemplateData<T extends Class> extends TemplateData<T> {
250168
List get navLinks => [packageGraph.defaultPackage, library];
251169
@override
252170
String get htmlBase => '..';
253-
@override
254-
Iterable<Subnav> getSubNavItems() sync* {
255-
if (clazz.hasPublicConstructors)
256-
yield new Subnav('Constructors', '${clazz.href}#constructors');
257-
if (clazz.hasPublicProperties)
258-
yield new Subnav('Properties', '${clazz.href}#instance-properties');
259-
if (clazz.hasPublicMethods)
260-
yield new Subnav('Methods', '${clazz.href}#instance-methods');
261-
if (clazz.hasPublicOperators)
262-
yield new Subnav('Operators', '${clazz.href}#operators');
263-
if (clazz.hasPublicStaticProperties)
264-
yield new Subnav('Static Properties', '${clazz.href}#static-properties');
265-
if (clazz.hasPublicStaticMethods)
266-
yield new Subnav('Static Methods', '${clazz.href}#static-methods');
267-
if (clazz.hasPublicConstants)
268-
yield new Subnav('Constants', '${clazz.href}#constants');
269-
}
270171

271172
Class get objectType {
272173
if (_objectType != null) {
@@ -303,7 +204,6 @@ class ConstructorTemplateData extends TemplateData<Constructor> {
303204
@override
304205
List get navLinksWithGenerics => [clazz];
305206
@override
306-
Iterable<Subnav> getSubNavItems() => _gatherSubnavForInvokable(constructor);
307207
@override
308208
String get htmlBase => '../..';
309209
@override
@@ -324,13 +224,6 @@ class EnumTemplateData extends ClassTemplateData<Enum> {
324224
Enum get eNum => clazz;
325225
@override
326226
Enum get self => eNum;
327-
@override
328-
Iterable<Subnav> getSubNavItems() => [
329-
new Subnav('Constants', '${eNum.href}#constants'),
330-
new Subnav('Properties', '${eNum.href}#instance-properties'),
331-
new Subnav('Methods', '${eNum.href}#instance-methods'),
332-
new Subnav('Operators', '${eNum.href}#operators')
333-
];
334227
}
335228

336229
class FunctionTemplateData extends TemplateData<ModelFunction> {
@@ -356,8 +249,6 @@ class FunctionTemplateData extends TemplateData<ModelFunction> {
356249
@override
357250
List get navLinks => [packageGraph.defaultPackage, library];
358251
@override
359-
Iterable<Subnav> getSubNavItems() => _gatherSubnavForInvokable(function);
360-
@override
361252
String get htmlBase => '..';
362253
}
363254

@@ -387,8 +278,6 @@ class MethodTemplateData extends TemplateData<Method> {
387278
@override
388279
List get navLinksWithGenerics => [clazz];
389280
@override
390-
Iterable<Subnav> getSubNavItems() => _gatherSubnavForInvokable(method);
391-
@override
392281
String get htmlBase => '../..';
393282
}
394283

@@ -458,8 +347,6 @@ class TypedefTemplateData extends TemplateData<Typedef> {
458347
List get navLinks => [packageGraph.defaultPackage, library];
459348
@override
460349
String get htmlBase => '..';
461-
@override
462-
Iterable<Subnav> getSubNavItems() => _gatherSubnavForInvokable(typeDef);
463350
}
464351

465352
class TopLevelPropertyTemplateData extends TemplateData<TopLevelVariable> {

lib/src/line_number_cache.dart

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,12 @@ class LineNumberCache {
4242
final Map<String, SplayTreeMap<int, int>> _lineNumbers =
4343
<String, SplayTreeMap<int, int>>{};
4444

45-
int lineNumber(String file, int offset) {
46-
if (offset == 0) {
47-
return 0;
48-
} else {
49-
var lineMap = _lineNumbers.putIfAbsent(
50-
file, () => _createLineNumbersMap(_fileContents(file)));
51-
var lastKey = lineMap.lastKeyBefore(offset);
52-
return lineMap[lastKey];
53-
}
54-
}
55-
5645
Tuple2<int, int> lineAndColumn(String file, int offset) {
57-
if (offset == 0) {
58-
return new Tuple2(0, 0);
59-
} else {
60-
var lineMap = _lineNumbers.putIfAbsent(
61-
file, () => _createLineNumbersMap(_fileContents(file)));
62-
var lastKey = lineMap.lastKeyBefore(offset);
63-
if (lastKey != null) {
64-
return new Tuple2(lineMap[lastKey] + 1, offset - lastKey);
65-
}
46+
var lineMap = _lineNumbers.putIfAbsent(
47+
file, () => _createLineNumbersMap(_fileContents(file)));
48+
var lastKey = lineMap.lastKeyBefore(offset);
49+
if (lastKey != null) {
50+
return new Tuple2(lineMap[lastKey] + 1, offset - lastKey);
6651
}
6752
return null;
6853
}

0 commit comments

Comments
 (0)