Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Access to Java Fields at DSL
Access to Java Fields at DSL [message #1385473] Fri, 06 June 2014 16:59 Go to next message
Michael Stadler is currently offline Michael StadlerFriend
Messages: 5
Registered: June 2014
Junior Member
Hi,

I want to write a Xtext grammar where the users can access Java Classes and their fields.

e.g.:

Java.Exampleclass: {
field1:"abc",
field2:"def"
}

(field1 and 2 are fields of the Java.Exampleclass)

The reference to the Java Class or interface wasn't a problem to implement. But I've not found a way to get access to fields in the Xtext Editor. These fieldnames should (later) be proposals for the auto completion etc.

It would be great if you can give me a hint.

Thanks in advance!
Michael
Re: Access to Java Fields at DSL [message #1385475 is a reply to message #1385473] Fri, 06 June 2014 18:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13317
Registered: July 2009
Senior Member
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 )
	}

}



Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Access to Java Fields at DSL [message #1385483 is a reply to message #1385475] Fri, 06 June 2014 19:32 Go to previous messageGo to next message
Michael Stadler is currently offline Michael StadlerFriend
Messages: 5
Registered: June 2014
Junior Member
That's exactly what I was looking for.
Thank you very much!
Re: Access to Java Fields at DSL [message #1385540 is a reply to message #1385473] Mon, 09 June 2014 06:14 Go to previous messageGo to next message
Michael Stadler is currently offline Michael StadlerFriend
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

Re: Access to Java Fields at DSL [message #1385541 is a reply to message #1385540] Mon, 09 June 2014 06:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13317
Registered: July 2009
Senior Member
Hi,

have a look at the code and see what is there ?????????

JvmDeclaredType (members / supertypes / operations ...)



Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 09 June 2014 06:28]

Report message to a moderator

Re: Access to Java Fields at DSL [message #1385550 is a reply to message #1385541] Mon, 09 June 2014 09:57 Go to previous message
Michael Stadler is currently offline Michael StadlerFriend
Messages: 5
Registered: June 2014
Junior Member
OK, I got it. Sorry for this question Wink
Previous Topic:Embedding DSL in Java / Creating Xtext model based on Java
Next Topic:xtext grammar import ATL metamodel
Goto Forum:
  


Current Time: Thu Jan 23 21:06:56 GMT 2020

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

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

Back to the top