|
Re: How to reference available methods of a JvmTypeReference (Xbase) [message #1723623 is a reply to message #1723598] |
Tue, 16 February 2016 20:45   |
|
hi,
did you consider a straight forward inferrer?
Model:
calls+=ServiceCall*;
ServiceCall:
'call' type=JvmTypeReference method=XRestrictedFeatureCall;
XRestrictedFeatureCall returns xbase::XExpression:
{xbase::XFeatureCall}
('<' typeArguments+=JvmArgumentTypeReference (',' typeArguments+=JvmArgumentTypeReference)* '>')?
feature=[types::JvmIdentifiableElement|IdOrSuper]
(=>explicitOperationCall?='('
(
featureCallArguments+=XShortClosure
| featureCallArguments+=XExpression (',' featureCallArguments+=XExpression)*
)?
')');
def dispatch void infer(Model element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
acceptor.accept(element.toClass("demo.Demo")) [
var i = 0;
for (call : element.calls) {
i = i + 1
members += call.toField("field"+i, call.type.cloneWithProxies) [
annotations += Inject.annotationRef()
]
val m1 = call.toMethod("executeIntern"+i, inferredType) [
visibility = JvmVisibility.PRIVATE
parameters+=call.toParameter("it", call.type.cloneWithProxies) => [
]
body = call.method
]
members += m1
val ifinal = i
members += call.toMethod("execute"+i, call.method.inferredType) [
body = '''
«IF m1.returnType.qualifiedName != Void.TYPE.typeRef.qualifiedName»return «ENDIF»executeIntern«ifinal»(field«ifinal»);'''
]
}
]
}
(very very naive impl)
you may do some customization to remove stuff like this from the scope
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.01866 seconds