Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8542559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:05:56+00:00 2026-06-11T12:05:56+00:00

I am building a code generator in XTend where I already have an input

  • 0

I am building a code generator in XTend where I already have an input model and meta model. That is, I use ATL to generate the input model for my XTend code generator (as part of a transformation sequence to gradually lower the abstraction level, instead of at once; this is the reason i’m not using xtext to create the syntax).

So to be very clear, my input model for the code generator is a file in XMI format and NOT in the grammar of the xtext project (not even using that)! And i think this is causing me problems/confusion.

I created a new XText project using Existing models, right clicked on the .text file, run as , generate artefacts, and then i did the same for the mwe2 file.

What is the next step, am I doing it right? How can I start my code generator? All the examples are from the POV that you use XText to create a DSL. I have an EMF meta model, and an XMI based instance of that. How to process that further using XTend?

Any hint or pointer to a tutorial is helpful.

Solution:

The solution was as Sven suggested in my accepted answer, but also I would like to note that you need to use a genmodel to generate Java artifacts from your meta model. This link shows how: http://www.vogella.com/articles/EclipseEMF/article.html , see section 4. This may appear all too logical, but i think it’s worth noting anyway.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:05:57+00:00Added an answer on June 11, 2026 at 12:05 pm

    If you have an XMI and just want to generate code from it, you don’t need Xtext at all.
    Just start with a Java project (I’d use a plug-in project, to reuse the dependency management) and start coding:

    import org.eclipse.emf.common.util.URI
    import org.eclipse.emf.ecore.EPackage
    import org.eclipse.emf.ecore.resource.Resource$Factory$Registry
    import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
    import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl
    
    class MyCodeGenerator {
    
      def static void main(String[] args) {
        new MyCodeGenerator().generate("mymodel.xmi")
      }
    
      def generate(String file) {
        doEMFSetup
        val resourceSet = new ResourceSetImpl
        val resource = resourceSet.getResource(URI.createURI(file), true)
        for (content : resource.contents) {
          generateCode(content)
        }
      }
    
      def dispatch generateCode(MySpecialType it) '''
        public class «name» {
          «FOR member : members»
          «ENDFOR»
        }
      '''
    
      def dispatch generateCode(MyMember it) '''
        private «type» «name»;
        ...
      '''
    
      def doEMFSetup() {
    //    EPackage$Registry.INSTANCE.put(MyPackage.eINSTANCE.nsURI, MyPackage.eINSTANCE)
        Resource$Factory.Registry.INSTANCE.extensionToFactoryMap.put("xmi", new XMIResourceFactoryImpl);
      }
    
    }
    

    The dependencies you need to add to your Manifest :

    Require-Bundle: org.eclipse.xtend.lib,
     com.google.guava,
     org.eclipse.xtext.xbase.lib,
     org.eclipse.emf.common,
     org.eclipse.emf.ecore,
     org.eclipse.emf.ecore.xmi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently building a code generator, which aims to generate boiler plate for me
When building code like this: <script type=text/javascript src=<%=ResolveUrl(~/js/js.js)%>></script> or <input type=image src=<%=ResolveUrl(~/img/submit.png)%> /> Should
More than one time I have encountered the following problem when building code with
I've been using Visual Studio's property sheets for building my code and I have
I am building a product, and I need a way to generate code at
I have a project with classes in a project that I am building in
I have a web app that I am building using asp mvc with nhiberante
Building a python fuse fs, in my readdir generator the first line of code
I'm building a dynamic code generator and using regular expressions. Given this block of
I'm building a category manager via database. The following PHP generates the code I'll

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.