Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .analysis_options
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
analyzer:
strong-mode: true
exclude:
- 'doc/api/**'
- 'lib/templates/*.html'
Expand Down
12 changes: 7 additions & 5 deletions bin/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,21 @@ main(List<String> arguments) async {
exit(1);
}

List<String> excludeLibraries = args['exclude'];
List<String> includeLibraries = args['include'];
List<String> includeExternals = args['include-external'];
List<String> excludeLibraries = args['exclude'] as List<String>;
List<String> includeLibraries = args['include'] as List<String>;
List<String> includeExternals = args['include-external'] as List<String>;

String url = args['hosted-url'];
List<String> footerFilePaths = args['footer'].map(_resolveTildePath).toList();
List<String> footerFilePaths =
args['footer'].map(_resolveTildePath).toList() as List<String>;
for (String footerFilePath in footerFilePaths) {
if (!new File(footerFilePath).existsSync()) {
print("Error: unable to locate footer file: ${footerFilePath}.");
exit(1);
}
}
List<String> headerFilePaths = args['header'].map(_resolveTildePath).toList();
List<String> headerFilePaths =
args['header'].map(_resolveTildePath).toList() as List<String>;
for (String headerFilePath in footerFilePaths) {
if (!new File(headerFilePath).existsSync()) {
print("Error: unable to locate header file: ${headerFilePath}.");
Expand Down
4 changes: 2 additions & 2 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class DartDoc {
new _Error(error, info.lineInfo, packageMeta.dir.path));
})
.where((_Error error) => error.isError)
.toList()..sort();
.toList() as List<_Error>..sort();

