| Validating model in Eclipse UI context before interpreting it [message #724832] |
Tue, 13 September 2011 06:15  |
Eclipse User |
|
|
|
Hi, I would like to know how I can validate resource in Eclipse context - i.e. without need to create a standalone injector.
I created an interpreter that gets executed from Eclipse run configuration. Before I interpret the AST I need to validate given resource and its dependencies to make sure it will run correctly. So far I did this with validator created by standalone injector, which works fine. When I try to create the validator from UI injector (which is I suppose the injector I should use in Eclipse context) and run it, it will show linking errors. I suspect that the validator created in UI context uses wrong resource set. This is the code, which does not work when I inject validator using UI plugin injector:
@Inject
// injected by UI injector
private IResourceValidator validator;
ResourceSet resourceSet = new ResourceSetImpl();
// loads all resources in project to resource set; returns the resource to interpret
Resource resource = loadResourcesToResourceSet(resourceSet, iresource);
// will show linking issues (Couldn't find reference to ...) even though there are no problems;
validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
Am I doing something wrong here? Do I need to load all resources to resource set (for standalone validator I had to do this)? How does the UI editor validate resources? I need to do exactly the same thing. I don't want to use the standalone injector because I suspect it messes up Eclipse registries and after its call not everything works correctly (e.g. cleaning project does not work).
Thanks for help, anything will be appreciated.
|
|
|
|
| Re: Validating model in Eclipse UI context before interpreting it [message #724881 is a reply to message #724832] |
Tue, 13 September 2011 07:59   |
Eclipse User |
|
|
|
Hi,
please use an injected XtextResourceSetProvider to obtain an instanceof
of ResourceSet.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
On 13.09.11 12:15, Kristian Nagy wrote:
> Hi, I would like to know how I can validate resource in Eclipse context
> - i.e. without need to create a standalone injector.
>
> I created an interpreter that gets executed from Eclipse run
> configuration. Before I interpret the AST I need to validate given
> resource and its dependencies to make sure it will run correctly. So far
> I did this with validator created by standalone injector, which works
> fine. When I try to create the validator from UI injector (which is I
> suppose the injector I should use in Eclipse context) and run it, it
> will show linking errors. I suspect that the validator created in UI
> context uses wrong resource set. This is the code, which does not work
> when I inject validator using UI plugin injector:
>
> @Inject
> // injected by UI injector
> private IResourceValidator validator;
>
> ResourceSet resourceSet = new ResourceSetImpl();
> // loads all resources in project to resource set; returns the resource
> to interpret
> Resource resource = loadResourcesToResourceSet(resourceSet, iresource);
> // will show linking issues (Couldn't find reference to ...) even though
> there are no problems; validator.validate(resource, CheckMode.ALL,
> CancelIndicator.NullImpl);
>
>
> Am I doing something wrong here? Do I need to load all resources to
> resource set (for standalone validator I had to do this)? How does the
> UI editor validate resources? I need to do exactly the same thing. I
> don't want to use the standalone injector because I suspect it messes up
> Eclipse registries and after its call not everything works correctly
> (e.g. cleaning project does not work).
>
> Thanks for help, anything will be appreciated.
>
|
|
|
| Re: Validating model in Eclipse UI context before interpreting it [message #724885 is a reply to message #724840] |
Tue, 13 September 2011 08:11   |
Eclipse User |
|
|
|
I load the resource to some resource set. Perhaps it is not the right resource set? I changed the code now like this (I try to inject ResourceSet this time) but it still shows linking issues:
@Inject
private IResourceValidator validator;
@Inject
private ResourceSet resourceSet;
void validate() {
Injector interpretationInjector = MyLangaugeActivator.getInstance().getInjector("com.examples.MyLanguage");
interpretationInjector.injectMembers(this);
// File T1 uses constructs in file T2 (no errors in UI view)
resourceSet.getResource(URI.createFileURI("C:\\T2.test"), true);
Resource resource = resourceSet.getResource(URI.createFileURI("C:\\T1.test"), true);
System.out.println(validator.validate(resource, CheckMode.ALL, null));
}
When I debug the validate function, I see that resource.getResourceSet() is populated correctly ( = SynchronizedXtextResourceSet resources=[uri='file:/C:/T2.test', uri='file:/C:/T1.test']).
What is very strange is that this works without any validation errors:
void validate() {
new MyLanguageStandaloneSetup().createInjectorAndDoEMFRegistration();
Injector interpretationInjector = MyLangaugeActivator.getInstance().getInjector("com.examples.MyLanguage");
interpretationInjector.injectMembers(this);
// File T1 uses constructs in file T2 (no errors in UI view)
resourceSet.getResource(URI.createFileURI("C:\\T2.test"), true);
Resource resource = resourceSet.getResource(URI.createFileURI("C:\\T1.test"), true);
System.out.println(validator.validate(resource, CheckMode.ALL, null));
}
This is exactly the same code, but this time I create a standalone setup as the first line. I don't use the standalone injector, it's still the UI plugin injector. Seems to me like the EMFRegistration has some side effects on validation ? Any ideas?
[Updated on: Tue, 13 September 2011 08:44] by Moderator
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04193 seconds