osate / osate2

Open Source AADL2 Tool Environment
http://osate.org
Eclipse Public License 2.0
37 stars 8 forks source link

'Aadl2StandaloneSetup' resource injection no longer works in OSATE 2.14. #2895

Closed schwerdf closed 3 months ago

schwerdf commented 4 months ago

I am using the Aadl2StandaloneSetup API to invoke the AADL parser outside of an editor window, as follows:

public class AADLXtextParser {
    @Inject
    private XtextResourceSet resourceSet;

    private void setupParser() {
        Aadl2StandaloneSetup setup = new Aadl2StandaloneSetup();
        Injector injector = setup.createInjector();
        injector.injectMembers(this);
        resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
    }
}

In OSATE versions up to and including 2.13, the injector will populate the resourceSet field with the workspace's resource set. In 2.14, it does nothing, causing a NullPointerException on the call to addLoadOption.

lwrage commented 3 months ago

Does it work if you use this code?

public class AADLXtextParser {
    private XtextResourceSet resourceSet;

    private void setupParser() {
        Aadl2StandaloneSetup setup = new Aadl2StandaloneSetup();
        Injector injector = setup.createInjector();
        injector.getInstance(XtextResourceSet.class);
        resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
    }
}
schwerdf commented 3 months ago

Not verbatim, but it does work if I explicitly assign the return value from getInstance to the field:

public class AADLXtextParser {
    private XtextResourceSet resourceSet;

    private void setupParser() {
        Aadl2StandaloneSetup setup = new Aadl2StandaloneSetup();
        Injector injector = setup.createInjector();
        resourceSet = injector.getInstance(XtextResourceSet.class);
        resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
    }
}
lwrage commented 3 months ago

Oops, missed the assignment, but you got the idea. This shows that the issue is actually the processing of the annotation, so it has nothing to do with OSATE.