|
Re: Referring to existing Java methods using Xbase [message #1018408 is a reply to message #1018110] |
Wed, 13 March 2013 19:44 |
|
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;
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.03356 seconds