Hi,
yes Xtext has support for Jvm Types. the thing that is problematic
(for code completion) is your synatax that names the getter/setter first and then then Class.
Here is a (syntactically and funtionally)simplified example
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types
Model:
statements += Statement*;
Statement:
SetStatement | GetStatement
;
GetStatement:
"with" class=[types::JvmDeclaredType|FQN] "get" "the" op=[types::JvmOperation]
;
SetStatement:
"with" class=[types::JvmDeclaredType|FQN] "set" "the" op=[types::JvmOperation] "to" value=STRING
;
FQN: ID ("." ID)*;
public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
IScope scope_Statement_op(SetStatement context, EReference ref) {
Iterable<JvmOperation> setters = Iterables.filter(context.getClass_().getDeclaredOperations(), new Predicate<JvmOperation>() {
public boolean apply(JvmOperation op) {
return op.getSimpleName().startsWith("set") && op.getParameters().size() == 1;
}
});
Function<JvmOperation, QualifiedName> nameComputation = new Function<JvmOperation, QualifiedName>() {
public QualifiedName apply(JvmOperation op) {
return QualifiedName.create(op.getSimpleName().substring(3).toLowerCase());
}
};
return Scopes.scopeFor(setters, nameComputation , IScope.NULLSCOPE);
}
IScope scope_Statement_op(GetStatement context, EReference ref) {
Iterable<JvmOperation> setters = Iterables.filter(context.getClass_().getDeclaredOperations(), new Predicate<JvmOperation>() {
public boolean apply(JvmOperation op) {
return op.getSimpleName().startsWith("get") && op.getParameters().size() == 0;
}
});
Function<JvmOperation, QualifiedName> nameComputation = new Function<JvmOperation, QualifiedName>() {
public QualifiedName apply(JvmOperation op) {
return QualifiedName.create(op.getSimpleName().substring(3).toLowerCase());
}
};
return Scopes.scopeFor(setters, nameComputation , IScope.NULLSCOPE);
}
}
there are already some projects around similar languages (Cucumber/Jnario)
~Christian