Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to handle overloaded methods with Custome xbase scope provider
How to handle overloaded methods with Custome xbase scope provider [message #1225012] Sat, 28 December 2013 12:12 Go to next message
Gayan Perera is currently offline Gayan PereraFriend
Messages: 6
Registered: July 2013
Junior Member
I have a scope provider which i have written to handle jvmOperation in my DSL.

DSL
RemoteMethod:
	'method:' op=[types::JvmOperation]
;


Scope Provider
	@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();
				final EList<IEObjectDescription> descriptions = new BasicEList<IEObjectDescription>();

				for (JvmOperation jvmOperation : operations) {
					descriptions.add(EObjectDescription.create(
							jvmOperation.getSimpleName(),
							jvmOperation));
				}

				return MapBasedScope
						.createScope(IScope.NULLSCOPE, descriptions);
			}
		}
		return super.getScope(context, reference);
	}


This seems to work for methods which are not overloaded. But as soon as i have a overloaded method it always refers to the first method. Is there a way i have expand this to support overloaded methods using the identifier of the operation ?
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 Go to previous message
Gayan Perera is currently offline Gayan PereraFriend
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 Smile
Previous Topic:[MWE2] Running workflow from plugin, custom components not found
Next Topic:Writing the contents of xtext editor to some other view
Goto Forum:
  


Current Time: Fri Apr 19 17:09:08 GMT 2024

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

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

Back to the top