1
votes

I created a new DSL by using xtext as follows. (Actually I will access the DSL on RCP application.)

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])?)
'}'
;

I have two files: sample1.mydsl

Component comp1 {
    display "comp1"
    dependency comp2
}

sampl2.mydsl

Component comp2 {
     display "comp2"
}

To check the reference from another file, I tried to run a test code as standalone but I couldn't get the eobject exactly.

test code

 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());
        }
    }
}

result

  configuration displayed name : comp1
  dep : org.xtext.example.mydsl.myDsl.impl.ComponentImpl@61544ae6 (eProxyURI: file:/Users/nuckee/Work/temp/mydsl/sample1.mydsl#|0)
  dep displayed name : null

How can exactly I get the display of "comp2" from another file?

I Hope someone can help me solve it. Thanks.

1
you have to load all relevent files to the resourceset yourself - Christian Dietrich
@Christian Dietrich I didn't load all files. ;; It works well now. Thank you. - user2663410

1 Answers

1
votes

You have to load all model files into the resourceset. Xtext does not do auto file discovery