Skip to main content



      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 03:07 Go to next message
Eclipse UserFriend
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 15:44 Go to previous messageGo to next message
Eclipse UserFriend
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;
	}
	
}
Re: Referring to existing Java methods using Xbase [message #1018606 is a reply to message #1018408] Thu, 14 March 2013 03:20 Go to previous message
Eclipse UserFriend
Thank you very much!
Previous Topic:Templates auto format
Next Topic:Error running workflow : Couldn't find extension
Goto Forum:
  


Current Time: Wed Jul 23 14:31:46 EDT 2025

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

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

Back to the top