Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross Reference handling in Inferrer(Looking for right code for generating Java code from cross reference)
Cross Reference handling in Inferrer [message #1753339] Sat, 04 February 2017 06:27 Go to next message
Akira Tanaka is currently offline Akira TanakaFriend
Messages: 98
Registered: March 2010
Member
Hello again,

I have created a sample dsl for my question. I created two types of Property, one using cross-reference and the other using JvmTypeReference.
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	objects += Object*;
Object:
	EntityObject | StringObject;
EntityObject:
	'entity' name=ValidID '{'
		properties += Property*
	'}';
Property:
	PropertyTypeA | PropertyTypeB;
PropertyTypeA:
	'property_a' name=ValidID ':' type=[Object|ValidID];
PropertyTypeB:
	'property_b' name=ValidID ':' type=JvmTypeReference;
StringObject:
	'string' name=ValidID body=XBlockExpression;

In the standard Domainmodel example, most of the types are specified as JvmTypeReference. IJvmModelInferrer may be simple or standard. However, when it comes to content-assist in the generated editor, it provides too many choices (see TypeB attached).

We would rather prefer to use TypeA Property so that we can get better content-assist in the generated editor (see TypeA, attached). However, I was not successful to make this work with IJvmModelInferrer.

Code for mapping EntityObject follows.
	def dispatch void infer(EntityObject element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
 		acceptor.accept(element.toClass(element.name)) [
 			for (property : element.properties) {
 				if (property instanceof PropertyTypeB)
	 				members += property.toField(property.name, property.type)
	 			else
	 				members += property.toField(property.name, /* what code should come here? */)
			}
		]
	}


I tried to find a discussion similar to mine and found the following (I am not looking for ProposalProvider route).
[url= https://www.eclipse.org/forums/index.php/t/268675/]
It seems no resolution was made at that time. I tried several approaches but did not work as expected. I would appreciate any advice on this.

Akira
Re: Cross Reference handling in Inferrer [message #1753341 is a reply to message #1753339] Sat, 04 February 2017 06:54 Go to previous messageGo to next message
Akira Tanaka is currently offline Akira TanakaFriend
Messages: 98
Registered: March 2010
Member
Sorry I forgot to include images.
  • Attachment: typeA.png
    (Size: 26.96KB, Downloaded 96 times)
  • Attachment: typeB.png
    (Size: 83.36KB, Downloaded 91 times)
Re: Cross Reference handling in Inferrer [message #1753342 is a reply to message #1753341] Sat, 04 February 2017 07:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
Can you follow the cross ref and get the property object ?
If yes

val String name = ... // name of ref.type
// could result in x.y.Z
name.typeRef


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 04 February 2017 07:28]

Report message to a moderator

Re: Cross Reference handling in Inferrer [message #1753343 is a reply to message #1753342] Sat, 04 February 2017 08:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
e.g.

def dispatch void infer(EntityObject element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
 		acceptor.accept(element.toClass(element.name)) [
 			for (property : element.properties) {
 				if (property instanceof PropertyTypeB)
	 				members += property.toField(property.name, property.type)
	 			else if (property instanceof PropertyTypeA){
	 				val String name = property.type?.name
	 				if (name !== null) {
	 					members += property.toField(property.name, name.typeRef)
	 				}
	 			}
			}
		]
	}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross Reference handling in Inferrer [message #1753369 is a reply to message #1753343] Sun, 05 February 2017 00:08 Go to previous message
Akira Tanaka is currently offline Akira TanakaFriend
Messages: 98
Registered: March 2010
Member
This works. Thank you very much!
Previous Topic:Xtext, eclipse Che and outline view
Next Topic:Type Resolution within XBlockExpression
Goto Forum:
  


Current Time: Fri Apr 26 18:35:50 GMT 2024

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

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

Back to the top