Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Scoping(Using attributs defined in a ClassDiagram in an ObjectDiagram)
Scoping [message #1015425] Thu, 28 February 2013 14:38 Go to next message
Günther Fiedler is currently offline Günther Fiedler
Messages: 21
Registered: February 2013
Junior Member
Hello,

I have a problem using the name of an attribute defined in a ClassDiagram as name in an ObjectDiagram. To give you guys more information, see the parts of my DSL

@ClassDiagram
Attribute:
vis=Visibility name=ID ':' type=Type;


@ObjectDiagram
InstanceSpecification:
name=[Attribute] '=' value=STRING;

I want to able to use only these attributes matching to a class, which means only those i defined earlier in the Class


Greetz,
Günther
Re: Scoping [message #1015427 is a reply to message #1015425] Thu, 28 February 2013 14:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
Hi this can be done by a simple scoping method in the
yourdslscopeprovider

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Scoping [message #1015429 is a reply to message #1015425] Thu, 28 February 2013 14:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
P.s.: a bit more grammar is needed to give you runnable sample code

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Scoping [message #1015435 is a reply to message #1015429] Thu, 28 February 2013 15:04 Go to previous messageGo to next message
Günther Fiedler is currently offline Günther Fiedler
Messages: 21
Registered: February 2013
Junior Member
Okay sry, thought this is enough Very Happy
I just post my two grammars, perhaps you can find something to correct.

Thank you very much.

ClassDiagram:
{ClassDiagram}
'ClassDiagram:'
('Classes:' classes+=Class+)?
('Interfaces:' interfaces+=Interface+)?
'CEND';

Class:
('['libName = STRING']')?
visib=Visibility (abstract?='abstract')? 'class' name=ID
('extends' generalization+=Generalization (',' generalization+=Generalization)*)?
('implements' interface+=Implements (',' interface+=Implements)*)? '{'
(attributes+=Attribute)*
(methodes+=Method)+
((associations+=Association)+)?
'}';

Type:
basic=('int' | 'boolean' | 'String' | 'void') |
classref=[Class];

Parameter:
type=Type name=ID;

Method:
('['libName = STRING']')?
(visib=Visibility)? name=ID '(' ((params+=Parameter (',' params+=Parameter)*)?)? ')' ':' returntype=Type
(code=STRING)?;

Attribute:
vis=Visibility name=ID ':' type=Type;

enum Visibility:
PROTECTED='protected' | PUBLIC='public' | PRIVATE='private';

Interface returns Interface:
'interface' name=ID '{'
(methodes+=Method)+
'}';

Implements returns Implements:
{Implements}
impl=[Interface];

Generalization returns Generalization:
{Generalization}
general=[Class];

Association:
(compartment?="compartment")? nameOfCompartment=ID ':' ref=[Class] card=Cardinality;

Cardinality:
'[' lowerBound=ElementBound '..' upperBound=ElementBound ']';

ElementBound returns ecore::EIntegerObject:
'*' | INT;

____________________________________________________________________________________
ObjectDiagram:
{ObjectDiagram}
'ObjectDiagram:'
objects+=Object+
'OEND';

Object:
name=ID ('instantiates' class=[Class])? '{'
(instspecs+=InstanceSpecification*)
(relations+=RelationShip*)
'}';

InstanceSpecification:
name=[Attribute] '=' value=STRING;

RelationShip:
nameOfRelationship=ID '>>' object=[Object];
Re: Scoping [message #1015438 is a reply to message #1015435] Thu, 28 February 2013 15:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
IScope scope_ InstanceSpecification_name(Object CTX, EReference ref)
{return Scopes.scopeFor(CTX.getclass().getattributes());}

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Scoping [message #1016118 is a reply to message #1015438] Tue, 05 March 2013 06:59 Go to previous message
Günther Fiedler is currently offline Günther Fiedler
Messages: 21
Registered: February 2013
Junior Member
Thank you very much!

I had the Scope correct, but I used the wrong getClass method ...
Previous Topic:Number/String syntax errors in Xtext
Next Topic:Bug with EcoreGeneratorFragment in xtext 2.4M5?
Goto Forum:
  


Current Time: Thu Oct 23 08:49:25 GMT 2014

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

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