Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to dynamically create instance without "dangling reference"?
How to dynamically create instance without "dangling reference"? [message #1266237] Fri, 07 March 2014 06:21
Matthew Liu is currently offline Matthew LiuFriend
Messages: 9
Registered: March 2013
Junior Member
Hello All,

I want to implement the implicit getter method in my DSL.

For example:
    class C1 {
        i : Integer := 100;
        i() : Integer;
    }

    class C2 {
        j : Integer := 100;
       // j():Integer; // this getter method should be implicitly created.
    }

    c1 : C1 := new C1();
    c2 : C2 := new C2();
    a : Integer := 0;
    a := c1.i();
    a := c2.j();


In C1, i() is the explicit getter method for the attribute i; In C2, since there is no explicitly defined getter method, I need create j() dynamically.

Note that Integer is TYPE, which is a cross-reference. The following is part of my grammar.

TClass returns TClass  :
	('CLASS'|'class') name= TNamedElement  '{'  elements+=TEntity )* '}'
	;

TEntity : 
   TOperation | 
   TAttributeDecl
   ;

TOperation returns TOperation:
    {TOperation} name=SimpleName  '(' ')'  ':'returnType = TType?  declaration?=';'
	; 

TType returns TType :
   referencedElement=[TNamedElement|ID]

TNamedElement : ID;


TAttributeDecl: 

TVariableDecl ( ':=' initialValue=TExpr )?

TVariableDecl returns TVariableDecl  :
	 (variables+=TVariable ( ',' variables+=TVariable )*) ':' type=TType 
	;

TVariable : 
    name = TNamedElement;



Currently, I try to create the implict getter method in afterModelLinked() method.

TOperation operation = MyDSLFactory.eINSTANCE.createTOperation();
......
TNamedElement namedElement = TdlFactory.eINSTANCE.createTNamedElement();
namedElement.setName("Integer");
ttype.setReferencedElement(namedElement);     // <------   
......
operation.setDeclaration(true);

// Then add the this operation to the EObject class (C2)


Now the Editor works well, However, the following is displayed in the Problem View.

The feature 'referencedElement' of 'com.uniquesoft.mint.actlang.tdl.tdl.impl.TTypeImpl@7ad44d8b{platform:/resource/bug2403/TDL/Test.tdl#//@elements.0/@elements.0/@elements.2/@returnType/@type}' contains a dangling reference 'com.uniquesoft.mint.actlang.tdl.tdl.impl.TNamedElementImpl@82f1fad{#//}'

I guess the root reason is that referenceElement feature in TType is a cross-reference. Could anyone please give some advice?

Also I am not sure whether this is a proper solution to implement the implicit getter. If not, Could anyone please propose a suitable solution? Thanks!

Best Regards,
Matthew

[Updated on: Fri, 07 March 2014 10:53]

Report message to a moderator

Previous Topic:XtextResourceSetProvider problems in junit
Next Topic:EObjectDescription could be found in Scope during serialization in an osgi environnement
Goto Forum:
  


Current Time: Wed Oct 28 00:55:12 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