Skip to main content



      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 11:57 Go to next message
Eclipse UserFriend
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 12:23 Go to previous messageGo to next message
Eclipse UserFriend
Where comes the return type from. How do you inferr it?
Re: addArrayTypeDimension for JvmUnknownTypeReference [message #1690869 is a reply to message #1690865] Tue, 31 March 2015 12:37 Go to previous messageGo to next message
Eclipse UserFriend
If you really want to generate a type that is not there you may use "abc.Xyz[]".typeRef
But id try to avoid that
Re: addArrayTypeDimension for JvmUnknownTypeReference [message #1690871 is a reply to message #1690869] Tue, 31 March 2015 12:39 Go to previous messageGo to next message
Eclipse UserFriend
Or even better have your own possiblyUnknownType ref that does create a real arrraytyyperef if the type already exists
Re: addArrayTypeDimension for JvmUnknownTypeReference [message #1690893 is a reply to message #1690869] Tue, 31 March 2015 15:35 Go to previous messageGo to next message
Eclipse UserFriend
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 15:44 Go to previous message
Eclipse UserFriend
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
Previous Topic:Delete me
Next Topic:xtext project creation programmatically
Goto Forum:
  


Current Time: Wed Jul 23 19:27:53 EDT 2025

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

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

Back to the top