Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Re-exporting imported namespace
Re-exporting imported namespace [message #792049] Mon, 06 February 2012 14:53
Christian Schulze is currently offline Christian SchulzeFriend
Messages: 8
Registered: October 2011
Junior Member
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
Previous Topic:Xtext 2.3 break Google Protobuf Editor
Next Topic: Larger JVM model inferrer examples?
Goto Forum:
  


Current Time: Thu Sep 19 21:05:42 GMT 2024

Powered by FUDForum. Page generated in 0.03020 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top