[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.tmf] Re: Cross reference
|
Hi ouakib,
afaik you can restrict the reference to attributes of the same class by providing your own ScopeProvider (see [1]). Here is some pseudo code, hope it helps:
public IScope scope_Attribute_name(Attribute context, EReference reference){
// get all elements of the class
EList<Element> elements = ((Class)context.eContainer).getElt();
// get attributes
Collection<Attribute> attributes = EcoreUtil.getObjectsByType(elements, YourDSLPackage.eINSTANCE.getAttribute());
Iterable<IScopedElement> scopedElements = Scopes.scopedElementsFor(attributes, new Function<EObject, String>() {
public String apply(EObject from) {
return (((Attribute)from).getName());
}
});
return new SimpleScope(IScope.NULLSCOPE, scopedElements);
}
Regards,
ILyas
------
[1] http://www.eclipse.org/Xtext/documentation/0_7_2/xtext.html#scoping
ouakib schrieb:
Hi all ,
this is my grammar :
Root: (root+=Model)* ;
Class: "class" name=ID (elt+=Element)* ;
Element : Attribute | Ref ;
Attribute : "var" name=ID ;
Ref : "ref" name=[Attribute|ID] ;
the attribute "name" in the element "Ref" references all the elements
"Attribute" in the model How I can restrict this reference to reference
only the "Attributres " which exists in then same "Class"
for instance in this model :
class class1
var var1 var var2
class class 2
var var3
var var4
ref var1
the reference to var1 from class2 must not work because var1 must be
in class1.