My Operation Definitions takes parameters, a XBlockExpression(as body), and explicit return type optionally.
I want to let my user dosn't have to declare return type explicitly like xtend.
below codes do infer return type of my operation:
// have explicit return type
if(op.type != null){
return op.type
}
// using Type Provider
var result = op.body.getType(true)
if(result == null || result.simpleName == "void"){
result = evalBlock.getCommonReturnType(true)
if(result == null){
result = TypesFactory::eINSTANCE.createJvmAnyTypeReference
}
}
return result.cloneWithProxies
the problem is when "return expression" refers parameters,
ITypeProvider can't evaluate actual return type
because of there is no type declaration of parameters in XBlockExpression.
So I tried like this:
var evalBlock = EcoreUtil2::cloneWithProxies(op.body) as XBlockExpression;
for(eachParm : op.params){
var vd = XbaseFactory::eINSTANCE.createXVariableDeclaration
vd.setType(eachParm.typeForIdentifiable.cloneWithProxies)
vd.setName(eachParm.simpleName)
}
But TypeProvider have throw an exception which says this block does not belongs to an resource.
So, How can I infer return type?
[Updated on: Tue, 06 March 2012 03:33]
Report message to a moderator