Skip to content

Commit

Permalink
Merge pull request #238 from keertip/operators
Browse files Browse the repository at this point in the history
get operators for a class
  • Loading branch information
keertip committed Feb 26, 2015
2 parents 769f9e2 + e1e8f78 commit b1d1e32
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
16 changes: 14 additions & 2 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ class Class extends ModelElement {
List<ElementType> _interfaces;
List<Constructor> _constructors;
List<Method> _allMethods;
List<Method> _operators;
List<Method> _inheritedMethods;
List<Method> _staticMethods;
List<Method> _instanceMethods;
Expand Down Expand Up @@ -626,6 +627,14 @@ class Class extends ModelElement {
return _allMethods;
}

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

_operators = _methods.where((m) => m.isOperator).toList(growable: false);

return _operators;
}

List<Method> get staticMethods {
if (_staticMethods != null) return _staticMethods;

Expand All @@ -639,8 +648,9 @@ class Class extends ModelElement {
List<Method> get instanceMethods {
if (_instanceMethods != null) return _instanceMethods;

_instanceMethods =
_methods.where((m) => !m.isStatic).toList(growable: false);
_instanceMethods = _methods
.where((m) => !m.isStatic && !m.isOperator)
.toList(growable: false);

return _instanceMethods;
}
Expand Down Expand Up @@ -815,6 +825,8 @@ class Method extends ModelElement {
@override
bool get isStatic => _method.isStatic;

bool get isOperator => _method.isOperator;

String get linkedReturnType => type.createLinkedReturnTypeName();

@override
Expand Down
3 changes: 3 additions & 0 deletions test/fake_package/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ abstract class Cat {
/// implements [Cat], [E]
class Dog implements Cat, E {

String name;

@deprecated
List<Apple> getClassA() {
return [new Apple()];
Expand All @@ -64,6 +66,7 @@ class Dog implements Cat, E {
@override
bool get isImplemented => true;

operator ==(Dog other) => name == other.name;
}

abstract class E {
Expand Down
11 changes: 8 additions & 3 deletions test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ void main() {
});

test('get methods', () {
expect(B.instanceMethods, hasLength(1));
expect(Dog.instanceMethods, hasLength(1));
});

test('get operators', () {
expect(Dog.operators, hasLength(1));
expect(Dog.operators[0].name, '==');
});

test('inherited methods', () {
Expand Down Expand Up @@ -421,8 +426,8 @@ void main() {
() => expect(forAnnotation.annotations, hasLength(1)));

test('has the right annotation', () {
expect(forAnnotation.annotations.first,
equals('<a href="ex/ForAnnotation.html">ForAnnotation</a>(\'my value\')'));
expect(forAnnotation.annotations.first, equals(
'<a href="ex/ForAnnotation.html">ForAnnotation</a>(\'my value\')'));
});

test('methods has the right annotation', () {
Expand Down

0 comments on commit b1d1e32

Please sign in to comment.