Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Xtend generator fails- attributes are not resolved(Xtend generator fails- attributes are not resolved)
Xtend generator fails- attributes are not resolved [message #1798060] Mon, 12 November 2018 02:23 Go to next message
Eclipse UserFriend
I followed this very good training material for advanced Xtext usage:

J.Hooman/DSL/AdvancedXtextManual.pdf

(I was not allowed to include the full hyperlink for some reason)

The problem starts in chapter 3.3.3
References between the two DSL files in runtime workspage works as in the example but the generator does not work- it just prints the text from the code:

Person: <<person.name>>
Greetings to: <<FOR greeting : person.greetings>> <<greeting.person.name>> (<<greeting.person.greetings.size>>)<<ENDFOR>>
<<FOR imp: person.imports>>
<<toText(imp)>>
<<ENDFOR>>

I have doublechecked the code several times to make sure it match the example.
MyDslGenerator.xtend looks as follows and match the example:

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

import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
import org.xtext.example.mydsl.myDsl.Person
import org.xtext.example.mydsl.myDsl.Import

/**
* Generates code from your model files on save.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
class MyDslGenerator extends AbstractGenerator {

override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
val root = ResourceUtils.resourceToEObject(resource) as Person;
fsa.generateFile(resource.getURI().lastSegment + '.txt', toText(root));
}

def static toText(Person person)
'''
Person: <<person.name>>
Greetings to: <<FOR greeting : person.greetings>> <<greeting.person.name>> (<<greeting.person.greetings.size>>)<<ENDFOR>>
<<FOR imp: person.imports>>
<<toText(imp)>>
<<ENDFOR>>

'''

def static toText(Import imp) {
val Person importedPerson = ResourceUtils.resourceToEObject(ResourceUtils.openImport(imp.eResource, imp.importURI)) as Person;
return
'''
Imported file: <<imp.importURI>>:
<<IF importedPerson == null>>
File cannot be opened.
<<ELSE>>
Number of greetings: <<importedPerson.greetings.size>>
<<ENDIF>>
'''
}
}

Should I file a bug? Which forum in that case?

Br Johan
Re: Xtend generator fails- attributes are not resolved [message #1798241 is a reply to message #1798060] Wed, 14 November 2018 10:51 Go to previous message
Eclipse UserFriend
you should use french quotation marks «» instead of <<>>
Previous Topic:Error: The code for the static initializer is exceeding the 65535 bytes limit
Next Topic:Element Rename in XText 2.14
Goto Forum:
  


Current Time: Fri Jun 20 01:20:34 EDT 2025

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

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

Back to the top