Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Errors in XPAND
Errors in XPAND [message #798269] Tue, 14 February 2012 13:10 Go to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
Hi,

I have an Xtext grammer like:

Model: entity1+=Entity1
entity2+=Entity2

Entity1: 'Entity1' prop=ID ';'

Entity2: 'Entity2' prop1=ID prop2=ID ';'

I want to generate codes for each Entity1 and I want to each Entity2 in Entity1.

Example:

public class name
{
This is Entity1
prop1 prop2 //These are properties of an instance Entity2
prop1 prop2 //These are properties of an instance Entity2
}

template.xpt file is:

«DEFINE main FOR Entity1»
«FILE name+".java"»

This is Entity1
«EXPAND test FOREACH Entity2»
«ENDFILE-»
«ENDDEFINE»

«DEFINE test FOR Entity2»

«prop1» «prop2»

«ENDDEFINE»

mw2 file is :

module workflow.MyDslGenerator

import org.eclipse.emf.mwe.utils.*

var targetDir = "src-gen"
var fileEncoding = "Cp1254"
var modelPath = "src/model"

Workflow {

component = org.eclipse.xtext.mwe.Reader {
// lookup all resources on the classpath
// useJavaClassPath = true

// or define search scope explicitly
path = modelPath

// this class will be generated by the xtext generator
register = org.xtext.example.mydsl.MyDslStandaloneSetup {}
load = {
slot = "entity1"
type = "Entity1"
}
}

component = org.eclipse.xpand2.Generator {
expand = "templates::Template::main FOREACH entity1"
outlet = {
path = targetDir
}
fileEncoding = fileEncoding
}
}



When I run the project, I received lots of errors on the Console. And a "Collection type expected!" error on the editor.

What can I do? If somebody can help me, I will be very glad.
Re: Errors in XPAND [message #798285 is a reply to message #798269] Tue, 14 February 2012 13:43 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 354
Registered: July 2009
Location: Dortmund
Senior Member

First, elements from Xtext models will only be referrable when they have a name. By default, your Entity types should have a name attribute like
Entity1: 'Entity1' name=ID ';'

Otherwise the Reader component would report something like "Could not find any exported element of type Entity1".

The name of elements can be also computed by providing a different IQualifiedNameProvider and bound it to the RuntimeModule, the default implementation will search for the "name" attributes to compute qualified names for elements. Only elements for which the IQualifiedNameProvider returns non-null can be exported into a slot and then passed the Xpand.

The "Collection type expected!" error occurs because there is no multi-valued reference from Entity1 to Entity2 named "Entity2". If you would like to expand each Entity2 from the same model as Entity1, you could go up to the model.

«DEFINE main FOR Entity1»
«FILE name+".java"»

This is Entity1
«EXPAND test FOREACH ((Model)eContainer).entity2»
«ENDFILE-»
«ENDDEFINE»


Usually this does not really make sense. Usually cross-references would be better here. You should look at the resulting Ecore metamodel from your grammar, this would make it easier to understand your Xpand templates.

Regards,
~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Errors in XPAND [message #798312 is a reply to message #798285] Tue, 14 February 2012 14:19 Go to previous messageGo to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
Thank you,

I tried the solution but this time I received:

Multiple markers at this line
- Collection type expected!
- Unknown org::xtext::example::mydsl::myDsl::Entity1
property, variable, type or enumeration literal 'eContainer'
- Template.xpt [line: 25] - EXPAND

error.

[Updated on: Tue, 14 February 2012 14:24]

Report message to a moderator

Re: Errors in XPAND [message #798502 is a reply to message #798312] Tue, 14 February 2012 19:19 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Hi,

are you using the JavaBeans metamodel or the Emf(Registry)Metamodel.
looks like you are using the JavaBeans one.
=>

«EXPAND test FOREACH ((Model)eContainer()).entity2»


~Christian
Re: Errors in XPAND [message #798891 is a reply to message #798502] Wed, 15 February 2012 07:46 Go to previous messageGo to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
Hi,
I am using JavaBeans metamodel.
Re: Errors in XPAND [message #798895 is a reply to message #798891] Wed, 15 February 2012 07:51 Go to previous messageGo to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
I want to define the attributes of one metaelement in a file which opens with the existing of a different metaelement.
Re: Errors in XPAND [message #798915 is a reply to message #798891] Wed, 15 February 2012 08:16 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Does the solution I proposed work?
Re: Errors in XPAND [message #798949 is a reply to message #798915] Wed, 15 February 2012 09:02 Go to previous messageGo to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
Unfortunlly not:(

I tried the solution but this time I received:

Multiple markers at this line
- Collection type expected!
- Unknown org::xtext::example::mydsl::myDsl::Entity1
property, variable, type or enumeration literal 'eContainer'
- Template.xpt [line: 25] - EXPAND

error.
Re: Errors in XPAND [message #798961 is a reply to message #798949] Wed, 15 February 2012 09:16 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Sure you did not miss the ()
Re: Errors in XPAND [message #798971 is a reply to message #798961] Wed, 15 February 2012 09:42 Go to previous messageGo to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
I did not miss the () but can it be because of missing sth in the generator file?

[Updated on: Wed, 15 February 2012 09:42]

Report message to a moderator

Re: Errors in XPAND [message #799011 is a reply to message #798971] Wed, 15 February 2012 10:27 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
how does your complete template look like?
Re: Errors in XPAND [message #799012 is a reply to message #798971] Wed, 15 February 2012 10:29 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
And where do you get the errors. In the editor or in the workflow
Re: Errors in XPAND [message #799054 is a reply to message #799012] Wed, 15 February 2012 11:37 Go to previous messageGo to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
complete template is this:

«IMPORT org::xtext::example::mydsl3::myDsl»

«EXTENSION templates::Extensions»
«DEFINE main FOR Entity1»
«FILE name+".java"»

This is Entity1
«EXPAND test FOREACH ((Model)eContainer).entity2»

«ENDFILE-»
«ENDDEFINE»

«DEFINE test FOR Entity2»

«name» «prop2»

«ENDDEFINE»

workflow is this:


module workflow.MyDslGenerator

import org.eclipse.emf.mwe.utils.*

var targetDir = "src-gen"
var fileEncoding = "Cp1254"
var modelPath = "src/model"

Workflow {

component = org.eclipse.xtext.mwe.Reader {
// lookup all resources on the classpath
// useJavaClassPath = true

// or define search scope explicitly
path = modelPath

// this class will be generated by the xtext generator
register = org.xtext.example.mydsl.MyDslStandaloneSetup {}
load = {
slot = "entity1"
type = "Entity1"
}
}

component = org.eclipse.xpand2.Generator {
expand = "templates::Template::main FOREACH entity1"
outlet = {
path = targetDir
}
fileEncoding = fileEncoding
}
}

The errors in both editor and workflow



Re: Errors in XPAND [message #799064 is a reply to message #799054] Wed, 15 February 2012 11:54 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Sorry you actually miss the () in econtainer()
Re: Errors in XPAND [message #799072 is a reply to message #799064] Wed, 15 February 2012 12:12 Go to previous messageGo to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
I guess I made a mistake while I was copying because it is not missing in my codes. The same errors are still same:(

[Updated on: Wed, 15 February 2012 12:12]

Report message to a moderator

Re: Errors in XPAND [message #799114 is a reply to message #799072] Wed, 15 February 2012 13:12 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Hi still cannot reproduce this. Can you once more post template and
grammar and make sure you use javsbeansmetamodel in editor and
workflow. And can you once more post the error message and ensure
that you call the eContainer () operation and not the eContainer
property
Re: Errors in XPAND [message #799139 is a reply to message #799114] Wed, 15 February 2012 13:45 Go to previous messageGo to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
Thanks for your interest. I am sending my codes from beginnig:

my xtext file:
grammar org.xtext.example.mydsl4.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl4/MyDsl"



Model:
entity1+=Entity1
entity2+=Entity2*;

Entity1:
'Entity1' name=ID ';';

Entity2:
'Entity2' name=ID prop2=ID ';';

instance model:
Entity1 name1;
Entity2 name2 properties;


template file:


«IMPORT org::xtext::example::mydsl3::myDsl»

«EXTENSION templates::Extensions»

«DEFINE main FOR Entity1»
«FILE name+".java"»


ENTITY1

«EXPAND test FOREACH ((Model)eContainer()).entity2»
«ENDFILE-»

«ENDDEFINE»

«DEFINE main FOR Entity2»
«FILE name+".xml"»

ENTITY2


«ENDFILE-»
«ENDDEFINE»

Generator file:

module workflow.MyDslGenerator

import org.eclipse.emf.mwe.utils.*

var targetDir = "src-gen"
var fileEncoding = "Cp1254"
var modelPath = "src/model"

Workflow {

component = org.eclipse.xtext.mwe.Reader {
// lookup all resources on the classpath
// useJavaClassPath = true

// or define search scope explicitly
path = modelPath

// this class will be generated by the xtext generator
register = org.xtext.example.mydsl4.MyDslStandaloneSetup {}
load = {
slot = "entity1"
type = "Entity1"
}
}

component = org.eclipse.xpand2.Generator {
expand = "templates::Template::main FOREACH entity1"
outlet = {
path = targetDir
}
fileEncoding = fileEncoding
}
}


Re: Errors in XPAND [message #799140 is a reply to message #799139] Wed, 15 February 2012 13:45 Go to previous messageGo to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
and this is the console:

0 [main] DEBUG org.eclipse.xtext.mwe.Reader - Resource Pathes : [src/model]
4 [main] INFO org.eclipse.xpand2.Generator - No meta models configured, using JavaBeans as default.
192 [main] DEBUG xt.validation.ResourceValidatorImpl - Syntax check OK! Resource: file:/C:/eclipse-xtext-jadex/workspace2/org.xtext.example.mydsl4.generator/src/model/Example.mydsl4
628 [main] ERROR org.eclipse.xpand2.Generator - Error in Component of type org.eclipse.xpand2.Generator:
EvaluationException : No Definition 'templates::Template::main for org::xtext::example::mydsl4::myDsl::impl::Entity1Impl' found!
[23,48] on line 1 'EXPAND templates::Template::main FOREACH entity1'

630 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Problems running workflow workflow.MyDslGenerator: No Definition 'templates::Template::main for org::xtext::example::mydsl4::myDsl::impl::Entity1Impl' found!
java.lang.RuntimeException: Problems running workflow workflow.MyDslGenerator: No Definition 'templates::Template::main for org::xtext::example::mydsl4::myDsl::impl::Entity1Impl' found!
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:82)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
Caused by: org.eclipse.emf.mwe.core.WorkflowInterruptedException: No Definition 'templates::Template::main for org::xtext::example::mydsl4::myDsl::impl::Entity1Impl' found!
at org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflowComponent.invokeInternal(AbstractExpressionsUsingWorkflowComponent.java:247)
at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:31)
at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:80)
... 3 more
Re: Errors in XPAND [message #799147 is a reply to message #799140] Wed, 15 February 2012 13:51 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Hi first the error message now is different than before and mydsl3 is
not mydsl4
Re: Errors in XPAND [message #799717 is a reply to message #799147] Thu, 16 February 2012 08:15 Go to previous messageGo to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
I opened a new project now and copy everything to mydsl 5. The results are the same. :


1 [main] DEBUG org.eclipse.xtext.mwe.Reader - Resource Pathes : [src/model]
5 [main] INFO org.eclipse.xpand2.Generator - No meta models configured, using JavaBeans as default.
239 [main] DEBUG xt.validation.ResourceValidatorImpl - Syntax check OK! Resource: file:/C:/eclipse-xtext-jadex/workspace2/org.xtext.example.mydsl5.generator/src/model/Example.mydsl5
1356 [main] ERROR org.eclipse.xpand2.Generator - Error in Component of type org.eclipse.xpand2.Generator:
EvaluationException : No Definition 'test for org::xtext::example::mydsl5::myDsl::impl::Entity2Impl' found!
templates::Template.xpt[138,49] on line 11 'EXPAND test FOREACH (Model)eContainer().entity2'
[23,48] on line 1 'EXPAND templates::Template::main FOREACH entity1'

1358 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Problems running workflow workflow.MyDslGenerator: No Definition 'test for org::xtext::example::mydsl5::myDsl::impl::Entity2Impl' found!

java.lang.RuntimeException: Problems running workflow workflow.MyDslGenerator: No Definition 'test for org::xtext::example::mydsl5::myDsl::impl::Entity2Impl' found!
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:82)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
Caused by: org.eclipse.emf.mwe.core.WorkflowInterruptedException: No Definition 'test for org::xtext::example::mydsl5::myDsl::impl::Entity2Impl' found!
at org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflowComponent.invokeInternal(AbstractExpressionsUsingWorkflowComponent.java:247)
at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:31)
at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:80)
... 3 more
Re: Errors in XPAND [message #799771 is a reply to message #799717] Thu, 16 February 2012 09:42 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 354
Registered: July 2009
Location: Dortmund
Senior Member

1) The import must be for mydsl5

«IMPORT org::xtext::example::mydsl5::myDsl»

«EXTENSION templates::Extensions»

«DEFINE main FOR Entity1»
«FILE name+".java"»


2) the folder "templates" must be on the root of your classpath. The template "Template.xpt" should be in there.
To check this: Open the Navigator view, the output folder is by default "bin", so it must be
- projectroot
+- bin
+- templates
+- Template.xpt



Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Errors in XPAND [message #799784 is a reply to message #799771] Thu, 16 February 2012 10:01 Go to previous messageGo to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
Hi,
Thanks for replies.

1. I fixed import statement and it is the same as you mentioned.
2. "templates" folder is on the root of my classpath

If I delete the «EXPAND test FOREACH ((Model)eContainer()).entity2» line from my template file, there is not any errors. Everything is Ok. When I add this line, above errors are occured. So, the problems resource is this line but I could not understand why
Re: Errors in XPAND [message #799800 is a reply to message #799717] Thu, 16 February 2012 10:26 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
sure you have a

Define test for Entity


In your former post it was a

Define main for Entity2
Re: Errors in XPAND [message #799801 is a reply to message #799800] Thu, 16 February 2012 10:27 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Sorry I meant

Define test for Entity2
Re: Errors in XPAND [message #799874 is a reply to message #799801] Thu, 16 February 2012 12:23 Go to previous messageGo to next message
terry tonery is currently offline terry tonery
Messages: 34
Registered: February 2012
Member
It is fixed now! Thank you very much!!!

[Updated on: Thu, 16 February 2012 12:31]

Report message to a moderator

Re: Errors in XPAND [message #799882 is a reply to message #799874] Thu, 16 February 2012 12:30 Go to previous message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Why don't you call EXPAND main FOR ...
Previous Topic:Exception generation
Next Topic:[Acceleo] running an installed module from workbench
Goto Forum:
  


Current Time: Fri Oct 24 14:47:52 GMT 2014

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

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