Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Inferr 1. type parameter of inferredType( myExpression )
Inferr 1. type parameter of inferredType( myExpression ) [message #1723044] Thu, 11 February 2016 03:58 Go to next message
Eclipse UserFriend
Hi,

in my inferrer I need to set the first type parameter of an inferrerType as a method parameter. Is there a way to do this?
Example:
The inferred type of my expression will be: List<Integer>, so I need a parameter of type Integer. In the inferrer I just have the expression so I need to inferr: toParameter( it, 'paramName', inferrerType( myExpression ) ) which is wrong.
Something like this would be needed:
toParameter( it, 'paramName', inferrerType( myExpression, 0 ) ), where 0 will indicate to use the first generic argument of inferred type.

Any ideas or is an enhancement request needed?

Thanks
~Ingo
Re: Inferr 1. type parameter of inferredType( myExpression ) [message #1723048 is a reply to message #1723044] Thu, 11 February 2016 04:17 Go to previous messageGo to next message
Eclipse UserFriend
Dear Ingo.

Have you tried something like the following code?

var typeReference = inferredType(myExpression)
var type = typeReference.type
var paramType = typeRef(Object)
if (type instanceof JvmTypeParameterDeclarator) {
    var pType = type.typeParameters.get(0)
    paramType = cloneWithProxis(typeRef(pType))
}
toParameter(it, 'paramName', paramType)


Stéphane.
Re: Inferr 1. type parameter of inferredType( myExpression ) [message #1723050 is a reply to message #1723048] Thu, 11 February 2016 04:41 Go to previous messageGo to next message
Eclipse UserFriend
Hi Stephane,

thanks for the code. I tried it, but this will not wor as the call of "typeReference.type" fails with an exception "equivilent can not be computed". I think no method of inferredType() can be called while in the inferrer phase.
So I think this is a missing use case.

any other ideas?
Re: Inferr 1. type parameter of inferredType( myExpression ) [message #1723126 is a reply to message #1723050] Thu, 11 February 2016 16:12 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ingo,

resolving expressions during model inference is not possible (or at least very problematic and will lead to surprising behavior). The reason is that the expressions are resolved against the outside structure, i.e. signatures and the like. So at the time of type inference and overload resolution all signatures must be finalized and no longer changed.
Therefore the method inferrerType(XExpression) really only creates a lazy placeholder which triggers the expression resolution when accessed. We would need to have another placeholder that will return the type argument instead of the type.

Sven
Re: Inferr 1. type parameter of inferredType( myExpression ) [message #1723596 is a reply to message #1723126] Tue, 16 February 2016 12:25 Go to previous message
Eclipse UserFriend
Hi Sven,

thanks for the explanation. This matches what I thought so far. Is this then a feature request to introduce a construct like "inferrerType( myExpression, 0 ) ", where the index is the type parameter of the expression type? Or is that something which can be done by extending the existing xtext version by myself?
Previous Topic:Missing import statement in generated emf classes
Next Topic:Load EObject with all cross-references from file path
Goto Forum:
  


Current Time: Thu Jul 03 09:56:46 EDT 2025

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

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

Back to the top