2016-11-22 2 views
0

私はXtextで単純なDSLを作成し、それをインタプリタで実行しようとしていますが、文法は最初のHello Wordプロジェクトです。
.Textファイルを正常に実行できます。
org.xtext.example.mydsl.uiプロジェクトでは、plugin.xmlファイルに書き込みます。私のクラスLaunchMydslShortcutからプロジェクトを実行するには。Xtext、LaunchMydslShortcutのIselection入力を取得

<extension 
    point="org.eclipse.debug.ui.launchShortcuts"> 
<shortcut 
     class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.xtext.example.mydsl.ui.launch.LaunchMydslShortcut" 
     icon="icon/sample.gif" 
     id="org.xtext.example.mydsl.u.launchMyDsl" 
     label="MyDsll" 
     modes="run"> 

     <contextualLaunch> 
     <enablement> 
     <with variable="selection"> 
      <count value="1"/> 
      <iterate 
       ifEmpty="false" 
       operator="and"> 
       <adapt type="org.eclipse.core.resources.IFile"/> 
       <test property="org.eclipse.debug.ui.matchesPattern" 
         value="*.mydsl"/> 
      </iterate> 
     </with> 
     </enablement> 
     <contextLabel 
      mode="run" 
      label="Run Mydsl"/> 
    </contextualLaunch> 

</shortcut> 
</extension> 

これは私のLaunchMydslShortcutクラスです:

class LaunchMydslShortcut implements ILaunchShortcut { 
    @Inject 
    private IResourceForEditorInputFactory resourceFactory; 

    override launch(ISelection selection, String mode) { 
     println("launch from selection") 

    } 

    override launch(IEditorPart editor, String mode) { 
     val input = editor.editorInput 

     if (editor instanceof XtextEditor && input instanceof FileEditorInput) { 
      val resource = resourceFactory.createResource(input) 
      resource.load(newHashMap()) 
      println("launch Doooone") 
     } 
    } 
} 

はしかし、私はlaunch(IEditorPart editor, String mode)機能を使用することを期待していますが、それはlaunch(ISelection selection, String mode)を実行します。
質問があるので、両者の違いは何ですか?なぜ私のプロジェクトは最初のものを使用していますか?どのように私は2番目を使用するのですか?

答えて

0

たとえば、パッケージエクスプローラからジェネレータを起動すると、最初の1つが呼び出されます(void launch(ISelection selection, String mode))。

void launch(IEditorPart editor, String mode)は、エディタのコンテキストメニューから起動するときに呼び出されます。

ユーティリティを使用して、必要な入力ファイルを取得し、IResourceを作成することができます。

良い例はorg.eclipse.xtext.xtext.launcher.WorkflowLaunchUtils.workflowFileFor(ISelection)org.eclipse.xtext.xtext.launcher.WorkflowLaunchUtils.workflowFileFor(IEditorPart)です.mwe2ファイルで動作しますが、あなたのDSL用に採用するのは簡単です。

+0

githubリポジトリのリンクは次のとおりです。https://github.com/eclipse/xtext-eclipse/blob/master/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/launcher/ WorkflowLaunchUtils.java –

関連する問題