fix(reflector): merge prop metadata from getters and setters

Closes #4006
This commit is contained in:
vsavkin 2015-09-04 16:36:08 -07:00 committed by Victor Savkin
parent 4ec4dcabe9
commit 15164a8e6c
4 changed files with 19 additions and 2 deletions

View File

@ -259,7 +259,8 @@ class ReflectionCapabilities implements PlatformReflectionCapabilities {
final res = {}; final res = {};
reflectClass(typeOrFunc).declarations.forEach((k,v) { reflectClass(typeOrFunc).declarations.forEach((k,v) {
var name = _normalizeName(MirrorSystem.getName(k)); 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; return res;
} }

View File

@ -27,3 +27,8 @@ ParamDecorator paramDecorator(value) {
PropDecorator propDecorator(value) { PropDecorator propDecorator(value) {
return new PropDecorator(value); return new PropDecorator(value);
} }
class HasGetterAndSetterDecorators {
@PropDecorator("get") get a {}
@PropDecorator("set") set a(v) {}
}

View File

@ -31,3 +31,6 @@ export function propDecorator(value) {
export var ClassDecorator = makeDecorator(ClassDecoratorMeta); export var ClassDecorator = makeDecorator(ClassDecoratorMeta);
export var ParamDecorator = makeParamDecorator(ParamDecoratorMeta); export var ParamDecorator = makeParamDecorator(ParamDecoratorMeta);
export var PropDecorator = makePropDecorator(PropDecoratorMeta); export var PropDecorator = makePropDecorator(PropDecoratorMeta);
// used only in Dart
export class HasGetterAndSetterDecorators {}

View File

@ -7,7 +7,8 @@ import {
PropDecorator, PropDecorator,
classDecorator, classDecorator,
paramDecorator, paramDecorator,
propDecorator propDecorator,
HasGetterAndSetterDecorators
} from './reflector_common'; } from './reflector_common';
import {IS_DART} from '../../platform'; import {IS_DART} from '../../platform';
@ -160,6 +161,13 @@ export function main() {
reflector.registerType(TestObj, new ReflectionInfo(null, null, null, null, {"a": [1, 2]})); reflector.registerType(TestObj, new ReflectionInfo(null, null, null, null, {"a": [1, 2]}));
expect(reflector.propMetadata(TestObj)).toEqual({"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", () => { describe("annotations", () => {