Only allow explicit imports [message #1856568] |
Thu, 15 December 2022 11:36  |
Eclipse User |
|
|
|
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?
[Updated on: Thu, 15 December 2022 11:38] by Moderator
|
|
|
|
|
Re: Only allow explicit imports [message #1856697 is a reply to message #1856669] |
Fri, 23 December 2022 03:51  |
Eclipse User |
|
|
|
No all files are visible everywhere by default
And the importednamespaceawarelocslc scopeprovider can be used to add explicit imports
This makes long names to short names as in java.
About the visibility of non. Local names you need to care about yourself
But with no details
( the example model younshared does not fit to ‚did not adapt anything')
It is hard to tell
|
|
|
Powered by
FUDForum. Page generated in 0.02997 seconds