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 #1856571 is a reply to message #1856568] |
Thu, 15 December 2022 18:34   |
|
Assuming
You import will be semantically a
Import second.*
(Your sample does not show what part of the ImportedNamespaceAwareLocalScopeProvideR customization)
You can use a filtering scope. Then if the uri differes, and the element is imported, the imported IEObjectDescription will be an AliasedEObjectDescription
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
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
|
|
|
Re: Only allow explicit imports [message #1856697 is a reply to message #1856669] |
Fri, 23 December 2022 08:51  |
|
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
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.02317 seconds