From e1e8f782e99818051a3076e3e8af41a1650bccb4 Mon Sep 17 00:00:00 2001 From: keertip Date: Thu, 26 Feb 2015 10:01:13 -0800 Subject: [PATCH] get operators --- lib/src/model.dart | 16 ++++++++++++++-- test/fake_package/lib/example.dart | 3 +++ test/model_test.dart | 11 ++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/src/model.dart b/lib/src/model.dart index a9cb9c9b1c..e7d603e152 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -501,6 +501,7 @@ class Class extends ModelElement { List _interfaces; List _constructors; List _allMethods; + List _operators; List _inheritedMethods; List _staticMethods; List _instanceMethods; @@ -626,6 +627,14 @@ class Class extends ModelElement { return _allMethods; } + List get operators { + if (_operators != null) return _operators; + + _operators = _methods.where((m) => m.isOperator).toList(growable: false); + + return _operators; + } + List get staticMethods { if (_staticMethods != null) return _staticMethods; @@ -639,8 +648,9 @@ class Class extends ModelElement { List 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; } @@ -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 diff --git a/test/fake_package/lib/example.dart b/test/fake_package/lib/example.dart index 2350376a11..3442377ebd 100644 --- a/test/fake_package/lib/example.dart +++ b/test/fake_package/lib/example.dart @@ -56,6 +56,8 @@ abstract class Cat { /// implements [Cat], [E] class Dog implements Cat, E { + String name; + @deprecated List getClassA() { return [new Apple()]; @@ -64,6 +66,7 @@ class Dog implements Cat, E { @override bool get isImplemented => true; + operator ==(Dog other) => name == other.name; } abstract class E { diff --git a/test/model_test.dart b/test/model_test.dart index 7f9437bcd8..d5c41ebae4 100644 --- a/test/model_test.dart +++ b/test/model_test.dart @@ -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', () { @@ -421,8 +426,8 @@ void main() { () => expect(forAnnotation.annotations, hasLength(1))); test('has the right annotation', () { - expect(forAnnotation.annotations.first, - equals('ForAnnotation(\'my value\')')); + expect(forAnnotation.annotations.first, equals( + 'ForAnnotation(\'my value\')')); }); test('methods has the right annotation', () {