Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » addArrayTypeDimension for JvmUnknownTypeReference(I try to generate an array type for a type that is generated by the generator)
addArrayTypeDimension for JvmUnknownTypeReference [message #1690860] Tue, 31 March 2015 15:57 Go to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
I have the following code in my ModelIInferrer:
	def dispatch void infer(TableDefinition element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
		val tableName = element.name // == "Chapter"
		val classPrefix = "Parcelable"
                ...
				val returnTypeName = classPrefix + tableName
				val returnType = typeRef(returnTypeName)
				members += element.toMethod("newArray", addArrayTypeDimension(returnType))[
					parameters += element.toParameter("size", typeRef(int))
					body = '''
						return new ┬źreturnTypeName┬╗[size];
					'''
				]

And I get the following generated Code:
    
    public Object/* type is 'null' */ newArray(final int size) {
      return new ParcelableChapter[size];
    }

And should be the following generated Code:
    
    public ParcelableChapter[] newArray(final int size) {
      return new ParcelableChapter[size];
    }


Can anybody tell my what I am doing wrong ?
Re: addArrayTypeDimension for JvmUnknownTypeReference [message #1690865 is a reply to message #1690860] Tue, 31 March 2015 16:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13882
Registered: July 2009
Senior Member
Where comes the return type from. How do you inferr it?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: addArrayTypeDimension for JvmUnknownTypeReference [message #1690869 is a reply to message #1690865] Tue, 31 March 2015 16:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13882
Registered: July 2009
Senior Member
If you really want to generate a type that is not there you may use "abc.Xyz[]".typeRef
But id try to avoid that


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: addArrayTypeDimension for JvmUnknownTypeReference [message #1690871 is a reply to message #1690869] Tue, 31 March 2015 16:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13882
Registered: July 2009
Senior Member
Or even better have your own possiblyUnknownType ref that does create a real arrraytyyperef if the type already exists

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: addArrayTypeDimension for JvmUnknownTypeReference [message #1690893 is a reply to message #1690869] Tue, 31 March 2015 19:35 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
Christian Dietrich wrote on Tue, 31 March 2015 12:37
If you really want to generate a type that is not there you may use "abc.Xyz[]".typeRef
But id try to avoid that

Thank you, this worked for me. What are the reasons for avoiding this approach?
Re: addArrayTypeDimension for JvmUnknownTypeReference [message #1690895 is a reply to message #1690893] Tue, 31 March 2015 19:44 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13882
Registered: July 2009
Senior Member
dont know how good this works out with type inference at other places.
thus i asked why you have that unknowntyperef at all.
if the type is inferred as well this should imho not happen


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Delete me
Next Topic:xtext project creation programmatically
Goto Forum:
  


Current Time: Wed Apr 14 15:13:03 GMT 2021

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

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

Back to the top