Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext Code generator Problem
Xtext Code generator Problem [message #1023953] Mon, 25 March 2013 14:33 Go to next message
d 627 is currently offline d 627Friend
Messages: 28
Registered: March 2013
Junior Member
Hi everyone

I'm new in xtext. and I needed for the project of my tesis; I've been doing the 15 minutes tutorial but with several problems with the code generator. This is what I've done until now:

/*
* generated by Xtext
*/
package org.xtext.example.mydsl.generator

import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IGenerator
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.xtext.naming.IQualifiedNameProvider
import org.xtext.example.mydsl.dmodel.Entity
import org.xtext.example.mydsl.dmodel.Feature

import com.google.inject.Inject

class DomainmodelGenerator implements IGenerator {

@Inject extension IQualifiedNameProvider nameProvider

override void doGenerate(Resource resource, IFileSystemAccess fsa) {
for(e: resource.allContents.toIterable.filter(typeof(Entity))) {
fsa.generateFile(
e.fullyQualifiedName.toString.replace(".", "/") + ".java",
e.compile)
}
}

def compile(Entity e) '''
«IF e.eContainer != null»
package «e.eContainer.fullyQualifiedName»;
«ENDIF»

public class «e.name» «IF e.superType != null»
extends «e.superType.fullyQualifiedName» «ENDIF»{
«FOR f:e.features»
«f.compile»
«ENDFOR»
}
'''

def compile(Feature f) '''
private «f.type.fullyQualifiedName» «f.name»;

public «f.type.fullyQualifiedName» get«f.name.toFirstUpper»() {
return «f.name»;
}

public void set«f.name.toFirstUpper»(«f.type.fullyQualifiedName» «f.name») {
this.«f.name» = «f.name»;
}
'''
}

I got 2 problems with 2 lines of the code
1) e.fullyQualifiedName.toString.replace(".", "/") + ".java". The editor tells: "The method fullyQualifiedName is undefined for the type DomainmodelGenerator" and "Couldn't resolve reference to JvmIdentifiableElement '+'"

2) e.compile : "The method compile is undefined for the type DomainmodelGenerator"
But in theory I've defined this methods in the same file.

I don't know if the problem is collegated whit the libraries that I have to import. In theory the steps I've done are similar to the tutorial but it seems that this one is refered to a previous version and some things have chance.

Thanks a lot for your cooperation.

Re: Xtext Code generator Problem [message #1024371 is a reply to message #1023953] Tue, 26 March 2013 07:00 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i actually cannot reproduce this. (using Xtext 2.4.0)
can you share your complete projects?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:WrappedException: The path is unmapped
Next Topic:Xtext: Referencing Elements of one DSL from another DSL Problem
Goto Forum:
  


Current Time: Fri Apr 19 08:14:40 GMT 2024

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

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

Back to the top