Skip to content

Commit 0553641

Browse files
authored
Merge pull request #1208 from dart-lang/strong-mode
Make dartdoc strong-mode clean (#1205).
2 parents 989ba92 + 0d6d4e7 commit 0553641

File tree

7 files changed

+52
-44
lines changed

7 files changed

+52
-44
lines changed

.analysis_options

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
analyzer:
2+
strong-mode: true
23
exclude:
34
- 'doc/api/**'
45
- 'lib/templates/*.html'

bin/dartdoc.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,21 @@ main(List<String> arguments) async {
6767
exit(1);
6868
}
6969

70-
List<String> excludeLibraries = args['exclude'];
71-
List<String> includeLibraries = args['include'];
72-
List<String> includeExternals = args['include-external'];
70+
List<String> excludeLibraries = args['exclude'] as List<String>;
71+
List<String> includeLibraries = args['include'] as List<String>;
72+
List<String> includeExternals = args['include-external'] as List<String>;
7373

7474
String url = args['hosted-url'];
75-
List<String> footerFilePaths = args['footer'].map(_resolveTildePath).toList();
75+
List<String> footerFilePaths =
76+
args['footer'].map(_resolveTildePath).toList() as List<String>;
7677
for (String footerFilePath in footerFilePaths) {
7778
if (!new File(footerFilePath).existsSync()) {
7879
print("Error: unable to locate footer file: ${footerFilePath}.");
7980
exit(1);
8081
}
8182
}
82-
List<String> headerFilePaths = args['header'].map(_resolveTildePath).toList();
83+
List<String> headerFilePaths =
84+
args['header'].map(_resolveTildePath).toList() as List<String>;
8385
for (String headerFilePath in footerFilePaths) {
8486
if (!new File(headerFilePath).existsSync()) {
8587
print("Error: unable to locate header file: ${headerFilePath}.");

lib/dartdoc.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class DartDoc {
261261
new _Error(error, info.lineInfo, packageMeta.dir.path));
262262
})
263263
.where((_Error error) => error.isError)
264-
.toList()..sort();
264+
.toList() as List<_Error>..sort();
265265

266266
double seconds = _stopwatch.elapsedMilliseconds / 1000.0;
267267
print("Parsed ${libraries.length} "
@@ -299,7 +299,7 @@ class DartDocResults {
299299
DartDocResults(this.packageMeta, this.package, this.outDir);
300300
}
301301

302-
class _Error implements Comparable {
302+
class _Error implements Comparable<_Error> {
303303
final AnalysisError error;
304304
final LineInfo lineInfo;
305305
final String projectPath;

lib/src/markdown_processor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ NodeList<CommentReference> _getCommentRefs(ModelElement modelElement) {
5858
}
5959
var node = modelElement.element.computeNode().parent.parent;
6060
if (node is AnnotatedNode) {
61-
if ((node as AnnotatedNode).documentationComment != null) {
62-
return (node as AnnotatedNode).documentationComment.references;
61+
if (node.documentationComment != null) {
62+
return node.documentationComment.references;
6363
}
6464
}
6565
}

lib/src/model.dart

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Map<String, Map<String, List<Map<String, dynamic>>>> get _crossdartJson {
3838
var crossdartFile =
3939
new File(p.join(config.inputDir.path, "crossdart.json"));
4040
if (crossdartFile.existsSync()) {
41-
__crossdartJson = JSON.decode(crossdartFile.readAsStringSync());
41+
__crossdartJson = JSON.decode(crossdartFile.readAsStringSync())
42+
as Map<String, Map<String, List<Map<String, dynamic>>>>;
4243
} else {
4344
__crossdartJson = {};
4445
}
@@ -361,7 +362,7 @@ class Class extends ModelElement implements EnclosedElement {
361362
return _inheritedMethods;
362363
}
363364

364-
List<Method> get inheritedOperators {
365+
List<Operator> get inheritedOperators {
365366
if (_inheritedOperators != null) return _inheritedOperators;
366367
InheritanceManager manager = new InheritanceManager(element.library);
367368
MemberMap cmap = manager.getMapOfMembersInheritedFromClasses(element);
@@ -708,26 +709,25 @@ abstract class EnclosedElement {
708709
}
709710

710711
class Enum extends Class {
711-
@override
712-
List<EnumField> _constants;
712+
List<EnumField> _enumFields;
713713

714714
Enum(ClassElement element, Library library) : super(element, library);
715715

716716
@override
717717
List<EnumField> get constants {
718-
if (_constants != null) return _constants;
718+
if (_enumFields != null) return _enumFields;
719719

720720
// This is a hack to give 'values' an index of -1 and all other fields
721721
// their expected indicies. https://github.com/dart-lang/dartdoc/issues/1176
722722
var index = -1;
723723

724-
_constants = _cls.fields
724+
_enumFields = _cls.fields
725725
.where(isPublic)
726726
.where((f) => f.isConst)
727727
.map((field) => new EnumField.forConstant(index++, field, library))
728728
.toList(growable: false)..sort(byName);
729729

730-
return _constants;
730+
return _enumFields;
731731
}
732732

733733
@override
@@ -1011,8 +1011,8 @@ class Library extends ModelElement {
10111011
if (_functions != null) return _functions;
10121012

10131013
Set<FunctionElement> elements = new Set();
1014-
elements.addAll(_library.definingCompilationUnit.functions);
1015-
for (CompilationUnitElement cu in _library.parts) {
1014+
elements.addAll(_libraryElement.definingCompilationUnit.functions);
1015+
for (CompilationUnitElement cu in _libraryElement.parts) {
10161016
elements.addAll(cu.functions);
10171017
}
10181018
elements.addAll(_exportedNamespace.definedNames.values
@@ -1046,7 +1046,7 @@ class Library extends ModelElement {
10461046

10471047
bool get isDocumented => oneLineDoc.isNotEmpty;
10481048

1049-
bool get isInSdk => _library.isInSdk;
1049+
bool get isInSdk => _libraryElement.isInSdk;
10501050

10511051
@override
10521052
String get kind => 'library';
@@ -1060,7 +1060,7 @@ class Library extends ModelElement {
10601060

10611061
// handle the case of an anonymous library
10621062
if (element.name == null || element.name.isEmpty) {
1063-
_name = _library.definingCompilationUnit.name;
1063+
_name = _libraryElement.definingCompilationUnit.name;
10641064
if (_name.endsWith('.dart')) {
10651065
_name = _name.substring(0, _name.length - '.dart'.length);
10661066
}
@@ -1073,15 +1073,15 @@ class Library extends ModelElement {
10731073
// name is to get source.encoding.
10741074
// This may be wrong or misleading, but developers expect the name
10751075
// of dart:____
1076-
var source = _library.definingCompilationUnit.source;
1076+
var source = _libraryElement.definingCompilationUnit.source;
10771077
_name = source.isInSystemLibrary ? source.encoding : _name;
10781078

10791079
return _name;
10801080
}
10811081

10821082
String get packageName {
10831083
if (_packageName == null) {
1084-
String sourcePath = _library.source.fullName;
1084+
String sourcePath = _libraryElement.source.fullName;
10851085
File file = new File(sourcePath);
10861086
if (file.existsSync()) {
10871087
_packageName = _getPackageName(file.parent);
@@ -1094,7 +1094,7 @@ class Library extends ModelElement {
10941094
return _packageName;
10951095
}
10961096

1097-
String get path => _library.definingCompilationUnit.name;
1097+
String get path => _libraryElement.definingCompilationUnit.name;
10981098

10991099
/// All variables ("properties") except constants.
11001100
List<TopLevelVariable> get properties {
@@ -1106,8 +1106,9 @@ class Library extends ModelElement {
11061106
if (_typeDefs != null) return _typeDefs;
11071107

11081108
Set<FunctionTypeAliasElement> elements = new Set();
1109-
elements.addAll(_library.definingCompilationUnit.functionTypeAliases);
1110-
for (CompilationUnitElement cu in _library.parts) {
1109+
elements
1110+
.addAll(_libraryElement.definingCompilationUnit.functionTypeAliases);
1111+
for (CompilationUnitElement cu in _libraryElement.parts) {
11111112
elements.addAll(cu.functionTypeAliases);
11121113
}
11131114

@@ -1125,11 +1126,11 @@ class Library extends ModelElement {
11251126
if (_classes != null) return _classes;
11261127

11271128
Set<ClassElement> types = new Set();
1128-
types.addAll(_library.definingCompilationUnit.types);
1129-
for (CompilationUnitElement cu in _library.parts) {
1129+
types.addAll(_libraryElement.definingCompilationUnit.types);
1130+
for (CompilationUnitElement cu in _libraryElement.parts) {
11301131
types.addAll(cu.types);
11311132
}
1132-
for (LibraryElement le in _library.exportedLibraries) {
1133+
for (LibraryElement le in _libraryElement.exportedLibraries) {
11331134
types.addAll(le.definingCompilationUnit.types
11341135
.where((t) => _exportedNamespace.definedNames.values.contains(t.name))
11351136
.toList());
@@ -1146,7 +1147,7 @@ class Library extends ModelElement {
11461147
return _classes;
11471148
}
11481149

1149-
LibraryElement get _library => (element as LibraryElement);
1150+
LibraryElement get _libraryElement => (element as LibraryElement);
11501151

11511152
Class getClassByName(String name) {
11521153
return _allClasses.firstWhere((it) => it.name == name, orElse: () => null);
@@ -1168,8 +1169,8 @@ class Library extends ModelElement {
11681169
if (_variables != null) return _variables;
11691170

11701171
Set<TopLevelVariableElement> elements = new Set();
1171-
elements.addAll(_library.definingCompilationUnit.topLevelVariables);
1172-
for (CompilationUnitElement cu in _library.parts) {
1172+
elements.addAll(_libraryElement.definingCompilationUnit.topLevelVariables);
1173+
for (CompilationUnitElement cu in _libraryElement.parts) {
11731174
elements.addAll(cu.topLevelVariables);
11741175
}
11751176
_exportedNamespace.definedNames.values.forEach((element) {
@@ -1273,21 +1274,21 @@ class Method extends ModelElement
12731274
}
12741275

12751276
abstract class ModelElement implements Comparable, Nameable, Documentable {
1276-
final Element element;
1277-
final Library library;
1277+
final Element _element;
1278+
final Library _library;
12781279

12791280
ElementType _modelType;
12801281
String _rawDocs;
12811282
Documentation __documentation;
1282-
List _parameters;
1283+
List<Parameter> _parameters;
12831284
String _linkedName;
12841285

12851286
String _fullyQualifiedName;
12861287

12871288
// WARNING: putting anything into the body of this seems
12881289
// to lead to stack overflows. Need to make a registry of ModelElements
12891290
// somehow.
1290-
ModelElement(this.element, this.library);
1291+
ModelElement(this._element, this._library);
12911292

12921293
factory ModelElement.from(Element e, Library library) {
12931294
if (e.kind == ElementKind.DYNAMIC) {
@@ -1388,6 +1389,8 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
13881389
@override
13891390
String get documentationAsHtml => _documentation.asHtml;
13901391

1392+
Element get element => _element;
1393+
13911394
/// Returns the fully qualified name.
13921395
///
13931396
/// For example: libraryName.className.methodName
@@ -1456,6 +1459,8 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
14561459
/// A human-friendly name for the kind of element this is.
14571460
String get kind;
14581461

1462+
Library get library => _library;
1463+
14591464
String get linkedName {
14601465
if (_linkedName == null) {
14611466
_linkedName = _calculateLinkedName();
@@ -1906,7 +1911,7 @@ class Package implements Nameable, Documentable {
19061911
}
19071912
}
19081913

1909-
class PackageCategory implements Comparable {
1914+
class PackageCategory implements Comparable<PackageCategory> {
19101915
final String name;
19111916
final List<Library> _libraries = [];
19121917

@@ -2029,8 +2034,8 @@ abstract class SourceCodeMixin {
20292034

20302035
String get _crossdartPath {
20312036
var node = element.computeNode();
2032-
if (node is Declaration && (node as Declaration).element != null) {
2033-
var source = ((node as Declaration).element.source as FileBasedSource);
2037+
if (node is Declaration && node.element != null) {
2038+
var source = (node.element.source as FileBasedSource);
20342039
var file = source.file.toString();
20352040
var uri = source.uri.toString();
20362041
var packageMeta = library.package.packageMeta;
@@ -2077,8 +2082,8 @@ abstract class SourceCodeMixin {
20772082

20782083
int get _lineNumber {
20792084
var node = element.computeNode();
2080-
if (node is Declaration && (node as Declaration).element != null) {
2081-
var element = (node as Declaration).element;
2085+
if (node is Declaration && node.element != null) {
2086+
var element = node.element;
20822087
var lineNumber = lineNumberCache.lineNumber(
20832088
element.source.fullName, element.nameOffset);
20842089
return lineNumber + 1;

lib/src/package_meta.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class _FilePackageMeta extends PackageMeta {
124124
/// empty list if no reasons found.
125125
@override
126126
List<String> getInvalidReasons() {
127-
var reasons = [];
127+
List<String> reasons = <String>[];
128128
if (_pubspec == null || _pubspec.isEmpty) {
129129
reasons.add('No pubspec.yaml found');
130130
} else if (!_pubspec.containsKey('name')) {

tool/doc_packages.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Future<List<String>> _packageUrls(int page) {
124124
return http
125125
.get('https://pub.dartlang.org/packages.json?page=${page}')
126126
.then((response) {
127-
return JSON.decode(response.body)['packages'];
127+
return new List<String>.from(JSON.decode(response.body)['packages']);
128128
});
129129
}
130130

@@ -133,8 +133,8 @@ Future<List<PackageInfo>> _getPackageInfos(List<String> packageUrls) {
133133
return http.get(p).then((response) {
134134
var json = JSON.decode(response.body);
135135
String name = json['name'];
136-
List<Version> versions =
137-
json['versions'].map((v) => new Version.parse(v)).toList();
136+
List<Version> versions = new List<Version>.from(
137+
json['versions'].map((v) => new Version.parse(v)));
138138
return new PackageInfo(name, Version.primary(versions));
139139
});
140140
}).toList();

0 commit comments

Comments
 (0)