|
Re: scope problem [message #558580 is a reply to message #558562] |
Mon, 13 September 2010 14:58 |
|
Hi,
there is something stange with the braces in your funtion rule.
changing it to
functionDecl: "def" "Operation" name=ID
('(' (params+=EClassParameter (',' params+=EClassParameter)*)? ')' )? "{"
"}"
;
makes it working.
But why to you want to define an EClass inline for a parameter?
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: scope problem [message #558589 is a reply to message #558583] |
Mon, 13 September 2010 15:30 |
|
Hey,
i still don't know if you want to instantiate or to reference an EClass Test when writing
def operation o1(EClass Test){}
using this grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Model:{Model}
classes+=(
EClassO
)*
|
("Library" "{"
functions+=functionDecl*
"}")
;
EClassO:
(aEClass|
DS='like' eClass=[ecore::EClass]
);
aEClass: "a" a=_EClass;
_EClass returns ecore::EClass:"EClass" name=ID;
functionDecl: "def" "Operation" name=ID
('(' (params+=EClassParameter (',' params+=EClassParameter)*)? ')' )? "{"
"}"
;
EClassParameter returns ecore::EClass: "EClass" name=ID ;
and these models
Library {
def Operation xxx (EClass A){
}
}
i get the completion i want at the second model
~Christian
P.S: of course i had to use a custom QualifiedNameProvider
public class MyDslQNP extends DefaultDeclarativeQualifiedNameProvider {
public String qualifiedName(EClass c) {
return c.getName();
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Mon, 13 September 2010 15:35] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: scope problem [message #558776 is a reply to message #558769] |
Tue, 14 September 2010 11:56 |
|
So in this places you do not want to have the parameter eclasses - so write scoping for the other places and filter out the stuff you do not want to have
public class FilteringScope implements IScope {
private IScope delegate;
private Predicate<IEObjectDescription> filter;
public FilteringScope(IScope delegate, Predicate<IEObjectDescription> filter) {
this.delegate = delegate;
this.filter = filter;
}
public IScope getOuterScope() {
return new FilteringScope(delegate.getOuterScope(), filter);
}
public Iterable<IEObjectDescription> getContents() {
return filter(delegate.getContents());
}
public Iterable<IEObjectDescription> getAllContents() {
return filter(delegate.getAllContents());
}
public IEObjectDescription getContentByName(String name) {
return filter(delegate.getContentByName(name));
}
public IEObjectDescription getContentByEObject(EObject object) {
return filter(delegate.getContentByEObject(object));
}
public Iterable<IEObjectDescription> getAllContentsByEObject(EObject object) {
return filter(delegate.getAllContentsByEObject(object));
}
protected Iterable<IEObjectDescription> filter(
Iterable<IEObjectDescription> unfiltered) {
return Iterables.filter(unfiltered, filter);
}
protected IEObjectDescription filter(IEObjectDescription contentByEObject) {
if (!filter.apply(contentByEObject))
return null;
return contentByEObject;
}
public IScope scope_Ref_theEClass(Ref ref, EReference eReference) {
IScope delegateScope = delegateGetScope(ref,eReference);
return new FilteringScope(delegateScope, new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
if (...) {
return false;
}
return true;
}
});
}
the best would be to get all information you need out of the IEObjectDescription - you may have to adopt the creation of the IEObjectDescriptions too.
see here http://www.eclipse.org/forums/index.php?t=rview&goto=515 624&th=162954
and here http://www.eclipse.org/forums/index.php?t=msg&goto=55572 9
too
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Tue, 14 September 2010 11:59] Report message to a moderator
|
|
|
|
|
|
|
|
Re: scope problem [message #559127 is a reply to message #559107] |
Wed, 15 September 2010 16:53 |
|
Hi,
everything is possible - so this would be once more a place for using scoping.
quick and (maybe) dirty:
public IScope scope_ETypedElement_eType(EAttribute a, EReference r) {
return Scopes.scopeFor(Iterables.filter(EcorePackage.eINSTANCE.getEClassifiers(),EDataType.class));
}
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Wed, 15 September 2010 16:55] Report message to a moderator
|
|
|
|
|
|
|
|
Re: scope problem [message #559962 is a reply to message #559956] |
Mon, 20 September 2010 14:42 |
|
Hi,
A: type=[ecore::EClass];
here the problem might be that the A is not yet instantiated when the scoping is called - just debug the methodes in the scoping base class to get a hint what happens and how to write (the signature) of the scope_ method.
in the scope definition i would retrieve the position of the A element that i typing in "list"...
if i define the scope for element A I have the method call when i already choice the element...and i don't want that...
i do not understand this - sorry - as i said before a concrete model example and a descripion of what happens when you are doing what would be helpful.
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: scope problem [message #559965 is a reply to message #559962] |
Mon, 20 September 2010 14:49 |
|
Update:
in the scope definition i would retrieve the position of the A element that i typing in "list"...
if i define the scope for element A I have the method call when i already choice the element...and i don't want that...
do you mean that the scoping method is called when you use autocompletion at the place you define the scoping?
this is wanted behaviour - scoping defines the possible allowed values for a referece. maybe the thing you need is validation and not scoping.
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Re: scope problem [message #559979 is a reply to message #559976] |
Mon, 20 September 2010 15:32 |
|
Maybe i was not exact enhough in my answer
with a grammar like
CC: xxx=ID ('(' list+=A (',' list+=A)* ')');
A: {A} type=[ecore::EClass];
and scoping like
public IScope scope_A_type(CC c, EReference r) {
System.out.println(-1);
return delegateGetScope(c, r);
}
public IScope scope_A_type(A a, EReference r) {
System.out.println(((CC)a.eContainer()).getList().indexOf(a));
return delegateGetScope(a, r);
}
you will get it running but i cannot say how stable this will work.
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Re: scope problem [message #559988 is a reply to message #559987] |
Mon, 20 September 2010 16:02 |
chuck Messages: 160 Registered: July 2010 |
Senior Member |
|
|
yes...the -1 is printed...but this not execute the delegation to the aìother scope...i mean...the position of A element with the second print is not showed until i choice an A element....
[Updated on: Mon, 20 September 2010 16:03] Report message to a moderator
|
|
|
Re: scope problem [message #559990 is a reply to message #559988] |
Mon, 20 September 2010 16:05 |
|
right - but that is not the problem - as i said before this has to do with how xtext instatiates objects - so you may have to ask for the index (second case) or ask the list for its actual size.
Maybe you can find out a way to figure it out - this is all advice i can give you.
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Mon, 20 September 2010 16:07] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.05732 seconds