Initializer from XExpression [message #1722396] |
Thu, 04 February 2016 15:05 |
Daniel Cardin Messages: 109 Registered: July 2009 |
Senior Member |
|
|
I have the following rule I want to infer
Attribute :
(transient='transient')? type=JvmTypeReference name=ValidID ('=' defaultValue=XLiteral)?
;
to the following static definition
public static final PropertyAttribute<«attribute.type»> «attribute.name» = new PersistentPropertyAttribute<«attribute.type»>("«attribute.name»", «attribute.type».class, «DEFAULT VALUE CODE»);
The normal inferrer works, of course, but I have to deal with the default value, which is not as straightforward as I thought.
My idea, greatly inspired by the past conversations, needs to be validated, please.
If I changed my grammar to :
Attribute returns xbase::XExpression :
{Attribute} (transient='transient')? type=JvmTypeReference name=ValidID ('=' defaultValue=XLiteral)?
;
... and adapted my compiler to return the "new ...." part with the properly interpreted default value.
Could I do this in the inferrer ?
attributes.toField(attribute.name, genericAttributeType) => [
visibility = JvmVisibility.PUBLIC
static = true
final = true
initializer = attribute ///////////// Since it's an XExpression... I assume it would go through the normal compiler mechanism?
]
Obviously (now ahah), I could use the type computer to make sure the expected type is compatible with the whole expression type.
Do you think that could work?
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02003 seconds