Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText/XTend: JVM type inferrer with multiple classes
XText/XTend: JVM type inferrer with multiple classes [message #995082] Sat, 29 December 2012 02:29 Go to next message
Ron Smith is currently offline Ron SmithFriend
Messages: 2
Registered: December 2012
Junior Member
What's the proper way to have an JVM type inferrer using XText & XTend that reacts to multiple types in a model and generates corresponding JVM types for each.

I have the following model:
grammar org.fornax.cartridges.sculptor.guix.GuixDsl with org.eclipse.xtext.xbase.Xbase

generate guixDsl "http://eclipse.org/cartridges/sculptor/guix/GuixDsl"

DslModel:
	app=DslGuixApplication;
	
DslGuixApplication :
  (documentation=STRING)?
  "Application" name=ID "{"
  
  	(modules+=DslGuiModule)*
  	
  "}";
  

DslGuiModule:
	(documentation=STRING)?
	'Module' name=ID '{'
		("hint" "=" hint=STRING)?
		(views+=DslView)*
	'}';



And the following model inferrer which extends AbstractModelInferrer:
   	def dispatch void infer(DslGuixApplication element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
   		acceptor.accept(element.toClass( element.fullyQualifiedName ))
   			.initializeLater [
				documentation = element.documentation
			]			
   	}

   	def dispatch void infer(DslGuiModule element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {

   		acceptor.accept(element.toClass( element.fullyQualifiedName ))
   			.initializeLater [
				documentation = element.documentation
			]
	}



My second infer method is not getting called at all. If I change the first method to call the second as follows it works, but am not sure it's the correct way to do it:

   	def dispatch void infer(DslGuixApplication element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
   		acceptor.accept(element.toClass( element.fullyQualifiedName ))
   			.initializeLater [
				documentation = element.documentation
			]
			
		for (DslGuiModule child : element.modules) {
			infer(child, acceptor, isPreIndexingPhase);
		}

   	}



I've looked at examples, but they're all working off fairly simple models. Are there any examples that work on multiple model types resulting in multiple JVM types?

Ron
Re: XText/XTend: JVM type inferrer with multiple classes [message #995246 is a reply to message #995082] Sat, 29 December 2012 14:09 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi Ron

the default implementation in AbstractModelInferrer is

public void _infer(EObject e, @NonNull IJvmDeclaredTypeAcceptor
acceptor, boolean preIndexingPhase) {
for (EObject child : e.eContents()) {
infer(child, acceptor, preIndexingPhase);
}
}

thus it automatically calls the infer method on all contents of the root
object

if you have an implementation for method infer for the root object, then
infer is not automatically called for the contents anymore, and you have
to do that yourself, as you do in your second solution (which indeed works)

hope this helps
cheers
Lorenzo

On 12/29/2012 02:18 PM, Ron Smith wrote:
> What's the proper way to have an JVM type inferrer using XText & XTend
> that reacts to multiple types in a model and generates corresponding JVM
> types for each.
>
> I have the following model:
>
> grammar org.fornax.cartridges.sculptor.guix.GuixDsl with
> org.eclipse.xtext.xbase.Xbase
>
> generate guixDsl "http://eclipse.org/cartridges/sculptor/guix/GuixDsl"
>
> DslModel:
> app=DslGuixApplication;
>
> DslGuixApplication :
> (documentation=STRING)?
> "Application" name=ID "{"
>
> (modules+=DslGuiModule)*
>
> "}";
>
>
> DslGuiModule:
> (documentation=STRING)?
> 'Module' name=ID '{'
> ("hint" "=" hint=STRING)?
> (views+=DslView)*
> '}';
>
>
>
> And the following model inferrer which extends AbstractModelInferrer:
>
> def dispatch void infer(DslGuixApplication element,
> IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
> acceptor.accept(element.toClass( element.fullyQualifiedName ))
> .initializeLater [
> documentation = element.documentation
> ]
> }
>
> def dispatch void infer(DslGuiModule element,
> IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
>
> acceptor.accept(element.toClass( element.fullyQualifiedName ))
> .initializeLater [
> documentation = element.documentation
> ]
> }
>
>
>
> My second infer method is not getting called at all. If I change the
> first method to call the second as follows it works, but am not sure
> it's the correct way to do it:
>
>
> def dispatch void infer(DslGuixApplication element,
> IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
> acceptor.accept(element.toClass( element.fullyQualifiedName ))
> .initializeLater [
> documentation = element.documentation
> ]
>
> for (DslGuiModule child : element.modules) {
> infer(child, acceptor, isPreIndexingPhase);
> }
>
> }
>
>
>
> I've looked at examples, but they're all working off fairly simple
> models. Are there any examples that work on multiple model types
> resulting in multiple JVM types?
>
> Ron


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: XText/XTend: JVM type inferrer with multiple classes [message #995604 is a reply to message #995246] Sun, 30 December 2012 16:37 Go to previous message
Ron Smith is currently offline Ron SmithFriend
Messages: 2
Registered: December 2012
Junior Member
Great, I'll proceed as I'm doing then. The examples didn't seem to cover this scenario so wasn't sure what was the correct path.

Thanks
Ron
Previous Topic:Problem with importURI and standalone generator
Next Topic:PDF Doc does not open or download.
Goto Forum:
  


Current Time: Tue Apr 23 16:04:05 GMT 2024

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

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

Back to the top