-
Notifications
You must be signed in to change notification settings - Fork 33
WIP: resolve property references to other namespace #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
8b726df
3500f89
c332a7e
3445726
1b5ce8c
7bdb05f
a4de9b3
1af0602
36aaacc
850e039
d9edaf2
15287f6
eb02138
96a9eab
073c3e9
e75cba8
d6f342b
596d002
7b0a6f5
66bb9e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,11 +135,13 @@ DescriptorBuilder.prototype.addNamedProperty = function(p, validate) { | |
| propsByName = this.propertiesByName; | ||
|
|
||
| if (validate) { | ||
| this.assertNotDefined(p, ns.name); | ||
| this.assertNotDefined(p, ns.localName); | ||
| this.assertNotDefined(p); | ||
| } | ||
|
|
||
| propsByName[ns.name] = propsByName[ns.localName] = p; | ||
| if (!this.propertiesByName[ns.name]) | ||
| propsByName[ns.name] = propsByName[ns.localName] = p; | ||
| else if (!this.propertiesByName[ns.localName]) | ||
| propsByName[ns.localName] = p; | ||
| }; | ||
|
|
||
| DescriptorBuilder.prototype.removeNamedProperty = function(p) { | ||
|
|
@@ -172,15 +174,18 @@ DescriptorBuilder.prototype.setIdProperty = function(p, validate) { | |
| this.idProperty = p; | ||
| }; | ||
|
|
||
| DescriptorBuilder.prototype.assertNotDefined = function(p, name) { | ||
| var propertyName = p.name, | ||
| DescriptorBuilder.prototype.assertNotDefined = function(p) { | ||
| var ns = p.ns, | ||
| propertyName = p.name, | ||
| definedProperty = this.propertiesByName[propertyName]; | ||
|
|
||
| if (definedProperty) { | ||
| if (this.propertiesByName[ns.name] && this.propertiesByName[ns.localName]) { | ||
| throw new Error( | ||
| 'property <' + propertyName + '> already defined; ' + | ||
| 'override of <' + definedProperty.definedBy.ns.name + '#' + definedProperty.ns.name + '> by ' + | ||
| '<' + p.definedBy.ns.name + '#' + p.ns.name + '> not allowed without redefines'); | ||
| 'override of <' + definedProperty.definedBy.ns.name + '#' + | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I blind or is this exactly equivalent to the original version, just with a different formatting?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, to make the review harder than necessary with this reformatting. In the course of modifying the function, I used code, dismissed it later and forgot to also revert the formatting. Your remark brought the function back to my mind. After taking another look, I refactored the variables and changed the error message. I hope this makes the namespace aspect more explicit. |
||
| definedProperty.ns.name + '> by ' + | ||
| '<' + p.definedBy.ns.name + '#' + p.ns.name + | ||
| '> not allowed without redefines'); | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -230,4 +235,4 @@ DescriptorBuilder.prototype.addTrait = function(t, inherited) { | |
|
|
||
| types.push(t); | ||
| typesByName[typeName] = t; | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,17 @@ Factory.prototype.createType = function(descriptor) { | |
| // initialize default values | ||
| forEach(descriptor.properties, function(p) { | ||
| if (!p.isMany && p.default !== undefined) { | ||
| prototype[p.name] = p.default; | ||
| var name; | ||
|
|
||
| if (p.ns.prefix === descriptor.ns.prefix) { | ||
|
|
||
| // use local name if property already in local ns | ||
| name = p.name; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting question here: What I'd expect is to have local name and ns name attribute present. I.e. I can always access the value via Likely this is only possible to accomplish via proxies, am I right about that?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
They are present, but ...
For IMO this is a compromise that we should accept. As you say, the alternative would be the introduction of proxy objects. I hope we understand each other (please don't hesitate to keep raising questions). The test cases should hold the truth to specify desired behaviour. So we need to make sure to get them right and fully cover this topic as well as update the documentation before merging. Btw, the current implementation also fails to access This is somehow inconsistent and it might be a nice improvement to map property instances early (i.e. during type creation) even if they are not explicitly initialized or have a default value. I'd more like to get One question in this context: should it be possible to define a default value for |
||
| } | ||
| else { | ||
| name = p.ns.name; | ||
| } | ||
| prototype[name] = p.default; | ||
| } | ||
| }); | ||
|
|
||
|
|
@@ -58,4 +68,4 @@ Factory.prototype.createType = function(descriptor) { | |
| props.defineDescriptor(ModdleElement, descriptor); | ||
|
|
||
| return ModdleElement; | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| { | ||
| "name": "MultipleInheritance", | ||
| "uri": "http://multipleinheritance", | ||
| "prefix": "mh", | ||
| "types": [ | ||
| { | ||
| "name": "AnotherRoot", | ||
| "properties": [ | ||
| { | ||
| "name": "any", | ||
| "type": "AnotherRoot", | ||
| "isMany": true | ||
| }, | ||
| { | ||
| "name": "many", | ||
| "type": "String", | ||
| "isMany": true | ||
| }, | ||
| { | ||
| "name": "single", | ||
| "type": "String" | ||
| }, | ||
| { | ||
| "name": "defaultSingle", | ||
| "type": "String", | ||
| "default": "mh-default-string" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "MultipleInherited", | ||
| "superClass": [ "AnotherRoot", "props:Root" ], | ||
| "properties": [ | ||
| ] | ||
| } | ||
| ] | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.