I'm using the "ImportedNamespaceAwareLocalScopeProvider".
Unfortunately the code I need to parse allows to re-export imported namespaces.
For example:
namespace A {
entity E { ... };
}
namespace B {
import A.E; // "A.E" needs to get re-exported as "B.E"
}
namespace C {
import B.E;
entity E2 : E { ... };
}
So I extended the DefaultDeclarativeQualifiedNameProvider to name my import directive so that it get's included in the index.
QualifiedName qualifiedName(Import e) {
String importedNamespace = e.getImportedNamespace();
int index = importedNamespace.lastIndexOf(".");
String className = importedNamespace.substring(index + 1);
return getFullyQualifiedName(e.eContainer()).append(className);
}
Now the imports get re-exported under the new namespace but the EObject type is now "Import" not "Entity".
I played a bit with the "DefaultResourceDescriptionStrategy" to resolve all imported symbols so that I can set the actual EObject type of the import when it get's re-exported.
@Inject
IQualifiedNameConverter converter;
@Inject
ResourceDescriptionsProvider resourceDescriptionsProvider;
@Inject
IContainer.Manager containerManager;
public boolean createEObjectDescriptions(org.eclipse.emf.ecore.EObject eObject, IAcceptor<IEObjectDescription> acceptor) {
if(eObject instanceof Import) {
Import import= (Import)eObject;
IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions(import.eResource());
IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(import.eResource().getURI());
for (IContainer c : containerManager.getVisibleContainers(resourceDescription, resourceDescriptions)) {
Iterable<IEObjectDescription> exportedObjects = c.getExportedObjects();
for(IEObjectDescription descr : exportedObjects) {
if(converter.toString(descr.getQualifiedName()).equals(import.getImportedNamespace())) {
System.out.println("Exporting " + import.getImportedNamespace() + " as " + descr.getEClass());
QualifiedName qualifiedName = getQualifiedNameProvider().getFullyQualifiedName(eObject);
acceptor.accept(EObjectDescription.create(qualifiedName, descr.getEObjectOrProxy()));
return false;
}
}
}
return false;
} else {
return super.createEObjectDescriptions(eObject, acceptor);
}
}
Unfortunately the above-mentioned code is not working. It seems that the "IContainer.Manager" isn't fully initialized at this stage.
Does someone know if and how it's possible to re-export imported symbols under their actual EObject type?
Many thanks in advance,
Christian