double seconds = _stopwatch.elapsedMilliseconds / 1000.0;
print("Parsed ${libraries.length} "
Expand Down Expand Up @@ -299,7 +299,7 @@ class DartDocResults {
DartDocResults(this.packageMeta, this.package, this.outDir);
}

class _Error implements Comparable {
class _Error implements Comparable<_Error> {
final AnalysisError error;
final LineInfo lineInfo;
final String projectPath;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/markdown_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ NodeList<CommentReference> _getCommentRefs(ModelElement modelElement) {
}
var node = modelElement.element.computeNode().parent.parent;
if (node is AnnotatedNode) {
if ((node as AnnotatedNode).documentationComment != null) {
return (node as AnnotatedNode).documentationComment.references;
if (node.documentationComment != null) {
return node.documentationComment.references;
}
}
}
Expand Down
67 changes: 36 additions & 31 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ Map<String, Map<String, List<Map<String, dynamic>>>> get _crossdartJson {
var crossdartFile =
new File(p.join(config.inputDir.path, "crossdart.json"));
if (crossdartFile.existsSync()) {
__crossdartJson = JSON.decode(crossdartFile.readAsStringSync());
__crossdartJson = JSON.decode(crossdartFile.readAsStringSync())
as Map<String, Map<String, List<Map<String, dynamic>>>>;
} else {
__crossdartJson = {};
}
Expand Down Expand Up @@ -361,7 +362,7 @@ class Class extends ModelElement implements EnclosedElement {
return _inheritedMethods;
}

List<Method> get inheritedOperators {
List<Operator> get inheritedOperators {
if (_inheritedOperators != null) return _inheritedOperators;
InheritanceManager manager = new InheritanceManager(element.library);
MemberMap cmap = manager.getMapOfMembersInheritedFromClasses(element);
Expand Down Expand Up @@ -708,26 +709,25 @@ abstract class EnclosedElement {
}

class Enum extends Class {
@override
List<EnumField> _constants;
List<EnumField> _enumFields;

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

@override
List<EnumField> get constants {
if (_constants != null) return _constants;
if (_enumFields != null) return _enumFields;

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

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

return _constants;
return _enumFields;
}

@override
Expand Down Expand Up @@ -1011,8 +1011,8 @@ class Library extends ModelElement {
if (_functions != null) return _functions;

Set<FunctionElement> elements = new Set();
elements.addAll(_library.definingCompilationUnit.functions);
for (CompilationUnitElement cu in _library.parts) {
elements.addAll(_libraryElement.definingCompilationUnit.functions);
for (CompilationUnitElement cu in _libraryElement.parts) {
elements.addAll(cu.functions);
}
elements.addAll(_exportedNamespace.definedNames.values
Expand Down Expand Up @@ -1046,7 +1046,7 @@ class Library extends ModelElement {

bool get isDocumented => oneLineDoc.isNotEmpty;

bool get isInSdk => _library.isInSdk;
bool get isInSdk => _libraryElement.isInSdk;

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

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

return _name;
}

String get packageName {
if (_packageName == null) {
String sourcePath = _library.source.fullName;
String sourcePath = _libraryElement.source.fullName;
File file = new File(sourcePath);
if (file.existsSync()) {
_packageName = _getPackageName(file.parent);
Expand All @@ -1094,7 +1094,7 @@ class Library extends ModelElement {
return _packageName;
}

String get path => _library.definingCompilationUnit.name;
String get path => _libraryElement.definingCompilationUnit.name;

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

Set<FunctionTypeAliasElement> elements = new Set();
elements.addAll(_library.definingCompilationUnit.functionTypeAliases);
for (CompilationUnitElement cu in _library.parts) {
elements
.addAll(_libraryElement.definingCompilationUnit.functionTypeAliases);
for (CompilationUnitElement cu in _libraryElement.parts) {
elements.addAll(cu.functionTypeAliases);
}

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

Set<ClassElement> types = new Set();
types.addAll(_library.definingCompilationUnit.types);
for (CompilationUnitElement cu in _library.parts) {
types.addAll(_libraryElement.definingCompilationUnit.types);
for (CompilationUnitElement cu in _libraryElement.parts) {
types.addAll(cu.types);
}
for (LibraryElement le in _library.exportedLibraries) {
for (LibraryElement le in _libraryElement.exportedLibraries) {
types.addAll(le.definingCompilationUnit.types
.where((t) => _exportedNamespace.definedNames.values.contains(t.name))
.toList());
Expand All @@ -1146,7 +1147,7 @@ class Library extends ModelElement {
return _classes;
}

LibraryElement get _library => (element as LibraryElement);
LibraryElement get _libraryElement => (element as LibraryElement);

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

Set<TopLevelVariableElement> elements = new Set();
elements.addAll(_library.definingCompilationUnit.topLevelVariables);
for (CompilationUnitElement cu in _library.parts) {
elements.addAll(_libraryElement.definingCompilationUnit.topLevelVariables);
for (CompilationUnitElement cu in _libraryElement.parts) {
elements.addAll(cu.topLevelVariables);
}
_exportedNamespace.definedNames.values.forEach((element) {
Expand Down Expand Up @@ -1273,21 +1274,21 @@ class Method extends ModelElement
}

abstract class ModelElement implements Comparable, Nameable, Documentable {
final Element element;
final Library library;
final Element _element;
final Library _library;

ElementType _modelType;
String _rawDocs;
Documentation __documentation;
List _parameters;
List<Parameter> _parameters;
String _linkedName;

String _fullyQualifiedName;

// WARNING: putting anything into the body of this seems
// to lead to stack overflows. Need to make a registry of ModelElements
// somehow.
ModelElement(this.element, this.library);
ModelElement(this._element, this._library);

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

Element get element => _element;

/// Returns the fully qualified name.
///
/// For example: libraryName.className.methodName
Expand Down Expand Up @@ -1456,6 +1459,8 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
/// A human-friendly name for the kind of element this is.
String get kind;

Library get library => _library;

String get linkedName {
if (_linkedName == null) {
_linkedName = _calculateLinkedName();
Expand Down Expand Up @@ -1906,7 +1911,7 @@ class Package implements Nameable, Documentable {
}
}

class PackageCategory implements Comparable {
class PackageCategory implements Comparable<PackageCategory> {
final String name;
final List<Library> _libraries = [];

Expand Down Expand Up @@ -2029,8 +2034,8 @@ abstract class SourceCodeMixin {

String get _crossdartPath {
var node = element.computeNode();
if (node is Declaration && (node as Declaration).element != null) {
var source = ((node as Declaration).element.source as FileBasedSource);
if (node is Declaration && node.element != null) {
var source = (node.element.source as FileBasedSource);
var file = source.file.toString();
var uri = source.uri.toString();
var packageMeta = library.package.packageMeta;
Expand Down Expand Up @@ -2077,8 +2082,8 @@ abstract class SourceCodeMixin {

int get _lineNumber {
var node = element.computeNode();
if (node is Declaration && (node as Declaration).element != null) {
var element = (node as Declaration).element;
if (node is Declaration && node.element != null) {
var element = node.element;
var lineNumber = lineNumberCache.lineNumber(
element.source.fullName, element.nameOffset);
return lineNumber + 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/package_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class _FilePackageMeta extends PackageMeta {
/// empty list if no reasons found.
@override
List<String> getInvalidReasons() {
var reasons = [];
List<String> reasons = <String>[];
if (_pubspec == null || _pubspec.isEmpty) {
reasons.add('No pubspec.yaml found');
} else if (!_pubspec.containsKey('name')) {
Expand Down
6 changes: 3 additions & 3 deletions tool/doc_packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Future<List<String>> _packageUrls(int page) {
return http
.get('https://pub.dartlang.org/packages.json?page=${page}')
.then((response) {
return JSON.decode(response.body)['packages'];
return new List<String>.from(JSON.decode(response.body)['packages']);
});
}

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