Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Referring to existing Java methods using Xbase
Referring to existing Java methods using Xbase [message #1018110] Wed, 13 March 2013 07:07 Go to next message
Oren Mishali is currently offline Oren MishaliFriend
Messages: 15
Registered: March 2013
Junior Member
Hi all,

Consider this example DSL code:

logger base.MyClass {
log method base.MyClass.foo();
}

I understand that it is possible to use Xbase for referring to an existing Java class, i.e., by using JvmTypeReference. So the user enjoys auto-completion for the class' name, and static checking.

Is there a similar way for referring to an existing Java method defined elsewhere in the class path (e.g., base.MyClass.foo)? My experience shows that JvmTypeReference allows to refer only to class level types and not to methods.

Thanks!
Oren

Re: Referring to existing Java methods using Xbase [message #1018408 is a reply to message #1018110] Wed, 13 March 2013 19:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13359
Registered: July 2009
Senior Member
Hi i think using that syntax it will be hard (ambiguity)
but what about something like (quick and dirty)

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase

import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	ref=JvmTypeReference "::" op=[types::JvmOperation];


public class MyDslScopeProvider extends XbaseScopeProvider {

	public IScope getScope(org.eclipse.emf.ecore.EObject context, EReference reference) {
		if (reference == MyDslPackage.Literals.MODEL__OP && context instanceof Model) {
			return scope_Model_op((Model) context, reference);
		}
		return super.getScope(context, reference);
	};

	IScope scope_Model_op(Model ctx, EReference ref) {
		if (ctx.getRef().getType() instanceof JvmDeclaredType) {
			Iterable<JvmOperation> declaredOperations = ((JvmDeclaredType)ctx.getRef().getType()).getDeclaredOperations();
			return Scopes.scopeFor(declaredOperations,
					
					new Function<JvmOperation, QualifiedName>() {
					public QualifiedName apply(JvmOperation op) {
						return QualifiedName.create(op.getSimpleName());
					}
				
					}, IScope.NULLSCOPE);
		}
		return IScope.NULLSCOPE;
	}
	
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Referring to existing Java methods using Xbase [message #1018606 is a reply to message #1018408] Thu, 14 March 2013 07:20 Go to previous message
Oren Mishali is currently offline Oren MishaliFriend
Messages: 15
Registered: March 2013
Junior Member
Thank you very much!
Previous Topic:Templates auto format
Next Topic:Error running workflow : Couldn't find extension
Goto Forum:
  


Current Time: Mon Feb 24 12:24:57 GMT 2020

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

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

Back to the top