Skip to content

Commit

Permalink
fix(reflector): merge prop metadata from getters and setters
Browse files Browse the repository at this point in the history
Closes #4006
  • Loading branch information
vsavkin committed Sep 4, 2015
1 parent 4ec4dca commit 15164a8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ class ReflectionCapabilities implements PlatformReflectionCapabilities {
final res = {};
reflectClass(typeOrFunc).declarations.forEach((k,v) {
var name = _normalizeName(MirrorSystem.getName(k));
res[name] = v.metadata.map((fm) => fm.reflectee).toList();
if (res[name] == null) res[name] = [];
res[name].addAll(v.metadata.map((fm) => fm.reflectee));
});
return res;
}
Expand Down
5 changes: 5 additions & 0 deletions modules/angular2/test/core/reflection/reflector_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ ParamDecorator paramDecorator(value) {
PropDecorator propDecorator(value) {
return new PropDecorator(value);
}

class HasGetterAndSetterDecorators {
@PropDecorator("get") get a {}
@PropDecorator("set") set a(v) {}
}
3 changes: 3 additions & 0 deletions modules/angular2/test/core/reflection/reflector_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ export function propDecorator(value) {
export var ClassDecorator = makeDecorator(ClassDecoratorMeta);
export var ParamDecorator = makeParamDecorator(ParamDecoratorMeta);
export var PropDecorator = makePropDecorator(PropDecoratorMeta);

// used only in Dart
export class HasGetterAndSetterDecorators {}
10 changes: 9 additions & 1 deletion modules/angular2/test/core/reflection/reflector_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
PropDecorator,
classDecorator,
paramDecorator,
propDecorator
propDecorator,
HasGetterAndSetterDecorators
} from './reflector_common';
import {IS_DART} from '../../platform';

Expand Down Expand Up @@ -160,6 +161,13 @@ export function main() {
reflector.registerType(TestObj, new ReflectionInfo(null, null, null, null, {"a": [1, 2]}));
expect(reflector.propMetadata(TestObj)).toEqual({"a": [1, 2]});
});

if (IS_DART) {
it("should merge metadata from getters and setters", () => {
var p = reflector.propMetadata(HasGetterAndSetterDecorators);
expect(p["a"]).toEqual([propDecorator("get"), propDecorator("set")]);
});
}
});

describe("annotations", () => {
Expand Down

0 comments on commit 15164a8

Please sign in to comment.