|
Re: How to handle overloaded methods with Custome xbase scope provider [message #1225570 is a reply to message #1225012] |
Mon, 30 December 2013 07:00 |
Gayan Perera Messages: 6 Registered: July 2013 |
Junior Member |
|
|
I found the solution for this after having a close look at existing DSL implementations like in jnario (jnario.org). I did some changes in my DSL as follows so that simple method names and methods full signature are identified.
RemoteMethod:
'method:' op=[types::JvmOperation|Method]
;
Method:
ID ('(' (TypeName (',' TypeName)*)? ')')?
;
TypeName:
ID ('.' ID)* ('<' TypeRef (',' TypeRef)* '>')? ('['']')?
;
TypeRef:
('?')? ('extends' | 'super')? TypeName
;
And modified the scope provider as follows.
@Override
public IScope getScope(EObject context, EReference reference) {
if (context instanceof RemoteMethod && "op".equals(reference.getName())) {
final ClientManager cm = (ClientManager) context.eContainer();
if (cm.getRemote().getType() instanceof JvmDeclaredType) {
final Iterable<JvmOperation> operations = ((JvmDeclaredType) cm
.getRemote().getType()).getDeclaredOperations();
IScope simpleNames = Scopes.scopeFor(operations,
new Function<JvmOperation, QualifiedName>() {
@Override
public QualifiedName apply(JvmOperation input) {
return QualifiedName.create(input
.getSimpleName());
}
}, IScope.NULLSCOPE);
return Scopes.scopeFor(operations,
new Function<JvmOperation, QualifiedName>() {
public QualifiedName apply(JvmOperation from) {
// Splitting it important because this is how the qualified name is created by the xbase linker.
return QualifiedName.create(SignatureUtil
.simpleSignatureOf(from).split("\\."));
}
}, simpleNames);
}
}
return super.getScope(context, reference);
}
Hope this might help to some one else as well
|
|
|
Powered by
FUDForum. Page generated in 0.01816 seconds