2012-10-10 49 views
0

我開發了一個帶有xText的DSL,並且最近添加了somme增強完成功能。 在通過Ctrl-Space完成調用完成的xText生成的編輯器中,完成處理程序必須執行文件夾掃描以在同一DSL的另一個文本文件中查找符號。 入口點是:如何掃描包含同級資源的EMF資源的文件夾

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

我用:

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

獲得該模型的emf.ecore容器。

現在,我怎樣才能找到兄弟資源,其他文件在ecore資源的同一文件夾中?

用另一個資源,我會調用Resource.load()來填充兄弟的下層emf.ecore模型。

我希望你明白我的近似英語(我是法國人)...

回答

0

這裏是最後的版本,緊湊像往常一樣;-):

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()) 
     { 
      ... 
     } 
     } 
    } 
} 
0

我假設同級車型不指對方。在這種情況下,您可以使用WorkspaceSynchronizer從資源中獲取文件。

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. 

希望這有助於。

+0

'WorkspaceSynchronizer' 在我的版本的Eclipse朱諾/ JDT的不被認可。 – Aubin

+0

您需要將「org.eclipse.emf.workspace」插件添加到您的依賴項中。 – bhatanant2

+0

WorkspaceSynchronizer無法解析 – Aubin