Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Access to Java Fields at DSL
Access to Java Fields at DSL [message #1385473] Fri, 06 June 2014 12:59 Go to next message
Eclipse UserFriend
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 14:12 Go to previous messageGo to next message
Eclipse UserFriend
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 )
	}

}

Re: Access to Java Fields at DSL [message #1385483 is a reply to message #1385475] Fri, 06 June 2014 15:32 Go to previous messageGo to next message
Eclipse UserFriend
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 02:14 Go to previous messageGo to next message
Eclipse UserFriend
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 02:34] by Moderator

Re: Access to Java Fields at DSL [message #1385541 is a reply to message #1385540] Mon, 09 June 2014 02:25 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

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

JvmDeclaredType (members / supertypes / operations ...)

[Updated on: Mon, 09 June 2014 02:28] by Moderator

Re: Access to Java Fields at DSL [message #1385550 is a reply to message #1385541] Mon, 09 June 2014 05:57 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 11:30:20 EDT 2025

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

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

Back to the top