Skip to content

Commit 4410c77

Browse files
authored
Privatize some of the interface of Canonicalization, Category (#2291)
1 parent f740dfc commit 4410c77

File tree

3 files changed

+72
-20
lines changed

3 files changed

+72
-20
lines changed

lib/src/model/canonicalization.dart

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ abstract class Canonicalization implements Locatable, Documentable {
1616
Set<String> get locationPieces;
1717

1818
List<ScoredCandidate> scoreCanonicalCandidates(Iterable<Library> libraries) {
19-
return libraries.map(scoreElementWithLibrary).toList()..sort();
19+
return libraries.map(_scoreElementWithLibrary).toList()..sort();
2020
}
2121

22-
ScoredCandidate scoreElementWithLibrary(Library lib) {
22+
ScoredCandidate _scoreElementWithLibrary(Library lib) {
2323
var scoredCandidate = ScoredCandidate(this, lib);
2424
Iterable<String> resplit(Set<String> items) sync* {
2525
for (var item in items) {
@@ -31,23 +31,23 @@ abstract class Canonicalization implements Locatable, Documentable {
3131

3232
// Large boost for @canonicalFor, essentially overriding all other concerns.
3333
if (lib.canonicalFor.contains(fullyQualifiedName)) {
34-
scoredCandidate.alterScore(5.0, 'marked @canonicalFor');
34+
scoredCandidate._alterScore(5.0, 'marked @canonicalFor');
3535
}
3636
// Penalty for deprecated libraries.
37-
if (lib.isDeprecated) scoredCandidate.alterScore(-1.0, 'is deprecated');
37+
if (lib.isDeprecated) scoredCandidate._alterScore(-1.0, 'is deprecated');
3838
// Give a big boost if the library has the package name embedded in it.
3939
if (lib.package.namePieces.intersection(lib.namePieces).isEmpty) {
40-
scoredCandidate.alterScore(1.0, 'embeds package name');
40+
scoredCandidate._alterScore(1.0, 'embeds package name');
4141
}
4242
// Give a tiny boost for libraries with long names, assuming they're
4343
// more specific (and therefore more likely to be the owner of this symbol).
44-
scoredCandidate.alterScore(.01 * lib.namePieces.length, 'name is long');
44+
scoredCandidate._alterScore(.01 * lib.namePieces.length, 'name is long');
4545
// If we don't know the location of this element, return our best guess.
4646
// TODO(jcollins-g): is that even possible?
4747
assert(locationPieces.isNotEmpty);
4848
if (locationPieces.isEmpty) return scoredCandidate;
4949
// The more pieces we have of the location in our library name, the more we should boost our score.
50-
scoredCandidate.alterScore(
50+
scoredCandidate._alterScore(
5151
lib.namePieces.intersection(locationPieces).length.toDouble() /
5252
locationPieces.length.toDouble(),
5353
'element location shares parts with name');
@@ -60,35 +60,63 @@ abstract class Canonicalization implements Locatable, Documentable {
6060
}
6161
}
6262
}
63-
scoredCandidate.alterScore(
63+
scoredCandidate._alterScore(
6464
scoreBoost, 'element location parts start with parts of name');
6565
return scoredCandidate;
6666
}
67+
68+
@Deprecated(
69+
'Public method intended to be private; will be removed as early as '
70+
'Dartdoc 1.0.0')
71+
ScoredCandidate scoreElementWithLibrary(Library lib) =>
72+
_scoreElementWithLibrary(lib);
6773
}
6874

6975
/// This class represents the score for a particular element; how likely
7076
/// it is that this is the canonical element.
7177
class ScoredCandidate implements Comparable<ScoredCandidate> {
72-
final List<String> reasons = [];
78+
final List<String> _reasons = [];
79+
80+
@Deprecated(
81+
'Public field intended to be private; will be removed as early as '
82+
'Dartdoc 1.0.0')
83+
List<String> get reasons => _reasons;
84+
85+
@Deprecated(
86+
'Public field intended to be private; will be removed as early as '
87+
'Dartdoc 1.0.0')
88+
set reasons(List<String> value) => reasons = value;
7389

7490
/// The canonicalization element being scored.
75-
final Canonicalization element;
91+
final Canonicalization _element;
92+
93+
@Deprecated(
94+
'Public getter intended to be private; will be removed as early as '
95+
'Dartdoc 1.0.0')
96+
Canonicalization get element => _element;
97+
7698
final Library library;
7799

78100
/// The score accumulated so far. Higher means it is more likely that this
79101
/// is the intended canonical Library.
80102
double score = 0.0;
81103

82-
ScoredCandidate(this.element, this.library);
104+
ScoredCandidate(this._element, this.library);
83105

84-
void alterScore(double scoreDelta, String reason) {
106+
void _alterScore(double scoreDelta, String reason) {
85107
score += scoreDelta;
86108
if (scoreDelta != 0) {
87-
reasons.add(
109+
_reasons.add(
88110
"${reason} (${scoreDelta >= 0 ? '+' : ''}${scoreDelta.toStringAsPrecision(4)})");
89111
}
90112
}
91113

114+
@Deprecated(
115+
'Public method intended to be private; will be removed as early as '
116+
'Dartdoc 1.0.0')
117+
void alterScore(double scoreDelta, String reason) =>
118+
_alterScore(scoreDelta, reason);
119+
92120
@override
93121
int compareTo(ScoredCandidate other) {
94122
//assert(element == other.element);
@@ -97,5 +125,5 @@ class ScoredCandidate implements Comparable<ScoredCandidate> {
97125

98126
@override
99127
String toString() =>
100-
"${library.name}: ${score.toStringAsPrecision(4)} - ${reasons.join(', ')}";
128+
"${library.name}: ${score.toStringAsPrecision(4)} - ${_reasons.join(', ')}";
101129
}

lib/src/model/category.dart

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,26 @@ class Category extends Nameable
2424
Indexable
2525
implements Documentable {
2626
/// All libraries in [libraries] must come from [package].
27+
Package _package;
28+
2729
@override
28-
Package package;
30+
Package get package => _package;
31+
32+
@Deprecated('Field intended to be final; setter will be removed as early as '
33+
'Dartdoc 1.0.0')
34+
set package(Package value) => _package = value;
35+
2936
final String _name;
37+
38+
DartdocOptionContext _config;
39+
3040
@override
31-
DartdocOptionContext config;
41+
DartdocOptionContext get config => _config;
42+
43+
@Deprecated('Field intended to be final; setter will be removed as early as '
44+
'Dartdoc 1.0.0')
45+
set config(DartdocOptionContext value) => _config = value;
46+
3247
final Set<Categorization> _allItems = {};
3348

3449
final List<Class> _classes = [];
@@ -41,7 +56,7 @@ class Category extends Nameable
4156
final List<ModelFunction> _functions = [];
4257
final List<Typedef> _typedefs = [];
4358

44-
Category(this._name, this.package, this.config);
59+
Category(this._name, this._package, this._config);
4560

4661
void addItem(Categorization c) {
4762
if (_allItems.contains(c)) return;
@@ -118,15 +133,24 @@ class Category extends Nameable
118133
@override
119134
String get fullyQualifiedName => name;
120135

121-
String get fileType => package.fileType;
136+
String get _fileType => package.fileType;
137+
138+
@Deprecated(
139+
'Public field intended to be private; will be removed as early as '
140+
'Dartdoc 1.0.0')
141+
String get fileType => _fileType;
122142

123-
String get filePath => 'topics/$name-topic.$fileType';
143+
String get filePath => 'topics/$name-topic.$_fileType';
124144

125145
@override
126146
String get href => isCanonical ? '${package.baseHref}$filePath' : null;
127147

148+
@Deprecated(
149+
'Public field is unused; will be removed as early as Dartdoc 1.0.0')
128150
String get categoryLabel => _categoryRenderer.renderCategoryLabel(this);
129151

152+
@Deprecated(
153+
'Public field is unused; will be removed as early as Dartdoc 1.0.0')
130154
String get linkedName => _categoryRenderer.renderLinkedName(this);
131155

132156
int _categoryIndex;

lib/src/model/top_level_variable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:dartdoc/src/model/model.dart';
88

99
/// Top-level variables. But also picks up getters and setters?
1010
class TopLevelVariable extends ModelElement
11-
with Canonicalization, GetterSetterCombo, Categorization
11+
with GetterSetterCombo, Categorization
1212
implements EnclosedElement {
1313
@override
1414
final Accessor getter;

0 commit comments

Comments
 (0)