Problem in Scoping with getting left side of a XBinaryOperation [message #759272] |
Mon, 28 November 2011 08:42 |
Ingo Meyer 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
|
|
|
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 |
Sebastian Zarnekow 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 ;)
|
|
|
|
Powered by
FUDForum. Page generated in 1.38364 seconds