Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » complete{TypeName}_{FeatureName} called with parent i.s.o. node itself
complete{TypeName}_{FeatureName} called with parent i.s.o. node itself [message #1753974] Mon, 13 February 2017 14:53 Go to next message
Paul Hoogendijk is currently offline Paul HoogendijkFriend
Messages: 2
Registered: February 2017
Junior Member
Hi,

I have the following grammer (which is a stripped down version of the real own):

Model:
    models += ModelDeclaration*
;

ModelDeclaration:
    InterfaceDeclaration | ComponentDeclaration
;

InterfaceDeclaration:
    'interface' 
    name = ID 
    CURLYBRACKET_OPEN
    eventDecls += EventDeclaration 
    CURLYBRACKET_CLOSE
;

EventDeclaration:
    name = ID 
    SEMICOLON
;


ComponentDeclaration:
    'component'
    name = ID
    CURLYBRACKET_OPEN
    (ports += PortDeclaration)*
    (behaviour = BehaviourDeclaration)
    CURLYBRACKET_CLOSE
;

PortDeclaration:
    names = [InterfaceDeclaration]
    name = ID
    SEMICOLON
;


BehaviourDeclaration:
    'behaviour'
    CURLYBRACKET_OPEN
    stats += BehaviourStatement
    my = CURLYBRACKET_CLOSE
;

BehaviourStatement:
    CompoundBehaviourStatement
  | ActionStatement
  | ReplyStatement
;

CompoundBehaviourStatement:
    {CompoundBehaviourStatement}
    CURLYBRACKET_OPEN
    (stats += BehaviourStatement)*
    CURLYBRACKET_CLOSE
;

ActionStatement:
    port = [PortDeclaration] '.' action = [EventDeclaration]
    SEMICOLON
;


ReplyStatement:
    (port = [PortDeclaration] DOT)?
    actionReply = 'reply'
    SEMICOLON
;

CURLYBRACKET_OPEN : '{';
CURLYBRACKET_CLOSE : '}';
SEMICOLON : ';';
DOT : '.';


Now, for content assist I want to filter on certain events for each of the ports (which events are allowed depends on properties which are part of the real grammar).
So, I want to override


	override completeActionStatement_Action(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		if (model instanceof ActionStatement) {
			var port = (model as ActionStatement).port
			port = port;
		}
		else {
			logger.error("Help; how to access port field?")					
		}
		super.completeActionStatement_Action(model, assignment, context, acceptor)
	}


However, sometimes this method is called with the parent (CompoundBehaviourStatement) i.s.o. the node it self.
As a result, I have no idea how to get the "port" field.

For instance this happens for the following example:

interface I {
	e;
}

component C {
	I p;
	I r;
	behaviour {
		{ p.}      // content assist after "p." does not work as expected; how to access port field?
	}
}


For the folling example it does work:
interface I {
	e;
}

component C {
	I p;
	I r;
	behaviour {
		{ p.e; p.}      // content assist after "p." does work as expected
	}
}



How to fix this, i.e. how to make sure it is always called with ActionStatement as model?

Thanks,

-Paul Hoogendijk.
Re: complete{TypeName}_{FeatureName} called with parent i.s.o. node itself [message #1753985 is a reply to message #1753974] Mon, 13 February 2017 16:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11483
Registered: July 2009
Senior Member
Hi,

Depending on the error recovery this might work or might not. I'll have a look if the error recovery can be improved


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com

[Updated on: Mon, 13 February 2017 17:07]

Report message to a moderator

Re: complete{TypeName}_{FeatureName} called with parent i.s.o. node itself [message #1754005 is a reply to message #1753985] Mon, 13 February 2017 18:10 Go to previous messageGo to next message
Paul Hoogendijk is currently offline Paul HoogendijkFriend
Messages: 2
Registered: February 2017
Junior Member
Thanks for the quick response.

Two remarks/questions:

1) How do I access the PortDeclaration inside the parent? So the port name "p" and its corresponding declaration?

2) I noticed that if I remove the ReplyStatement that it does work. Does that make sense?

Thanks,

Paul.
Re: complete{TypeName}_{FeatureName} called with parent i.s.o. node itself [message #1754007 is a reply to message #1754005] Mon, 13 February 2017 18:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11483
Registered: July 2009
Senior Member
well,

this is where your grammar is ambigous.

if you simply write

xxxx.

you can be inside an action or you can be inside a reply.
this is why the content assist cannot decide what to created.
thus you get the last object that could be decided as param.

=> there is no real solution for that.


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: complete{TypeName}_{FeatureName} called with parent i.s.o. node itself [message #1754008 is a reply to message #1754007] Mon, 13 February 2017 18:36 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11483
Registered: July 2009
Senior Member
p.s.

ofcourse you could merge both into one

PortBasedStatement:
((
port = [PortDeclaration] '.' (
action=[EventDeclaration] |
actionReply='reply'
)
) |
{PortBasedStatement}actionReply = 'reply')
";"
;


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Previous Topic:xbase expression performance issue with nested feature calls
Next Topic:After Migtation from xtext 2.10 to xtext 2.11. Cannot open text editor for my DSL
Goto Forum:
  


Current Time: Mon Dec 11 02:18:40 GMT 2017

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

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