Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 08:58 Go to next message
Ingo Meyer is currently offline Ingo MeyerFriend
Messages: 162
Registered: July 2009
Senior Member
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 09:17 Go to previous messageGo to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
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 09:41 Go to previous messageGo to next message
Ingo Meyer is currently offline Ingo MeyerFriend
Messages: 162
Registered: July 2009
Senior Member
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 21:12 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 83
Registered: January 2016
Location: Kiel
Member

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 17:25 Go to previous message
Ingo Meyer is currently offline Ingo MeyerFriend
Messages: 162
Registered: July 2009
Senior Member
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: Fri Sep 20 21:47:49 GMT 2024

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

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

Back to the top