[SOLVED, Xtext/Xpand] Code generation [message #1129368] |
Tue, 08 October 2013 15:05  |
Eclipse User |
|
|
|
Hi, i'm trying to build a very simple code generator. This is the xtext grammar:
grammar org.xtext.example.mydsl.Entity with org.eclipse.xtext.common.Terminals
generate entity "..."
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!';
and in the generator xtend file i have this code:
class EntityGenerator implements IGenerator
{
override void doGenerate(Resource resource, IFileSystemAccess fsa)
{
(error 1) for(g : resource.allContents.toIterable.filter(Greeting))
{
(error 2) fsa.generateFile("documento.txt",g.compile)
}
}
def compile(Greeting g) '''
<Greeting>
«g.name»
<\Greeting>
'''
}
I get these two errors:
(1) The method or field Greeting is undefined for the type EntityGenerator
(2) Type mismatch: cannot convert from EObject to Greeting
A solution to this problem?
Bye!
[Updated on: Wed, 09 October 2013 07:08] by Moderator Report message to a moderator
|
|
|
|
Re: [Xtext/Xpand] Code generation [message #1130023 is a reply to message #1129368] |
Wed, 09 October 2013 06:50   |
Eclipse User |
|
|
|
yes, these are my imports:
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.xtext.generator.IGenerator
import org.eclipse.xtext.naming.IQualifiedNameProvider
import org.xtext.example.mydsl.entity.Greeting
|
|
|
Re: [Xtext/Xpand] Code generation [message #1130040 is a reply to message #1130023] |
Wed, 09 October 2013 07:07   |
Eclipse User |
|
|
|
Ok i solved. This is the problem: i followed the tutorial on the xtext website, which is not update. The snippet with errors in the website is
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
for(e: resource.allContents.toIterable.filter(Entity)) {
fsa.generateFile(
e.fullyQualifiedName.toString("/") + ".java",
e.compile)
}
}
but in the eclipse help, the snippet is
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
for(e: resource.allContents.toIterable.filter(typeof(Entity))) {
fsa.generateFile(
e.fullyQualifiedName.toString("/") + ".java",
e.compile)
}
}
the change is inside the for loop. There was a missing typeof(...).
|
|
|
|
Powered by
FUDForum. Page generated in 0.04019 seconds