Error in Xtext/Xbase tutorial [message #1270366] |
Wed, 12 March 2014 23:08 |
JJ Mising name Messages: 12 Registered: November 2010 |
Junior Member |
|
|
I have tried to run the simple Xbase example in the Xtext 2.5 documentation and I ran into what seems to be a recurrent problem: it could not recognize the entity properties in the operation's body. Each time you try to reference a property you get an error of the type "Couldn't resolve reference to JvmIdentifiableElement 'xxx'", where xxx is the property.
I did google the problem, and found that in general people had forgotten to add the Xtend library with the xbase.lib jar, but this was not the case for me, it was in the build path. I also tried a Java and Plugin project, both yielded the same error.
I resulted to try to run the MongoBeans example and found that it was running just fine. So I tried to fix the Domain Model DSL using the MongoBeans example and eventually got it to run by changing the way the accessor methods get generated in the DomainmodelJvmModelInferrer.xtend file.
Before:
Property : {
members += feature.toField(feature.name, feature.type)
members += feature.toGetter(feature.name, feature.type)
members += feature.toSetter(feature.name, feature.type)
}
After:
...
import org.eclipse.xtext.common.types.JvmDeclaredType
...
Property : {
addDelegateAccessors(feature)
}
...
def protected addDelegateAccessors(JvmDeclaredType inferredType, Property property) {
inferredType.members += property.toMethod('get' + property.name.toFirstUpper, property.jvmType) [
documentation = property.documentation
body = '''
return «property.name» ;
'''
]
inferredType.members += property.toMethod('set' + property.name.toFirstUpper,
property.newTypeRef(Void.TYPE)) [
documentation = property.documentation
parameters += toParameter(property.name.toFirstUpper, property.jvmType)
body = '''
«property.name» = «property.name.toFirstUpper» ;
'''
]
}
def protected getJvmType(Property property) {
property.type
}
[Updated on: Thu, 13 March 2014 23:30] Report message to a moderator
|
|
|
Re: Error in Xtext/Xbase tutorial [message #1270544 is a reply to message #1270366] |
Thu, 13 March 2014 05:54 |
|
Hi,
i cannot reproduce your problem. maybe i did not understand it...
i dont get any compile errors in the xtend file...
did you try to modify/import the domain model example as which the tutorial ships with xtext and can be instantiated with new project wizard
i think the problem is some missing/wrong imports
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.02958 seconds