|
|
|
|
|
Re: Help with xtext grammar void method [message #813823 is a reply to message #813791] |
Mon, 05 March 2012 18:55 |
|
Hi,
it would have been very helpful if youd mentione using Xbase before.
what you are askin for is about xbases type system.
if you translate your stuff correctly in the jvmmodelinferrer it will work out of the box.
so simply infer void as return type
NoResult:
{NoResult}'nada'
;
package org.eclipse.xtext.example.domainmodel.jvmmodel
import com.google.inject.Inject
import org.eclipse.xtext.common.types.JvmDeclaredType
import org.eclipse.xtext.example.domainmodel.domainmodel.Entity
import org.eclipse.xtext.example.domainmodel.domainmodel.Operation
import org.eclipse.xtext.example.domainmodel.domainmodel.Property
import org.eclipse.xtext.naming.IQualifiedNameProvider
import org.eclipse.xtext.util.IAcceptor
import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer
import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder
import org.eclipse.xtext.example.domainmodel.domainmodel.Result
class DomainmodelJvmModelInferrer extends AbstractModelInferrer {
@Inject extension JvmTypesBuilder
@Inject extension IQualifiedNameProvider
def dispatch infer(Entity e, IAcceptor<JvmDeclaredType> acceptor, boolean prelinkingPhase) {
acceptor.accept(
e.toClass( e.fullyQualifiedName ) [
documentation = e.documentation
if (e.superType != null)
superTypes += e.superType.cloneWithProxies
for ( f : e.features ) {
switch f {
Property : {
members += f.toField(f.name, f.type)
members += f.toGetter(f.name, f.type)
members += f.toSetter(f.name, f.type)
}
Operation : {
members += f.toMethod(f.name, if (f.result instanceof Result) (f.result as Result).type else f.newTypeRef("java.lang.void")) [
documentation = f.documentation
for (p : f.params) {
parameters += p.toParameter(p.name, p.parameterType)
}
body = f.body
]
}
}
}
]
)
}
}
this will work in the editor
but will still lead to a compile error in the generated java code (if the ops body is empty)
so a bug for this will be welcome
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Mon, 05 March 2012 18:56] Report message to a moderator
|
|
|
|
|
Re: Help with xtext grammar void method [message #813909 is a reply to message #813823] |
Mon, 05 March 2012 20:51 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Christian,
f.newTypeRef("void")
instead of
f.newTypeRef("java.lang.void")
should do the trick.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 05.03.12 19:56, schrieb Christian Dietrich:
> Hi,
>
> it would have been very helpful if youd mentione using Xbase before.
> what you are askin for is about xbases type system.
> if you translate your stuff correctly in the jvmmodelinferrer it will
> work out of the box.
> so simply infer void as return type
>
> NoResult:
> {NoResult}'nada'
> ;
>
> package org.eclipse.xtext.example.domainmodel.jvmmodel
>
> import com.google.inject.Inject
> import org.eclipse.xtext.common.types.JvmDeclaredType
> import org.eclipse.xtext.example.domainmodel.domainmodel.Entity
> import org.eclipse.xtext.example.domainmodel.domainmodel.Operation
> import org.eclipse.xtext.example.domainmodel.domainmodel.Property
> import org.eclipse.xtext.naming.IQualifiedNameProvider
> import org.eclipse.xtext.util.IAcceptor
> import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer
> import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder
> import org.eclipse.xtext.example.domainmodel.domainmodel.Result
>
> class DomainmodelJvmModelInferrer extends AbstractModelInferrer {
>
> @Inject extension JvmTypesBuilder
> @Inject extension IQualifiedNameProvider
>
> def dispatch infer(Entity e, IAcceptor<JvmDeclaredType> acceptor,
> boolean prelinkingPhase) {
> acceptor.accept(
> e.toClass( e.fullyQualifiedName ) [
> documentation = e.documentation
> if (e.superType != null)
> superTypes += e.superType.cloneWithProxies
>
> for ( f : e.features ) {
> switch f {
>
> Property : {
> members += f.toField(f.name, f.type)
> members += f.toGetter(f.name, f.type)
> members += f.toSetter(f.name, f.type)
> }
>
> Operation : {
> members += f.toMethod(f.name, if (f.result instanceof Result) (f.result
> as Result).type else f.newTypeRef("java.lang.void")) [
> documentation = f.documentation
> for (p : f.params) {
> parameters += p.toParameter(p.name, p.parameterType)
> }
> body = f.body
> ]
> }
> }
> }
> ]
> )
> }
>
> }
>
> this will work in the editor
> but will still lead to a compile error in the generated java code
> so a bug for this will be welcome
>
> ~Christian
|
|
|
|
Powered by
FUDForum. Page generated in 0.04444 seconds