Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem in Scoping with getting left side of a XBinaryOperation
Problem in Scoping with getting left side of a XBinaryOperation [message #759272] Mon, 28 November 2011 08:42 Go to next message
Ingo Meyer is currently offline Ingo MeyerFriend
Messages: 162
Registered: July 2009
Senior Member
Hi there,

I'm trying to scope a right side of a XBinaryOperation or XAssignment depending on the type of the left side. At the end I would be able to ommit an Enum when the left side is a enum like (pseudo code): "Entity.myEnumFeature == EnumLiteral" instead "Entity.myEnumFeature == EnumType.EnumLiteral".

The left side of course is a XFeatureCall in that case, but unfortunately in my ScopeProvider the left side feature is always a proxy at the time of the call for the right side. Later my hole model is resolved correctly, so there is no error in it. Using "org.eclipse.xtext.xbase.typing.AbstractTypeProvider#getFeature(org.eclipse.xtext.xbase.XAbstractFeatureCall)" doesn't help.

Here is my part of my ScopeProvider.createLocalVarScope method,
"typing" is my TypeProvider inheriting from XbaseTypeProvider:

	protected IScope createLocalVarScope(
			IScope parentScope,
			final LocalVariableScopeContext ctx )
	{

EObject x = ctx.getContext();

		if (x.eContainer() instanceof XBinaryOperation && //
				x.eContainingFeature() == XbasePackage.Literals.XBINARY_OPERATION__RIGHT_OPERAND)
		{
			final XBinaryOperation bop = (XBinaryOperation) x.eContainer();
			final JvmTypeReference left = typing.getType( bop.getLeftOperand() );
			if (left != null && typing.isEnum( left ))
			{
				final Iterable<JvmEnumerationLiteral> enums = typing.getJvmEnumerationLiterals( left );
				parentScope = super.createLocalVarScope( parentScope, createLocalVariableScopeContext( x, reference, ctx.isIncludeCurrentBlock(), ctx.getIndex() ) );
				parentScope = getJvmEnumerationLiteralsScope( parentScope, enums );
				return parentScope;
			}
		}
		if (x.eContainer() instanceof XAssignment && //
				x.eContainingFeature() == XbasePackage.Literals.XASSIGNMENT__VALUE)
		{
			final XAssignment bop = (XAssignment) x.eContainer();
			final JvmTypeReference left = typing.getTypeForIdentifiable( typing.getFeature( bop ) );
			if (left != null && typing.isEnum( left ))
			{
				final Iterable<JvmEnumerationLiteral> enums = typing.getJvmEnumerationLiterals( left );
				parentScope = super.createLocalVarScope( parentScope, createLocalVariableScopeContext( x, reference, ctx.isIncludeCurrentBlock(), ctx.getIndex() ) );
				parentScope = getJvmEnumerationLiteralsScope( parentScope, enums );
				return parentScope;
			}
		}


Any ideas?

thanks a lot
Ingo

BTW i'm on the 2.2 nightly and it works very nice Wink
Re: Problem in Scoping with getting left side of a XBinaryOperation [message #759332 is a reply to message #759272] Mon, 28 November 2011 12:12 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Ingo,

I think it's a re-entrant invocation of getScope. The linker tries to
resolve the _left_ assignment thing which is an JvmIdentifiable.
Therefore it tries to find e.g. setters with that name and wants to
match them against the type of the _right_ side. In order to do that,
the right side has to be resolved. If you try to access the left side in
your scoping, it'll eventually return the unresolved proxy in order to
avoid endless recursion. At least that's what I expect according to your
description and the code.
Do you invoke XAbstractFeatureCall#getFeature somewhere in your own type
provider code?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 28.11.11 09:42, schrieb Ingo Meyer:
> Hi there,
>
> I'm trying to scope a right side of a XBinaryOperation or XAssignment
> depending on the type of the left side. At the end I would be able to
> ommit an Enum when the left side is a enum like (pseudo code):
> "Entity.myEnumFeature == EnumLiteral" instead "Entity.myEnumFeature ==
> EnumType.EnumLiteral".
>
> The left side of course is a XFeatureCall in that case, but
> unfortunately in my ScopeProvider the left side feature is always a
> proxy at the time of the call for the right side. Later my hole model is
> resolved correctly, so there is no error in it. Using
> "org.eclipse.xtext.xbase.typing.AbstractTypeProvider#getFeature(org.eclipse.xtext.xbase.XAbstractFeatureCall)"
> doesn't help.
>
> Here is my part of my ScopeProvider.createLocalVarScope method,
> "typing" is my TypeProvider inheriting from XbaseTypeProvider:
>
>
> protected IScope createLocalVarScope(
> IScope parentScope,
> final LocalVariableScopeContext ctx )
> {
>
> EObject x = ctx.getContext();
>
> if (x.eContainer() instanceof XBinaryOperation && //
> x.eContainingFeature() ==
> XbasePackage.Literals.XBINARY_OPERATION__RIGHT_OPERAND)
> {
> final XBinaryOperation bop = (XBinaryOperation) x.eContainer();
> final JvmTypeReference left = typing.getType( bop.getLeftOperand() );
> if (left != null && typing.isEnum( left ))
> {
> final Iterable<JvmEnumerationLiteral> enums =
> typing.getJvmEnumerationLiterals( left );
> parentScope = super.createLocalVarScope( parentScope,
> createLocalVariableScopeContext( x, reference,
> ctx.isIncludeCurrentBlock(), ctx.getIndex() ) );
> parentScope = getJvmEnumerationLiteralsScope( parentScope, enums );
> return parentScope;
> }
> }
> if (x.eContainer() instanceof XAssignment && //
> x.eContainingFeature() == XbasePackage.Literals.XASSIGNMENT__VALUE)
> {
> final XAssignment bop = (XAssignment) x.eContainer();
> final JvmTypeReference left = typing.getTypeForIdentifiable(
> typing.getFeature( bop ) );
> if (left != null && typing.isEnum( left ))
> {
> final Iterable<JvmEnumerationLiteral> enums =
> typing.getJvmEnumerationLiterals( left );
> parentScope = super.createLocalVarScope( parentScope,
> createLocalVariableScopeContext( x, reference,
> ctx.isIncludeCurrentBlock(), ctx.getIndex() ) );
> parentScope = getJvmEnumerationLiteralsScope( parentScope, enums );
> return parentScope;
> }
> }
>
>
> Any ideas?
>
> thanks a lot
> Ingo
>
> BTW i'm on the 2.2 nightly and it works very nice ;)
Re: Problem in Scoping with getting left side of a XBinaryOperation [message #759387 is a reply to message #759332] Mon, 28 November 2011 14:12 Go to previous message
Ingo Meyer is currently offline Ingo MeyerFriend
Messages: 162
Registered: July 2009
Senior Member
hmm, thanks for the hint, I will investigate if it is a "re-entrant invocation".
Is there any chance to identifiy such a call?
Shouldn't there be then also a call for the right side?

I'm invoking XAbstractFeatureCall#getFeature in the 2nd block (XAssignment) of the code of my initial post:
"final JvmTypeReference left = typing.getTypeForIdentifiable( typing.getFeature( bop ) );"
where "typing.getFeature" is just a delegate call to that method.

I will have a look in the stacktrace now to see if you're right.

Thanks again,
Ingo
Previous Topic:warnings when importing xbase
Next Topic:Unary Minus in Expressions
Goto Forum:
  


Current Time: Tue Apr 23 11:25:20 GMT 2024

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

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

Back to the top