Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Best way to access Properties of a Class
Best way to access Properties of a Class [message #1341541] Thu, 08 May 2014 14:35 Go to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hello,

I wanted to know if there is a good way to achieve the following. I want to use some crossreferences in my DSL model to access the inner properties of an element. Here some code for a better understanding:

class Person {
     public name:String;
}

class House {
     public me:Person = new Person();

     init(){
     this.me.name = "Alex";
     //or just
     me.name = "Alex"
  }
}


At the moment I am using the folowing grammar to define "me.name = "Alex". Here is a snippet:

PropRef:
	{PropRef}
	(expression=NameOrThisExpression) | (expression=NameOrThisExpression '.'    nameBinding=[FeatureDefinition|ID]);


Is there maybe a better way to do this? Btw. I am also manipulating the scoping, to add some elements as targets to the crossreferences.

~Alex
Re: Best way to access Properties of a Class [message #1341577 is a reply to message #1341541] Thu, 08 May 2014 14:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
HI,

this looks fine so far http://christiandietrich.wordpress.com/2013/05/18/xtext-and-dot-expressions/


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Best way to access Properties of a Class [message #1352199 is a reply to message #1341577] Tue, 13 May 2014 10:50 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hi,

thanks for the hint! But when I'm trying to implement a typesystem
(I'm using the XTS: https://code.google.com/a/eclipselabs.org/p/xtext-typesystem/) for such a grammar (like mine) I stuck at the following problem.
My PropRef should have a type of either the expression OR the type of the referenced FeatureDefinition (nameBinding). This is
important for the following situation:

...
alex.name = "Alex"


In my case, I can only define a type for alex OR name of this expression (alex.name). Do you maybe know how I define the type for both cases?

~ Alex
Re: Best way to access Properties of a Class [message #1352200 is a reply to message #1352199] Tue, 13 May 2014 10:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i do not understand this


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Best way to access Properties of a Class [message #1352263 is a reply to message #1352200] Tue, 13 May 2014 11:30 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
This is hard to explain but I will try it in a better way:

1. I try to integrate the Xtext-Typesystem-Framework into my DSL
2. So I add types to different elements of my metamodel
3. I define the primitive types and derived types

In my case I try to define a type and a typecheck for the following expression:


class Person {
     public name:String;
}

class House {
     public me:Person = new Person();

     init(){
       // here is the expresion
    [b] me.name = "Alex"[/b]
  }
}


The string ("Alex") on the right side of the equals sign has an 'StringType'. The 'me' on the left side is a NameExpression with a reference to a Property. This property has also a type, here 'Person'. Now I am trying to validate the expresssion me.name = "Alex" and want to make sure, that the type of the left and right side are equals.

Do you have maybe any experiences with the Xtext-Typesystem-Framework? Or maybe I should start a new post...

Alex



Re: Best way to access Properties of a Class [message #1352457 is a reply to message #1352263] Tue, 13 May 2014 13:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i am not experienced with that framework nbut i think it should be very simple

(the left thing inherits its type from the name property, the right thing is a literal)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Best way to access Properties of a Class [message #1359451 is a reply to message #1352199] Fri, 16 May 2014 10:37 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 13/05/2014 12:50, Alexander R wrote:
> Hi,
>
> thanks for the hint! But when I'm trying to implement a typesystem
> (I'm using the XTS:
> https://code.google.com/a/eclipselabs.org/p/xtext-typesystem/) for such
> a grammar (like mine) I stuck at the following problem. My PropRef
> should have a type of either the expression OR the type of the
> referenced FeatureDefinition (nameBinding). This is important for the
> following situation:
>
> ..
> alex.name = "Alex"
>
>
> In my case, I can only define a type for alex OR name of this expression
> (alex.name). Do you maybe know how I define the type for both cases?
>
> ~ Alex
>

From what I understand your DSL is Java-like, isn't it? There's an
example for typing a small Java language in Xsemantics,
http://xsemantics.sourceforge.net/

hope this helps
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: Best way to access Properties of a Class [message #1369608 is a reply to message #1359451] Tue, 20 May 2014 17:14 Go to previous message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Thanks for the hints! The solution for this problem:

- define a type-operation for the whole expression: me.name
- set the the type of the whole expression to the type of "name"

~Alex
Previous Topic:Accessing value of an EMF property generated with the STRING rule
Next Topic:[SOLVED]Problem with Xtend keywords
Goto Forum:
  


Current Time: Thu Mar 28 19:29:12 GMT 2024

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

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

Back to the top