Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtend2] Problems with method modifiers
[Xtend2] Problems with method modifiers [message #665590] Fri, 15 April 2011 08:02 Go to next message
Alessandro Carraro is currently offline Alessandro CarraroFriend
Messages: 27
Registered: July 2009
Junior Member
2 questions, one about method visibility and the other about generating
static methods

1)I have problems when adding visibility modifiers in xtend2 files.

public generate(){''''''} reports:
Couldn't resolve reference to JvmType 'public'.
Incompatible implicit return type. Expected void but was
org.eclipse.xtext.xtend2.lib.StringConcatenation


public StringConcatenation generate(){''''''} reports:
Couldn't resolve reference to JvmType 'public'.
Incompatible implicit return type. Expected void but was
org.eclipse.xtext.xtend2.lib.StringConcatenation
extraneous input 'generate' expecting '('

Also tried with the '^' character but without success

According to online help, I could declare a method as protected or
private, but neither works (same errors)

2)In the specifications it is not mentioned the possibility to generate
in xtend2 static method (although you can import static). The reason I'm
asking is that I have a really big xtend file (little more than 1000
rows) and template validation/compilation/linking is awfully slow.
I noticed that things really speed up if I work by splitting the big
template in "modules" and import them statically in a sort of 'master
template'. the only thing making this impossible is that 'static'
keyword is not recognized. Is there a reason for this?

many thanks

Alex
Re: [Xtend2] Problems with method modifiers [message #665624 is a reply to message #665590] Fri, 15 April 2011 10:00 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Alex,

visibility modifiers are not yet implemented. They are likely to appear
before the next milestone.

Please file a ticket with the template file that is awefully slow.

No, we do not plan to support the definition of static methods. You
could use different files and reuse them by means of dynamic dependencies.
Instead of

import static org.mypack.MyXtendClass

you can use

@Inject org.mypack.MyXtendClass as fieldName

in the class body where the part 'as fieldName' is optional. The name
'myXtendClass' will be used as the default if you do not specify
something explicitly.

A ticket with your slow file attached would be helpful.

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

Am 15.04.11 10:02, schrieb carraro.alessandro@gmail.com:
> 2 questions, one about method visibility and the other about generating
> static methods
>
> 1)I have problems when adding visibility modifiers in xtend2 files.
>
> public generate(){''''''} reports:
> Couldn't resolve reference to JvmType 'public'.
> Incompatible implicit return type. Expected void but was
> org.eclipse.xtext.xtend2.lib.StringConcatenation
>
>
> public StringConcatenation generate(){''''''} reports:
> Couldn't resolve reference to JvmType 'public'.
> Incompatible implicit return type. Expected void but was
> org.eclipse.xtext.xtend2.lib.StringConcatenation
> extraneous input 'generate' expecting '('
>
> Also tried with the '^' character but without success
>
> According to online help, I could declare a method as protected or
> private, but neither works (same errors)
>
> 2)In the specifications it is not mentioned the possibility to generate
> in xtend2 static method (although you can import static). The reason I'm
> asking is that I have a really big xtend file (little more than 1000
> rows) and template validation/compilation/linking is awfully slow.
> I noticed that things really speed up if I work by splitting the big
> template in "modules" and import them statically in a sort of 'master
> template'. the only thing making this impossible is that 'static'
> keyword is not recognized. Is there a reason for this?
>
> many thanks
>
> Alex
Re: [Xtend2] Problems with method modifiers [message #727607 is a reply to message #665624] Wed, 21 September 2011 15:57 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Hi Sebastian,

Sebastian Zarnekow wrote on Fri, 15 April 2011 12:00

...
No, we do not plan to support the definition of static methods. You
could use different files and reuse them by means of dynamic dependencies.
Instead of

import static org.mypack.MyXtendClass

you can use

@Inject org.mypack.MyXtendClass as fieldName

in the class body where the part 'as fieldName' is optional. The name
'myXtendClass' will be used as the default if you do not specify
something explicitly.


First: "as" gives a syntax error Smile

If dynamic dependencies are the recommended way for imports among xtend files, doesn't that mean that methods defined in one xtend file cannot be used as extension methods in another xtend file?

It would be useful to say
import static extension MyOtherXtendClass.*

If instead I have to use
@Inject MyOtherXtendClass delegate

I have to invoke those functions as
delegate.m(a1, a2)

instead of
a1.a2

right?

something seems to be missing.
Stephan




Re: [Xtend2] Problems with method modifiers [message #727721 is a reply to message #727607] Wed, 21 September 2011 21:16 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 21.09.11 17.57, Stephan Herrmann wrote:
>
> If dynamic dependencies are the recommended way for imports among xtend
> files, doesn't that mean that methods defined in one xtend file cannot
> be used as extension methods in another xtend file?
>
> It would be useful to say import static extension MyOtherXtendClass.*
> If instead I have to use
> @Inject MyOtherXtendClass delegate
> I have to invoke those functions as
> delegate.m(a1, a2)
> instead of
> a1.a2
> right?

You can combine @Inject with extension and get the effect you want:

@Inject extension SomeClass

Since you don't need the field name in the call, you can omit it in the
declaration.

Hallvard
Re: [Xtend2] Problems with method modifiers [message #728043 is a reply to message #665624] Thu, 22 September 2011 12:55 Go to previous messageGo to next message
Oliver Libutzki is currently offline Oliver LibutzkiFriend
Messages: 40
Registered: September 2011
Member
Sebastian Zarnekow wrote on Fri, 15 April 2011 06:00
No, we do not plan to support the definition of static methods. You
could use different files and reuse them by means of dynamic dependencies.
Instead of

import static org.mypack.MyXtendClass

you can use

@Inject org.mypack.MyXtendClass as fieldName

in the class body where the part 'as fieldName' is optional. The name
'myXtendClass' will be used as the default if you do not specify
something explicitly.

Sometimes it's not possible to impact the creation of an instance of an Xtend class. As the class is not instantiated by Guice MyXtendClass is not injected. Defining static methods in Xtend would bypass this problem, I think.
Re: [Xtend2] Problems with method modifiers [message #728052 is a reply to message #727721] Thu, 22 September 2011 13:09 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Hallvard Traetteberg wrote on Wed, 21 September 2011 23:16
You can combine @Inject with extension and get the effect you want:

@Inject extension SomeClass

Since you don't need the field name in the call, you can omit it in the
declaration.

Hallvard


Thanks, I didn't see this option. BTW, there seem to be different versions of Xtend2 syntax, neither the "as" syntax mentioned before, nor omitting the field name worked for me, but that's a minor issue.

Oliver L wrote on Thu, 22 September 2011 14:55

Sometimes it's not possible to impact the creation of an instance of an Xtend class. As the class is not instantiated by Guice MyXtendClass is not injected. Defining static methods in Xtend would bypass this problem, I think.


I agree. So far my experience with Guice in Xtext isn't all sunshine and roses so I'd prefer using less injection rather then more.

thanks for your replies,
Stephan

[Updated on: Thu, 22 September 2011 13:11]

Report message to a moderator

Previous Topic:Declaring predicates
Next Topic:DSL > XMI > DSL
Goto Forum:
  


Current Time: Fri Apr 26 00:17:48 GMT 2024

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

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

Back to the top