2015-11-16 2 views
1

Я создал новый DSL с помощью XText следующим образом. (На самом деле я получить доступ к DSL на RCP приложения.)ссылка кросс-файл в XText

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals 

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl" 


Configuration: 
components+=(Component)*; 

Component: 
'Component' name=ID 
'{' 
(('display' display=STRING) & 
('dependency' dependency=[Component|ID])?) 
'}' 
; 

У меня есть два файла: sample1.mydsl

Component comp1 { 
    display "comp1" 
    dependency comp2 
} 

sampl2.mydsl

Component comp2 { 
    display "comp2" 
} 

Чтобы проверить ссылку из другого файла, Я попытался запустить тестовый код как автономный, но я не смог точно получить eobject.

тестовый код

public static final void main(String arg[]) { 
    new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("../"); 
    Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration(); 
    XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); 
    resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); 
    File file=new File("/Users/nuckee/Work/temp/mydsl/sample1.mydsl"); 
    Resource resource = resourceSet.getResource(
      URI.createURI(file.toURI().toString()), true); 

    Configuration config = (Configuration) resource.getContents().get(0); 
    Component comp1 = config.getComponents().get(0); 
    if (comp1 != null) { 
     System.out.println("configuration displayed name : " + comp1.getDisplay()); 
     Component dep = comp1.getDependency() ; 
     if (dep != null) { 
      System.out.println("dep : " + dep); 
      System.out.println("dep displayed name : " + dep.getDisplay()); 
     } 
    } 
} 

результат

configuration displayed name : comp1 
    dep : [email protected] (eProxyURI: file:/Users/nuckee/Work/temp/mydsl/sample1.mydsl#|0) 
    dep displayed name : null 

Как именно я могу получить отображение "comp2" из другого файла?

Я надеюсь, кто-то может помочь мне решить эту проблему. Благодарю.

+0

вы должны загрузить все Релевент файлы в ResourceSet себя –

+0

@Christian Dietrich Я не загрузит все файлы. ;; Теперь он работает хорошо. Спасибо. – user2663410

ответ

0

Вы должны загрузить все файлы модели в ResourceSet. XText не делает открытие файла автоматической

Смежные вопросы