Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 326755

Summary: Xpand template bug in Xtext User Guide
Product: [Modeling] TMF Reporter: Philip May <eniak.info>
Component: XtextAssignee: Jan Koehnlein <jan>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eniak.info, jan, sven.efftinge, tmf.xtext-inbox
Version: unspecifiedFlags: sven.efftinge: indigo+
Target Milestone: M3   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Philip May CLA 2010-10-01 05:42:36 EDT
Build Identifier: M20100909-0800

Xtext User Guide has a Xpand template with a bug.
It is in this section:
http://www.eclipse.org/Xtext/documentation/1_0_0/xtext.html#getting-started-xpand

The template you suggest ist:
«IMPORT org::eclipse::xtext::example::domainmodel»
«EXTENSION templates::Extensions»

«DEFINE main FOR Entity-»
«FILE qualifiedName().replaceAll("\\.","/")+".java"-»
package «packageName()»;

public class «name» {
  «EXPAND property FOREACH features»
}
«ENDFILE»
«ENDDEFINE»

«DEFINE property FOR Feature»
  private «type.referenced.qualifiedName()» «name»;
  
  public void set«name.toFirstUpper()»(
       «type.referenced.qualifiedName()» «name») {
    this.«name» = «name»;
  } 
  public «type.referenced.qualifiedName()» get«name.toFirstUpper()»() {
    return «name»;
  } 
«ENDDEFINE»

but this template does not recognize the extends expression of the language.
That means that Speaker does not extend Person when you generate the code.

The teamplate should be modified to this:

«IMPORT org::eclipse::xtext::example::domainmodel»
«EXTENSION templates::Extensions»

«DEFINE main FOR Entity-»
«FILE qualifiedName().replaceAll("\\.","/")+".java"-»
package «packageName()»;

public class «name»«IF superType != null» extends «superType.name»«ENDIF» {
  «EXPAND property FOREACH features»
}
«ENDFILE»
«ENDDEFINE»

«DEFINE property FOR Feature»
  private «type.referenced.qualifiedName()» «name»;
  
  public void set«name.toFirstUpper()»(
       «type.referenced.qualifiedName()» «name») {
    this.«name» = «name»;
  } 
  public «type.referenced.qualifiedName()» get«name.toFirstUpper()»() {
    return «name»;
  } 
«ENDDEFINE»


Reproducible: Always

Steps to Reproduce:
1. Do the tutorial: http://www.eclipse.org/Xtext/documentation/1_0_0/xtext.html#getting-started-xpand
2. generate the java classes and look at the Speaker class
3. notice that it does not extend Person
Comment 1 Jan Koehnlein CLA 2010-10-07 10:20:26 EDT
Fixed in HEAD.
Comment 2 Karsten Thoms CLA 2017-09-19 17:29:56 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 3 Karsten Thoms CLA 2017-09-19 17:41:20 EDT
Closing all bugs that were set to RESOLVED before Neon.0