Skip to content

Commit

Permalink
Merge pull request #265 from keertip/sdk
Browse files Browse the repository at this point in the history
fix doc gen for sdk
  • Loading branch information
sethladd committed Mar 14, 2015
2 parents ec1c822 + 545b561 commit 970e48d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
42 changes: 26 additions & 16 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ abstract class ModelElement {
return new Accessor(e, library);
}
if (e is TopLevelVariableElement) {
return new Variable(e, library);
return new TopLevelVariable(e, library);
}
if (e is TypeParameterElement) {
return new TypeParameter(e, library);
}
if (e is DynamicElementImpl) {
return new Dynamic(e, library);
}
if (e is ParameterElement) {
return new Parameter(e, library);
}
throw "Unknown type ${e.runtimeType}";
}

Expand Down Expand Up @@ -121,7 +124,10 @@ abstract class ModelElement {
if (melement != null &&
melement.element.node != null &&
melement.element.node is AnnotatedNode) {
return (melement.element.node as AnnotatedNode).documentationComment.references;
var docComment =
(melement.element.node as AnnotatedNode).documentationComment;
if (docComment != null) return docComment.references;
return null;
}
}
if (element.node is AnnotatedNode) {
Expand Down Expand Up @@ -412,7 +418,7 @@ class Library extends ModelElement {
List<Class> _enums;
List<ModelFunction> _functions;
List<Typedef> _typeDefs;
List<Variable> _variables;
List<TopLevelVariable> _variables;

LibraryElement get _library => (element as LibraryElement);

Expand All @@ -430,7 +436,7 @@ class Library extends ModelElement {
.map((lib) => new Library(lib, package))
.toList();

List<Variable> _getVariables() {
List<TopLevelVariable> _getVariables() {
if (_variables != null) return _variables;

List<TopLevelVariableElement> elements = [];
Expand All @@ -439,26 +445,27 @@ class Library extends ModelElement {
elements.addAll(cu.topLevelVariables);
}
elements..removeWhere(isPrivate);
_variables =
elements.map((e) => new Variable(e, this)).toList(growable: false);
_variables = elements
.map((e) => new TopLevelVariable(e, this))
.toList(growable: false);

return _variables;
}

bool get hasProperties => _getVariables().any((v) => !v.isConst);

/// All variables ("properties") except constants.
List<Variable> getProperties() {
List<TopLevelVariable> getProperties() {
return _getVariables().where((v) => !v.isConst).toList(growable: false);
}

bool get hasConstants => _getVariables().any((v) => v.isConst);

List<Variable> getConstants() {
List<TopLevelVariable> getConstants() {
return _getVariables().where((v) => v.isConst).toList(growable: false);
}

bool get hasEnums => !getEnums().isEmpty;
bool get hasEnums => getEnums().isNotEmpty;

List<Class> getEnums() {
if (_enums != null) return _enums;
Expand All @@ -475,7 +482,7 @@ class Library extends ModelElement {
return _enums;
}

bool get hasTypeDefs => !getTypedefs().isEmpty;
bool get hasTypeDefs => getTypedefs().isNotEmpty;

List<Typedef> getTypedefs() {
if (_typeDefs != null) return _typeDefs;
Expand All @@ -490,7 +497,7 @@ class Library extends ModelElement {
return _typeDefs;
}

bool get hasFunctions => !getFunctions().isEmpty;
bool get hasFunctions => getFunctions().isNotEmpty;

List<ModelFunction> getFunctions() {
if (_functions != null) return _functions;
Expand Down Expand Up @@ -940,14 +947,15 @@ class Accessor extends ModelElement {
bool get isGetter => _accessor.isGetter;

@override
String get _href => throw "not implemented yet";
String get _href =>
'${library.name}/${_accessor.enclosingElement.name}/$name.html';
}

/// Top-level variables. But also picks up getters and setters?
class Variable extends ModelElement {
class TopLevelVariable extends ModelElement {
TopLevelVariableElement get _variable => (element as TopLevelVariableElement);

Variable(TopLevelVariableElement element, Library library)
TopLevelVariable(TopLevelVariableElement element, Library library)
: super(element, library) {
if (hasGetter) {
var t = _variable.getter.returnType;
Expand Down Expand Up @@ -1013,7 +1021,8 @@ class Parameter extends ModelElement {
String toString() => element.name;

@override
String get _href => throw 'not implemented yet';
String get _href =>
'${library.name}/${_parameter.enclosingElement.name}/$name.html';
}

class TypeParameter extends ModelElement {
Expand All @@ -1027,7 +1036,8 @@ class TypeParameter extends ModelElement {
String toString() => element.name;

@override
String get _href => throw 'not implemented yet';
String get _href =>
'${library.name}/${_typeParameter.enclosingElement.name}/$name';
}

class ElementType {
Expand Down
6 changes: 3 additions & 3 deletions test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ void main() {
});

group('Variable', () {
Variable v;
Variable v3;
TopLevelVariable v;
TopLevelVariable v3;

setUp(() {
v = library.getProperties()[0];
Expand All @@ -310,7 +310,7 @@ void main() {
});

group('Constant', () {
Variable constant;
TopLevelVariable constant;

setUp(() {
constant = library.getConstants()[0];
Expand Down

0 comments on commit 970e48d

Please sign in to comment.