Pregunta

I have developed a DSL with xText and recently add somme enhanced completion. In a xText-generated editor when calling completion by Ctrl-Space, the completion handler has to perform a folder scanning to look for symbols in another text file of the same DSL. The entry point is :

public class TypesProposalProvider extends AbstractTypesProposalProvider
{
   public void completeQualifiedName_Path(
      EObject                     model,
      Assignment                  assignment,
      ContentAssistContext        context,
      ICompletionProposalAcceptor acceptor )
   {
      super.completeQualifiedName_Path( model, assignment, context, acceptor );

I use:

      Model root = (Model) context.getRootModel();
      Resource rootRc = root.eResource();

to obtain the emf.ecore container of the model.

And now, how can I look for sibling resources, the other files in the same folder, in term of ecore resource?

With the another resources, I'll call Resource.load() to populate the underlaying emf.ecore model of the siblings.

I hope you understand my approximative English (I'm French)...

¿Fue útil?

Solución 2

Here is the final version, compact as usual ;-) :

Resource   rootRc = root.eResource();
String     rcPath = rootRc.getURI().toPlatformString( true );
IFile      file   = (IFile)ResourcesPlugin.getWorkspace().getRoot().findMember( rcPath );
IContainer parent = file.getParent();
for( IResource member : parent.members())
{
   String ext = member.getFileExtension();
   if( ext != null && ext.equals( "types" ))
   {
      String prefix     = member.getName();
      String path       = member.getLocation().toString();
      URI    uriSibling = URI.createFileURI( path );
      prefix = prefix.substring( 0, prefix.length() - ".types".length());
      if( ! rcPath.endsWith( '/' + prefix + ".types" )
         && ( context.getPrefix().isEmpty() || prefix.startsWith( cntxtPrefix )))
      {
         Resource types  = rs.createResource( uriSibling );
         types.load( null );
         for( EObject rc : types.getContents())
         {
            ...
         }
      }
   }
}

Otros consejos

I am assuming that the sibling models dont refer each other. In that case you can use WorkspaceSynchronizer to get the file from the resource.

Example

Resource rootRc = root.eResource();
IFile file = WorkspaceSynchronizer.getFile(rootRc);

IResource parent = file.getParent();

Iresource[] childern = parent.members();

for(<iterate over children>)
     load the children resources. 

Hope this helps.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top