XText/XTend: JVM type inferrer with multiple classes [message #995082] |
Sat, 29 December 2012 02:29 |
Ron Smith 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 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
|
Powered by
FUDForum. Page generated in 0.03558 seconds