Only allow explicit imports [message #1856568] |
Thu, 15 December 2022 16:36  |
|
Hello,
I have a grammar that uses the importedNamespace mechanism.
QualifiedID:
ID (QID_SEPARATOR ID)*
;
Import:
'import' (alias=ID EQUALS)? importedNamespace=QualifiedID SEMI
;
So I can write
package main;
import second;
class A extends B {
}
The problem is that out of the box B can be referenced EVEN without the import because XText adds all resources in the project to the local scope. To limit this, I created my own GlobalScopeProvider that filters out all resources in the project:
@Override
protected IScope getScope(
final Resource context,
boolean ignoreCase,
EClass type,
Predicate<IEObjectDescription> filter) {
...
Predicate<IEObjectDescription> resFilter = new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
// Filter out if not in the same resource
URI inputBase = input.getEObjectURI().trimFragment();
return inputBase.hashCode() == context.getURI().hashCode();
}
};
if (filter != null) {
resFilter = (Predicate<IEObjectDescription>) filter.and(resFilter);
}
...
}
But after adding the import, B can't be found. I think the issue is that the "ImportedNamespaceAwareLocalScopeProvider" would eventually use the GlobalScope, which is filtered.
Is there a way to make this work?
Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
[Updated on: Thu, 15 December 2022 16:38] Report message to a moderator
|
|
|
|
Re: Only allow explicit imports [message #1856669 is a reply to message #1856571] |
Wed, 21 December 2022 21:44   |
|
Thanks for the reply Christian.
I have not modified the ImportedNamespaceAwareLocalScopeProvider (yet).
I see the AliasedEObjectDescription being created in the ImportScope. However, the getImportFrom() in that class uses the parent scope which is filtered so I never see the elements from the second file in order to import them. Do I need to add them manually in my ImportedNamespaceAwareLocalScopeProvider?
Thanks,
Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
|
|
|
|
Powered by
FUDForum. Page generated in 1.34812 seconds