Skip to content

Commit

Permalink
Merge pull request #268 from dart-lang/operator-page
Browse files Browse the repository at this point in the history
page for operator
  • Loading branch information
sethladd committed Mar 14, 2015
2 parents 557d21d + ac5e3e6 commit 71aa629
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
14 changes: 9 additions & 5 deletions lib/src/html_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,19 @@ class HtmlGenerator extends Generator {
package.libraries.forEach((lib) {
generateLibrary(package, lib);

lib.getClasses().forEach((clazz) {
lib.getClasses().forEach((Class clazz) {
generateClass(package, lib, clazz);

clazz.instanceMethods.forEach((m) {
generateMethod(package, lib, clazz, m);
clazz.instanceMethods.forEach((method) {
generateMethod(package, lib, clazz, method);
});

clazz.staticMethods.forEach((m) {
generateMethod(package, lib, clazz, m);
clazz.operators.forEach((operator) {
generateMethod(package, lib, clazz, operator);
});

clazz.staticMethods.forEach((method) {
generateMethod(package, lib, clazz, method);
});
});

Expand Down
28 changes: 23 additions & 5 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ abstract class ModelElement {
if (e is ConstructorElement) {
return new Constructor(e, library);
}
if (e is MethodElement) {
if (e is MethodElement && e.isOperator) {
return new Operator(e, library);
}
if (e is MethodElement && !e.isOperator) {
return new Method(e, library);
}
if (e is PropertyAccessorElement) {
Expand Down Expand Up @@ -560,7 +563,7 @@ class Class extends ModelElement {
List<ElementType> _interfaces;
List<Constructor> _constructors;
List<Method> _allMethods;
List<Method> _operators;
List<Operator> _operators;
List<Method> _inheritedMethods;
List<Method> _staticMethods;
List<Method> _instanceMethods;
Expand Down Expand Up @@ -686,13 +689,17 @@ class Class extends ModelElement {
_allMethods = _cls.methods.where(isPublic).map((e) {
var mSource =
source != null ? source.substring(e.node.offset, e.node.end) : null;
return new Method(e, library, mSource);
if (!e.isOperator) {
return new Method(e, library, mSource);
} else {
return new Operator(e, library, mSource);
}
}).toList(growable: false);

return _allMethods;
}

List<Method> get operators {
List<Operator> get operators {
if (_operators != null) return _operators;

_operators = _methods.where((m) => m.isOperator).toList(growable: false);
Expand Down Expand Up @@ -928,7 +935,9 @@ class Method extends ModelElement {
@override
bool get isStatic => _method.isStatic;

bool get isOperator => _method.isOperator;
bool get isOperator => false;

String get typeName => 'method';

String get linkedReturnType => type.createLinkedReturnTypeName();

Expand All @@ -937,6 +946,15 @@ class Method extends ModelElement {
'${library.name}/${_method.enclosingElement.name}/$name.html';
}

class Operator extends Method {
Operator(MethodElement element, Library library, [String source])
: super(element, library, source);

bool get isOperator => true;

String get typeName => 'operator';
}

/// Getters and setters.
class Accessor extends ModelElement {
PropertyAccessorElement get _accessor => (element as PropertyAccessorElement);
Expand Down
2 changes: 1 addition & 1 deletion templates/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ <h2>Operators</h2>
<code>
<span class="returntype">{{{ linkedReturnType }}}</span>
<span class="name-and-params">
<span class="name">{{ name }}</span>({{{ linkedParams }})
<span class="name"><a href="{{href}}">{{ name }}</a></span>({{{ linkedParams }})
</span>
</code>
</dt>
Expand Down
17 changes: 3 additions & 14 deletions templates/method.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{>head}}
<title>{{method.name}} method - {{class.name}} class - {{ library.name }} library - Dart API</title>
<title>{{method.name}} {{method.typeName}} - {{class.name}} class - {{ library.name }} library - Dart API</title>

<!-- required because all the links are pseudo-absolute -->
<base href="../..">
Expand All @@ -23,7 +23,8 @@
<h1 class="title">
{{ method.name }}
<span class="type">
{{#method.isStatic}}static {{/method.isStatic}}method
{{#method.isStatic}}static {{/method.isStatic}}{{method.typeName}}
on <span class="classname"><a href="{{class.href}}">{{class.name}}</a></span>
</span>
</h1>
</div>
Expand All @@ -45,18 +46,6 @@ <h1 class="title">
</code>
</section>

<section id="declared-in">
Declared in <a href="{{class.href}}">{{class.name}}</a>.
{{#class.hasImplementors}}
Also accessible from
<ul class="comma-separated end-with-period">
{{#class.implementors}}
<li><a href="{{href}}">{{name}}</a></li>
{{/class.implementors}}
</ul>
{{/class.hasImplementors}}
</section>

<section class="desc markdown">

{{#markdown}}
Expand Down
2 changes: 1 addition & 1 deletion templates/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pre.prettyprint {
border: 1px solid #CCC;
}

.title .type, .classname {
.title .type, .classname, .classname a {
color: #BBB;
}

Expand Down

0 comments on commit 71aa629

Please sign in to comment.