Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Generating "void" methods using JvmTypesBuilder.toMethod.
Generating "void" methods using JvmTypesBuilder.toMethod. [message #756094] Thu, 10 November 2011 20:41 Go to next message
Goran   is currently offline Goran Friend
Messages: 45
Registered: November 2011
Member
I am trying to generate a method with return type "void" using the JvmTypesBuilder.

I noticed that the JvmTypesBuilder.toMethod takes a JvmTypeReference as parameter.
Simply passing "null" generates a method with returnType "void" but it automatically adds a return statement.
This is incorrect Java code and as a result is not compilable:
	public void test() {
	  return null;
	}

In the JvmModelInferrer I have the following:
	members += f.toMethod(f.name, null) [
		documentation = f.documentation
		for (p : f.params) {
			parameters += p.toParameter(p.name, p.parameterType)
		}
		body = f.body
	]


Passing a JvmVoidImplCustom doesn't work since this is not a subtype of JvmTypeReference.

What is the right way of generating a method with returnType "void" and without a return statement?

Thanks in advanced
Re: Generating "void" methods using JvmTypesBuilder.toMethod. [message #756097 is a reply to message #756094] Thu, 10 November 2011 20:47 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Goran,

you have to set void as the return type of the method, e.g. via
TypeReferences.getTypeForName(void.class, someEObject)

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 10.11.11 21:41, Goran wrote:
> I am trying to generate a method with return type "void" using the
> JvmTypesBuilder.
>
> I noticed that the JvmTypesBuilder.toMethod takes a JvmTypeReference as
> parameter.
> Simply passing "null" generates a method with returnType "void" but it
> automatically adds a return statement. This is incorrect Java code and
> as a result is not compilable:
>
> public void test() {
> return null;
> }
>
> In the JvmModelInferrer I have the following:
>
> members += f.toMethod(f.name, null) [
> documentation = f.documentation
> for (p : f.params) {
> parameters += p.toParameter(p.name, p.parameterType)
> }
> body = f.body
> ]
>
>
> Passing a JvmVoidImplCustom doesn't work since this is not a subtype of
> JvmTypeReference.
>
> What is the right way of generating a method with returnType "void" and
> without a return statement?
>
> Thanks in advanced
>
Re: Generating "void" methods using JvmTypesBuilder.toMethod. [message #756108 is a reply to message #756097] Thu, 10 November 2011 23:16 Go to previous message
Goran   is currently offline Goran Friend
Messages: 45
Registered: November 2011
Member
Thanks Sebastian,

I guess I'm gonna have to spend some time learning the API.

~Goran
Previous Topic:[Xtext 2.1] Problems extending Xbase
Next Topic:Cross-referencing to plural names?
Goto Forum:
  


Current Time: Thu Apr 25 14:29:49 GMT 2024

Powered by FUDForum. Page generated in 0.02174 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top