Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to generate a field with a generic type
How to generate a field with a generic type [message #903769] Sat, 25 August 2012 17:49 Go to next message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
Hi,

I'm using the following code to generate a field:
val mapType = entity.newTypeRef(typeof(Map))
members += entity.toField("columnValues", mapType) [
	setInitializer [
		append('''new HashMap<«entity.name»,String>()''')
	]
]

That gives me:
 private Map<?,?> columnValues = new HashMap<Customer,String>();

But I would like to have:
 private Map<Customer,String> columnValues = new HashMap<Customer,String>();


And I would like to generate the import statement for the HashMap.

Is this possible ?

Regards
Roger
Re: How to generate a field with a generic type [message #903772 is a reply to message #903769] Sat, 25 August 2012 18:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13357
Registered: July 2009
Senior Member
Hi,

what about

val mapType = entity.newTypeRef(typeof(Map), newTypeRef, entity.newTypeRef(typeof(String)))


~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to generate a field with a generic type [message #903775 is a reply to message #903772] Sat, 25 August 2012 19:35 Go to previous messageGo to next message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
Hi,

thanks a lot. The generic type is generated but how do I generate the import ?


Regards
Roger
Re: How to generate a field with a generic type [message #903781 is a reply to message #903775] Sat, 25 August 2012 21:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13357
Registered: July 2009
Senior Member
setInitializer [
		append('''new java.util.HashMap<«entity.name»,String>()''')
	]


or

setInitializer [
		imports.add("java.util.HashMap")
		append('''new HashMap<«entity.name»,String>()''')	
	]


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to generate a field with a generic type [message #903837 is a reply to message #903781] Sun, 26 August 2012 06:46 Go to previous messageGo to next message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
The import statement is ignored. At least in the 2.3.1 version I'm using here.

setInitializer [
		imports.add("java.util.HashMap")
		append('''new HashMap<«entity.name»,String>()''')	
]


Regards
Roger
Re: How to generate a field with a generic type [message #903840 is a reply to message #903837] Sun, 26 August 2012 08:05 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13357
Registered: July 2009
Senior Member
setInitializer [
		append("new ").append(entity.newTypeRef(typeof(HashMap)).type)
		.append('''<«entity.name»,String>()''')	
	]


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:New Project Wizard without use XtextNewProjectWizard ?
Next Topic:Books on Xtext
Goto Forum:
  


Current Time: Wed Feb 19 19:24:12 GMT 2020

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

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

Back to the top