0

私はxTextを使用してDSLを開発し、最近somme拡張補完を追加しました。Ctrl-Spaceでコンプリーションを呼び出すときにxTextで生成されたエディターでは、コンプリーションハンドラーは、同じDSLの別のテキストファイルでシンボルを探すためにフォルダースキャンを実行する必要があります。エントリポイントは次のとおりです。

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モデルにデータを入力します。

私のおおよその英語(私はフランス語です)をご理解いただければ幸いです...

4

2 に答える 2

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())
         {
            ...
         }
      }
   }
}
于 2012-10-11T17:52:54.107 に答える
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. 

お役に立てれば。

于 2012-10-11T12:56:53.383 に答える