Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Context-specific scopeFor method dispatched without entering IScopeProvider.getScope
Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1863849] Fri, 01 March 2024 10:19 Go to next message
Kaan B. Y. is currently offline Kaan B. Y.Friend
Messages: 15
Registered: June 2023
Junior Member
Hello,

I have implemented a custom scope provider for my DSL.

In a nutshell:
@InjectLogger
Logger logger;

@Override
IScope getScope(EObject context, EReference ref) {
       logger.info("Providing scope for " + context);
       if (context instanceof SpecificObject1) {
          // Dispatch type-specific scopeFor
          logger.info("Dispatching scoper for SpecificObject1");
          scopeFor(context, ref);
       }
       if (context instanceof SpecificObject2) {
          // Dispatch type-specific scopeFor
       }
       // ...
       
       // If none of the if blocks match, use the default scope provider
       super.getScope(context, ref);
}

// ...

dispatch IScope scopeFor(SpecificObject1 context, EReference ref) {
       // Provide special scope for specific object
       // val scope = ...
       logger.info("Returning custom scope for SpecificObject1 instance");
       return scope;
}


Now, I have a situation where the scopeFor method for SpecificObject1 is dispatched without ever entering the getScope method defined by the IScopeProvider interface. This has become evident to me due to the missing log message, to be more specific, there is a case where "Returning custom scope for SpecificObject1 instance" is printed, but "Dispatching scoper for SpecificObject1" doesn't show up at all.

How is this possible? I have thought of the getScope method of the IScopeProvider interface as the "entry point" for all scoping.

Thanks in advance and regards
K.

[Updated on: Fri, 01 March 2024 11:53]

Report message to a moderator

Re: Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1863862 is a reply to message #1863849] Fri, 01 March 2024 14:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14711
Registered: July 2009
Senior Member
Hi, can you please prodvide a reproducer. do you have an imports for Scopes.scopeFor methods?
if yes your method might shadow that


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1863896 is a reply to message #1863862] Mon, 04 March 2024 14:01 Go to previous messageGo to next message
Kaan B. Y. is currently offline Kaan B. Y.Friend
Messages: 15
Registered: June 2023
Junior Member
Scopes.scopeFor is imported, but I don't think shadowing is an issue because all calls to Scopes.scopeFor are explicit (i.e. Scopes::scopeFor).

I think it happens because one of the scopeFor dispatch methods (ex. for SpecificObject2) explicitly calls the scopeFor method for SpecificObject1, so that SpecificObject1 gets scoped without entering getScope. It's difficult to tell because I can't debug the code in Eclipse.

That's another issue. The scoper uses some utility methods written in Kotlin. I use IntelliJ for Kotlin code, but IntelliJ has no Xtext/Xtend support. But, in exchange, Eclipse has no (or very lackluster) Kotlin support. Is there some approach to debug Xtend code that uses Kotlin imports?
Re: Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1863897 is a reply to message #1863896] Mon, 04 March 2024 14:05 Go to previous messageGo to next message
Kaan B. Y. is currently offline Kaan B. Y.Friend
Messages: 15
Registered: June 2023
Junior Member
Let me also provide some more context regarding the DSL:

The language itself is very simple, it consists of field and section declarations. A section can have multiple supertypes.

SectionDeclaration:
	"section" Symbol
	SectionFragment
;

fragment SectionFragment*:
	(":" supertype=InheritanceChain)? 
	("{"
		(elements+=FieldDeclaration)*
	"}")?
;

FieldDeclaration:
	Symbol
	":" type=RootExpression
	("=" assignment=RootExpression)?
;


InheritanceChain is a Rust-like supertype declaration (Section1 + Section2 + Section3...)
RootExpression is the root rule for expressions, symbols, literals, etc.

When a field assignment is scoped, it should also contain the fields of the supertypes of the section it is contained in.

This means
section MySection {
        foo: Int = 10
}

section MySectionChild : MySection {
        bar: Int = foo + 10
}

should be linked correctly.

How should the assignment in a FieldDeclaration be scoped? Should I check if SectionDeclaration occurs as an eContainer for the respective FieldDeclaration?

[Updated on: Mon, 04 March 2024 14:07]

Report message to a moderator

Re: Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1863898 is a reply to message #1863897] Mon, 04 March 2024 15:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14711
Registered: July 2009
Senior Member
yes you would check econtainer to end up at SectionDeclaration
then collect all supetypes and their fields + the local fields


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1864018 is a reply to message #1863898] Mon, 11 March 2024 15:22 Go to previous messageGo to next message
Kaan B. Y. is currently offline Kaan B. Y.Friend
Messages: 15
Registered: June 2023
Junior Member
That means children do not inherit scopes from their containers, i.e. if I scope in the supertypes for FieldDeclaration the RootExpression in the assignment field still has to be handled by its own and respectively call scopeFor on its FieldDeclaration container?

Thanks for your helpful answers so far.

[Updated on: Mon, 11 March 2024 15:22]

Report message to a moderator

Re: Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1864027 is a reply to message #1864018] Tue, 12 March 2024 09:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14711
Registered: July 2009
Senior Member
i dont understand this question. can you please elaborate.
you are the one who implements scopes


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 12 March 2024 09:32]

Report message to a moderator

Re: Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1865256 is a reply to message #1864027] Mon, 29 April 2024 15:05 Go to previous messageGo to next message
Kaan B. Y. is currently offline Kaan B. Y.Friend
Messages: 15
Registered: June 2023
Junior Member
Hello,

I had to upgrade Xtext inbetween but I am back on topic again.

Let me restate my question:

As far as I have understood it, when Xtext needs to scope an EObject, it provides the assigned scope provider with the respective EObject. My question is, is there some kind of internal "scope inheritance" done by Xtext?

Consider the example from my previous message:
section MySection {
        foo: Int = 10
}

section MySectionChild : MySection {
        bar: Int = foo + 10
}


If I scope in MySection for MySectionChild, should I explicitly "append" that scope to the scope of the RootExpression ('foo + 10') in the assignment of bar, or is the scope of MySectionChild already in the scope of the bar FieldDeclaration, because MySectionChild is the eContainer of bar?

Thanks in advance for your answer.

[Updated on: Mon, 29 April 2024 15:05]

Report message to a moderator

Re: Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1865280 is a reply to message #1865256] Tue, 30 April 2024 01:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14711
Registered: July 2009
Senior Member
In this case you must collect all visible variable declarations yourself manually and then construct a scope out of it

Or nest the scope of the current section with the one of the parent section , manually


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 30 April 2024 01:14]

Report message to a moderator

Re: Context-specific scopeFor method dispatched without entering IScopeProvider.getScope [message #1865433 is a reply to message #1865280] Fri, 03 May 2024 10:11 Go to previous message
Kaan B. Y. is currently offline Kaan B. Y.Friend
Messages: 15
Registered: June 2023
Junior Member
Manually, got it, thanks for your answer.
Previous Topic:How to restrict validator to the active working file?
Next Topic:Custom Validator on Xtext Project From Existing Ecore Model
Goto Forum:
  


Current Time: Mon Sep 09 04:21:56 GMT 2024

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

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

Back to the top