|
Re: Access to Java Fields at DSL [message #1385475 is a reply to message #1385473] |
Fri, 06 June 2014 18:12 |
|
Hi,
can you give a bit more context what you have done? grammar?
if the reference to class is a JvmDeclaredType you can ask it for its DeclaredFields
e.g.
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types
Model:
instances+=Instance*;
Instance:
'instance' name=ID 'of' type=[types::JvmDeclaredType|FQN] '{'
values+=Value*
'}';
Value:
field=[types::JvmField] '=' v=STRING
;
FQN: ID ("." ID)*;
class MyDslScopeProvider extends org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider {
def IScope scope_Value_field(Instance ctx, EReference r) {
return Scopes.scopeFor(ctx.type.declaredFields,[
f|QualifiedName.create(f.simpleName)
], IScope.NULLSCOPE )
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: Access to Java Fields at DSL [message #1385540 is a reply to message #1385473] |
Mon, 09 June 2014 06:14 |
Michael Stadler Messages: 5 Registered: June 2014 |
Junior Member |
|
|
Hi,
I've two further questions:
I realized, that in the previous example of Christian Dietrich it is just possible to access the fields of exactly this class and the inherited fields (if this java class inherits from another one) are not available. Is it possible to achieve this?
Further, I wanted to check wheter a setter method exists for this field at the java class. But again, unfortunatly I've found no solution.
This aspect can be checked either at the ScopeProvider, or as a Check at the DslValidator.
Thanks again for helping me out
Michael
[Updated on: Mon, 09 June 2014 06:34] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03624 seconds