Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » using filters in cross referencing
using filters in cross referencing [message #975946] Thu, 08 November 2012 07:43 Go to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi All,

In content assistance class, i got to see filter, which is set to alwaysTrue() by default in my project..there are many other options i can try for filter, however I did not get any documentation about how to give other filter possibilities. I was only able to try one more option for filter ie., alwaysFalse().

Can any one point me, where i can get any documentation or examples about how to give other types of filters in lookupCrossReference method.

Thanks,
Sri.
Re: using filters in cross referencing [message #976014 is a reply to message #975946] Thu, 08 November 2012 08:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi feel free to create a new predicate<ieobjectdescription> yourself.
You can filter there based on the ieoobjectdescription (name, URI,
user data etc)

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: using filters in cross referencing [message #977432 is a reply to message #976014] Fri, 09 November 2012 09:29 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi,
Thanks a lot for your reply.
If i have to use below grammar, and can not use QN,

Model: cs+=Company* employees+=Emp* block+=Block+
;
Block: emp1=company_crossRef
| emp_id=empId_crossRef
;

company_crossRef: comp1=[Company] ':' emp2=[Emp] ':' empId2=[empId] ;
empId_crossRef: emp1=[Emp] ':' empId1=[empId];

Company: c='Company' name=ID '{' emp+=Emp+ '}';

Emp: r='Emp' name=ID '{' empIdName+= empId* '}'';' ;
empId: 'Employee_id' name=ID

Then,

(1) Do i need to cross reference at some higher rule like Block instead of in company_crossRef, empId_crossRef etc as this discussion suggests? http://www.eclipse.org/forums/index.php/m/898746/

(2) Do I need to give filter with IEObjectDescription in scopeProvider class or do i need to override lookupCrossReference method in proposal provider? I understood as lookupCrossReference, in turn takes scope provider's definition before actually giving the list of cross referable items. So, is it the same if i mention filter either in lookupCrossReference or in scopeProvider?

(3) I got very few examples of filter usage in eclipse discussions, other than that, don't we have good documentation explaining possible options in filters?
Re: using filters in cross referencing [message #977446 is a reply to message #977432] Fri, 09 November 2012 09:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi you still have the ambiguity problem.!!!!!

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: using filters in cross referencing [message #977458 is a reply to message #977446] Fri, 09 November 2012 09:51 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi, If i can use QualifiedName, i get fully QN of all possibilities. However for my grammar, I need to get it working without fully QN. so trying if I can do anything with filters in scope or proposal Provider. Do you have any suggestions for me about the path i need to take to resolve ambiguity without actually showing fully QN.
Thanks.
Re: using filters in cross referencing [message #977480 is a reply to message #977458] Fri, 09 November 2012 10:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi please answer the following questions first:

(1) it is not possible to change concrete syntax
(2) it is not possible to change abstract syntax

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: using filters in cross referencing [message #977481 is a reply to message #977458] Fri, 09 November 2012 10:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
PS: you could try to use the node model to find what the user has
actually typed before to filter the elements in lookup cross ref

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: using filters in cross referencing [message #977504 is a reply to message #977481] Fri, 09 November 2012 10:30 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi, Thank you for reply. Sorry i am not quite clear at this moment about what exactly are concrete and abstract syntax. But, yes, it is not possible, in my case, to change the syntax. Syntax is fixed for my grammar.
When i cross reference only one of company or employee, I needed to restrict the scope and it worked as i want, it shows employee of that particular company and after that employee Ids of that employee..By node model, do you mean gmf.node etc.,?
Re: using filters in cross referencing [message #977517 is a reply to message #977504] Fri, 09 November 2012 10:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
No I mean the node model Xtext provides. Have a look at the class
inode nodemodelutil etc

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: using filters in cross referencing [message #977518 is a reply to message #977517] Fri, 09 November 2012 10:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.S:

with abstract syntax i mean the metamodel.
you may have a look for a similar problem at http://dslmeinte.wordpress.com/2010/08/16/path-expressions-in-entity-models/


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: using filters in cross referencing [message #977523 is a reply to message #977518] Fri, 09 November 2012 10:51 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Thank you, I will go through the link.
Re: using filters in cross referencing [message #981389 is a reply to message #977523] Mon, 12 November 2012 11:20 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi Christian,

Thank you for the link. I tried out the example in this link (I looked at later blog he created for more recent xtext versions, and tried that too..still could not get even that working).

while trying the first link, http://dslmeinte.wordpress.com/2010/08/16/path-expressions-in-entity-models/

I work on xtext 2.2.1, and the scope providers i have been writing appear similiar to what is there in this blog. So, For the domain model example grammar in xtext, i tried to copy scope provider in the blog to scopeProvider.java in my project, and i got below errors, which i could not fix. Do any of these errors appear obvious or any hint to me about how to fix these errors?

(1) On line 6, The method structuralFeatures(Entity) is undefined for the type MyDslScopeProvider

(2) On line 13,
The method structuralFeatures(Entity) is undefined for the type MyDslScopeProvider

(3) Multiple markers at this line. The method emptyIterable() is undefined for the type Iterables

(4) On line 15, The method emptyIterable() is undefined for the type Iterables. After i have imported, import com.google.common.collect.Iterables;

(5) On line 26, The type IResourceDescription.Event.Listener is not generic; it cannot be parameterized with arguments <StructuralFeature>

The list of packages i imported are:

package org.xtext.example.mydsl2.scoping;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;

import org.eclipse.xtext.resource.IResourceDescription.Event.Listener;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider;

import org.eclipse.xtext.xbase.lib.IterableExtensions;

import org.xtext.example.mydsl2.myDsl.Entity;
import org.xtext.example.mydsl2.myDsl.Feature;
import org.xtext.example.mydsl2.myDsl.PathHead;
import org.xtext.example.mydsl2.myDsl.PathTail;
import org.xtext.example.mydsl2.myDsl.Reference;
import org.xtext.example.mydsl2.myDsl.StructuralFeature;
import org.xtext.example.mydsl2.myDsl.Type;
import org.xtext.example.mydsl2.myDsl.impl.StructuralFeatureImpl;

import com.google.common.collect.Iterables;

Please give me a hint if the errors i am getting are because of any obvious reasons.

Thanks.
Re: using filters in cross referencing [message #981440 is a reply to message #981389] Mon, 12 November 2012 12:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi your Imports look wired To me - i cannot tell you What to do sry.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: using filters in cross referencing [message #981445 is a reply to message #981389] Mon, 12 November 2012 12:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
And please do nou use the domain model example. It is xbase based :-)

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: using filters in cross referencing [message #981476 is a reply to message #981445] Mon, 12 November 2012 12:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Just gave it a short try

Model: cs+=Company* employees+=Emp* (block+=Head ";")+
; 

Named:
	Company | Emp | empId
;

Head:
	headable=[Named] tail=Tail
;

Tail:
	{Tail}":" tailable=[Named] (tail=Tail)?
;

Company: c='Company' name=ID '{' emp+=Emp+ '}';

Emp: r='Emp' name=ID '{' empIdName+= empId* '}'';' ; 
empId: 'Employee_id' name=ID;


public class MyDslNameProvider extends SimpleNameProvider {

}


public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {

	@Override
	public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return MyDslNameProvider.class;
	}
	
}


public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {

	IScope scope_Head_headable(EObject ctx, EReference ref) {
		return new FilteringScope(delegateGetScope(ctx, ref), new Predicate<IEObjectDescription>() {

			@Override
			public boolean apply(IEObjectDescription input) {
				return EcoreUtil2.isAssignableFrom(MyDslPackage.Literals.COMPANY, input.getEClass())
					|| EcoreUtil2.isAssignableFrom(MyDslPackage.Literals.EMP, input.getEClass());
			}
			
		});
	}
	
	IScope scope_Tail_tailable(EObject ctx, EReference ref) {
		EObject container = ctx.eContainer();
		if (container instanceof Head) {
			Head head = (Head)container;
			if (head.getHeadable() instanceof Company) {
				return Scopes.scopeFor(((Company)head.getHeadable()).getEmp());
			}
			if (head.getHeadable() instanceof Emp) {
				return Scopes.scopeFor(((Emp)head.getHeadable()).getEmpIdName());
			}
			return IScope.NULLSCOPE;
		} else if (container instanceof Tail) {
			Tail tail = (Tail)container;
			if (tail.getTailable() instanceof Emp) {
				return Scopes.scopeFor(((Emp)tail.getTailable()).getEmpIdName());
			}
			return IScope.NULLSCOPE;
		}
		return IScope.NULLSCOPE;
	}
	
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: using filters in cross referencing [message #984362 is a reply to message #981476] Wed, 14 November 2012 16:34 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi, thank you Christian for your reply. Yes xbase and xtend are also used for cross-referencing...though i am working on xtext only..
may be basic but i am not sure about what { some-word } stand for in the rule:
Tail:
{Tail}":" tailable=[Named] (tail=Tail)?
;
Re: using filters in cross referencing [message #984452 is a reply to message #984362] Wed, 14 November 2012 18:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
the feature is called unassiged action. it creates the object at the place of the action and not lazy (first assignment) as it is usually done by xtext
otherwise you would have the head or parent tail in the scoping and not the tail you
are actually working on as context object during content assist.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: using filters in cross referencing [message #985101 is a reply to message #984452] Thu, 15 November 2012 06:35 Go to previous message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi, Thanks a lot for your help. I did try for some time on how to make xtext not to do lazy linking and create object at the place of action (if that is same as eager linking) with not much success. the grammar and scope you tried are working like charm. that's great..

Only thing i want to know is if it possible to avoid xtext suggesting : after "amazon_emp1 : amazon_1"
ie., after amazon_1, it is suggesting both : and ; though nothing drops down if : is selected
similarly with company rule "sony : sony_emp1 : sony_1"
ie., after sony_1, it is suggesting both : and ; though nothing drops down if : is selected

any suggestions for me, what to concentrate on, if i like to avoid the last : it is suggesting?
Thanks.
Previous Topic:whitespace Indentation based grammar ?
Next Topic:XText builder run takes many minutes on eclipse start
Goto Forum:
  


Current Time: Fri Apr 19 06:35:24 GMT 2024

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

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

Back to the top