|
|
|
|
|
Re: How can I get the referencing objects for a certain object [message #1706116 is a reply to message #1706112] |
Sun, 23 August 2015 17:43 |
|
that should be straigr forward ?!?
Model:
declarations+=Declarations*
expressions+=Expression*
strangeThing+=StangeThing*
;
Declarations:
'declaration' name=ID '{' '}'
;
Expression:
'expression' name=ID 'using' declaration=[Declarations] '{'
'}'
;
StangeThing:
"strange" "thing" "for" declaration=[Declarations] "with" expr=[Expression]
;
public class MyDslResourceDescriptionStrategy extends DefaultResourceDescriptionStrategy {
@Override
public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDescription> acceptor) {
if (eObject instanceof Expression) {
Map<String, String> data = new HashMap<>();
data.put("DEF", NodeModelUtils.findNodesForFeature(eObject, MyDslPackage.Literals.EXPRESSION__DECLARATION).get(0).getText());
IEObjectDescription d = EObjectDescription.create(getQualifiedNameProvider().getFullyQualifiedName(eObject), eObject, data );
acceptor.accept(d);
}
return super.createEObjectDescriptions(eObject, acceptor);
}
}
class MyDslScopeProvider extends org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider {
def IScope scope_StrangeThing_expr(StrangeThing ctx, EReference ref) {
val name = ctx.declaration.name
val locals = <Declarations>newArrayList
// todo collect locals manually
// ...
Scopes.scopeFor(locals, new FilteringScope(delegateGetScope(ctx,ref),[
name == getUserData("DEF")
]))
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: How can I get the referencing objects for a certain object [message #1706907 is a reply to message #1706904] |
Mon, 31 August 2015 17:49 |
|
Have a look at
* org.eclipse.xtext.resource.IContainer.Manager.getVisibleContainers(IResourceDescription, IResourceDescriptions) to get a list of containers.
* a container can be asked for org.eclipse.xtext.resource.ISelectable.getExportedObjectsByType(EClass) - may give you all decls/expresions
* a container can be asked for org.eclipse.xtext.resource.IContainer.getResourceDescriptions()
* a IResourceDescription can be asked for org.eclipse.xtext.resource.IResourceDescription.getReferenceDescriptions()
* a IReferenceDescription has a source and target object uri and the reference it represents - reference should be of type type you search for, target uri should point to the stuff you are looking for
* as said before IReferenceDescription is created for non local refs
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.05359 seconds