Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xtext2] howto include (xtend) class as a static extension
[xtext2] howto include (xtend) class as a static extension [message #733739] Wed, 05 October 2011 14:53 Go to next message
Thomas Lauria is currently offline Thomas LauriaFriend
Messages: 4
Registered: January 2011
Junior Member
Hi there,
I have two questions to the static extensions of xtend2.

If I understand the extensions right, the following java class
package de.barfoo.generator;
import org.eclipse.xtend.expression.Resource;
public class Test {
	public static String getFoobar(final Resource res) {
		return res.toString();
	}
}

should in xtend then be accessible like that:

package de.barfoo.generator
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IGenerator
import org.eclipse.xtext.generator.IFileSystemAccess

import static extension de.barfoo.Test.*

class RestEntityDslGenerator implements IGenerator {
	override void doGenerate(Resource resource, IFileSystemAccess fsa) {
		resource.getFoobar()
	}
}


Is this in theory right? My first problem is, there is no getFoobar Method or foobar Property on the resource Object.

My Second Question:
is it possible to static import a class defined in xtend as extension?
applied to the upper example, use Test.xtend instead Test.java?

I could not find a way to define static functions in xtend, so is this possible at all?

Thank you
Re: [xtext2] howto include (xtend) class as a static extension [message #733761 is a reply to message #733739] Wed, 05 October 2011 15:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi,

(1) this will work/is ok: but org.eclipse.emf.ecore.resource.Resource != org.eclipse.xtend.expression.Resource
(2) why static: do something like @Inject extension GeneratorExtensions generatorExtensions
(3) no this is not possible

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [xtext2] howto include (xtend) class as a static extension [message #733777 is a reply to message #733761] Wed, 05 October 2011 15:38 Go to previous message
Thomas Lauria is currently offline Thomas LauriaFriend
Messages: 4
Registered: January 2011
Junior Member
Hi, thank you for your answer.
to (1), uups my mistake.

to (2) the idea behind was my actual Layout: several Extensions split up in different classes:
GeneratorEntityExtensions.xtend
GeneratorServiceExtensions.xtend
GeneratorStringExtensions.xtend

Then I wanted only to
"import static extension " this classes, without polluting three member variables in the target Generator object.

But your way by injecting the generators was leading me to the following, much more better Layout:

In MainGenerator:
@Inject extension GeneratorExtensions generatorExtensions
then in GeneratorExtensions
@Inject extension Ext1 ext1
@Inject extension Ext2 ext2
@Inject extension Ext3 ext3

so (3) is not necessary anymore Wink

Thank you
Previous Topic:Parsing a grammar that allows for conditional compilation
Next Topic:Default import
Goto Forum:
  


Current Time: Sat Apr 27 02:10:29 GMT 2024

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

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

Back to the top