Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xbase] narrow cross references for java based JvmTypes
[xbase] narrow cross references for java based JvmTypes [message #709891] Thu, 04 August 2011 12:57 Go to next message
Florian Quadt is currently offline Florian QuadtFriend
Messages: 6
Registered: July 2009
Junior Member
Hello,
I'm working on a small DSL that extends XBase and trying to add constraints to narrow the mapped JvmTypes and the offered methods(i.e. String, Object and clone()).
If I have an instance of a String JvmType in a specific context I want to allow only a few methods and not all of String and Object.
 
Entity Foo{
var String x
op bar(){
x.//here I only want equals() and contains()
}}


I'm able to narrow the offered methods in the content assist quite easy (by registering an own predicate), but of course this doesn't forbid to write a not allowed method in the model editor (without content assist).

Is scoping the right place to do such a thing?
What methods / classes must be implemented / overridden?
Is it possible to influence the xbase type collection process instead of narrow possible types afterwards?

Xtext2 is quite nice and it's fun to develop DSLs with Xtext.
Thank you for your great work.

I appreciate your assistance.

Best Regards,

Florian
Re: [xbase] narrow cross references for java based JvmTypes [message #709903 is a reply to message #709891] Thu, 04 August 2011 13:15 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

scoping is about visibility not about validity (for some more detail see a recent blog post). My suggestion is adapt validation to check if the methods referred to are OK.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: [xbase] narrow cross references for java based JvmTypes [message #710019 is a reply to message #709903] Thu, 04 August 2011 15:40 Go to previous messageGo to next message
Florian Quadt is currently offline Florian QuadtFriend
Messages: 6
Registered: July 2009
Junior Member
Hi Alex,

thank you for your immediate answer and the link to the blogpost.

So it seems that the standard way to narrow JvmElements is to define validation rules in @check as well as in content assist and there is no concept to do this in one place. Therefore I have to implement at least a helper class that both validation and contentAssist call to ensure integrity of content assist and validation, right?

The difference between visibility and validity was clear with xtext 1.x but with xbase and all the java classes it seems not that obvious to me.
My idea was to use xbase so I can use the exprLanguage and the typeSystem, but at least want to allow only a few java classes.
Of cause in Xbase all types are visible but in my language I only want to allow i.e. "java.util.*". Sure I can do this in validation and content assist, but if I never want to use most of the Java classes this seems not straightforward. Why add "Math" or "Random" if my DSL has nothing to do with that?

BG,

Florian

Re: [xbase] narrow cross references for java based JvmTypes [message #710642 is a reply to message #710019] Fri, 05 August 2011 08:52 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

nobody really keeps you from actually restricting the scope. I only wanted to point out disadvantages of that approach. I don't know if it is the right hook for your use case, but you might start digging in the XbaseScopeProvider / DefaultJvmFeatureDescriptionProvider and its VisibilityService.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: [xbase] narrow cross references for java based JvmTypes [message #710905 is a reply to message #710642] Fri, 05 August 2011 15:00 Go to previous messageGo to next message
Florian Quadt is currently offline Florian QuadtFriend
Messages: 6
Registered: July 2009
Junior Member
Hi Alex,

I will dive into these classes and check if they fit better for global scope constraints.

After implementing some helper classes, scope narrowing in validation and content assist seems to be the easy way to narrow features on a specific context.
So thanks again for your help.

Best Regards,

Florian
Re: [xbase] narrow cross references for java based JvmTypes [message #946389 is a reply to message #710905] Tue, 16 October 2012 07:00 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hello all, I need narrowed cross referencing for the below grammar in xtext:

Model: cs+=Company* block+=Block+;
Block: g=[Company] '.' e=[Employee] '.' f=[employeeId];
Company: 'Company' name=ID
'{' es+= Employee* '}';
Employee: 'Employee' name=ID '{'fs+=employeeId* '}' ';' ;
employeeId: 'Employee-id' name=ID;

the language looks like:

Company sony {
Employee sony_emp1
{
Employee-id one
} ;
Employee sony_emp2 { Employee-id two } ;
}

Company amazon {
Employee amazonEmp1 { Employee-id three } ;
}

amazon . amazonEmp1 .

I need the narrowed drop down or cross referencing for three after amazon . amazonEmp1 .

could not find a way how to do this, though by changing the scope provider i can cross reference till employee, any suggestions about how to get cross reference for employee ID?

Thanks.
Re: [xbase] narrow cross references for java based JvmTypes [message #946808 is a reply to message #946389] Tue, 16 October 2012 14:24 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

the scoping methods to put into <Mydsl>ScopeProvider look something like this.

IScope scope_Block_e(Block b, EReference ref){
	Company linkedCompanyInBlock=b.getG();
	List<Employee> listOfCompanyEmployees = linkedCompanyInBlock.getEs();
	return Scopes.scopeFor(listOfCompanyEmployees);
}
	
IScope scope_Block_f(Block b, EReference ref){
	Employee linkedEmployeeInBlock=b.getE();
	List<employeeId> listOfEmployeeIds = linkedEmployeeInBlock.getFs(); 
	return Scopes.scopeFor(listOfEmployeeIds);
}


Alex

P.S.: Note that your question had nothing to do with xbase or hava based JvmTypes. You should have opened a new thread.


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Previous Topic:Where is the recursive rule?
Next Topic:Finding referencing objects
Goto Forum:
  


Current Time: Thu Mar 28 10:25:45 GMT 2024

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

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

Back to the top