Skip to main content



      Home
Home » Modeling » TMF (Xtext) » PersistableResourceDescriptionsImpl validates the resource
PersistableResourceDescriptionsImpl validates the resource [message #632846] Thu, 14 October 2010 09:32 Go to next message
Eclipse UserFriend
Hi,
if I save my model file, the validations are called twice. At first the editor checks the file to update error markers. Later the resource is updated in the Xtext index, which validates again and updates the markers.

Is the second check necessary for global scope and references outside the file?
I wrote checks to check if an element is referenced somewhere in the Xtext index, but this check was executed after a clean before the ResourceDescriptions are complete.

Benjamin
Re: PersistableResourceDescriptionsImpl validates the resource [message #633044 is a reply to message #632846] Fri, 15 October 2010 04:09 Go to previous messageGo to next message
Eclipse UserFriend
Am 10/14/10 3:32 PM, schrieb Benjamin Schwertfeger:
> Hi,
> if I save my model file, the validations are called twice. At first the
> editor checks the file to update error markers. Later the resource is
> updated in the Xtext index, which validates again and updates the markers.
>
> Is the second check necessary for global scope and references outside
> the file?

It is neccessary to update the Markers.
Within the editor only Annotations are updated.

> I wrote checks to check if an element is referenced somewhere in the
> Xtext index, but this check was executed after a clean before the
> ResourceDescriptions are complete.

Yeah, the validation is called just before the changed
IResourceDescriptions is updated. I don't see why we need to do that.
Could you please open a bugzilla?

Thanks,
Sven


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: PersistableResourceDescriptionsImpl validates the resource [message #633065 is a reply to message #633044] Fri, 15 October 2010 04:50 Go to previous messageGo to next message
Eclipse UserFriend
Am 10/15/10 10:09 AM, schrieb Sven Efftinge:
>> I wrote checks to check if an element is referenced somewhere in the
>> Xtext index, but this check was executed after a clean before the
>> ResourceDescriptions are complete.

Sebastian reminded me that you should use the same IResourceDescriptions
used in the AbstractGlobalScopeProvider you will get a view on the
IResourceDescriptions containing the old state, shadowed by the new
state (And most important without the dirty resource information).

This is the relevant code o obtain the right IResourceDescriptions based
on the current context (we should encaspulate that better):

@Inject
@Named(NAMED_BUILDER_SCOPE)
private Provider<IResourceDescriptions>
builderScopeResourceDescriptions;

@Inject
private Provider<IResourceDescriptions> resourceDescriptions;

public IResourceDescriptions getResourceDescriptions(EObject ctx) {
Map<Object, Object> loadOptions = ctx.eResource().getResourceSet()
.getLoadOptions();
IResourceDescriptions result = createResourceDescriptions();
if (loadOptions.containsKey(NAMED_BUILDER_SCOPE)) {
result = createBuilderScopeResourceDescriptions();
}
if (result instanceof IResourceDescriptions.IContextAware) {
((IResourceDescriptions.IContextAware) result).setContext(ctx);
}
return result;
}


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: PersistableResourceDescriptionsImpl validates the resource [message #633082 is a reply to message #633065] Fri, 15 October 2010 06:17 Go to previous messageGo to next message
Eclipse UserFriend
Thanks,
I tried to get the two resource descriptions and use the builder one, if the loadOption is set. If I save the file, the builderScopeResourceDescriptions are asked for resources and throw a NPE because of not set resource descriptions inside the ShadowingResourceDescriptions:

@Inject
private IResourceDescriptions resourceDescriptions;
@Inject
@Named(AbstractGlobalScopeProvider.NAMED_BUILDER_SCOPE)
private Provider<IResourceDescriptions> builderScopeResourceDescriptionsProvider;

public boolean isReferenced(final EObject object) {
         IResourceDescriptions descriptions = resourceDescriptions;
         Map<Object, Object> loadOptions = object.eResource().getResourceSet().getLoadOptions();
         if (Boolean.TRUE.equals(loadOptions.get(AbstractGlobalScopeProvider.NAMED_BUILDER_SCOPE))) {
                 descriptions = builderScopeResourceDescriptionsProvider.get();
         }
//this throws the exception after save:
         final Iterable<IResourceDescription> allResourceDescriptions = descriptions.getAllResourceDescriptions();
Re: PersistableResourceDescriptionsImpl validates the resource [message #633118 is a reply to message #633082] Fri, 15 October 2010 08:29 Go to previous message
Eclipse UserFriend
You missed the following :

if (result instanceof IResourceDescriptions.IContextAware) {
((IResourceDescriptions.IContextAware) result).setContext(ctx);
}

Sven


Am 10/15/10 12:17 PM, schrieb Benjamin Schwertfeger:
> Thanks,
> I tried to get the two resource descriptions and use the builder one, if
> the loadOption is set. If I save the file, the
> builderScopeResourceDescriptions are asked for resources and throw a NPE
> because of not set resource descriptions inside the
> ShadowingResourceDescriptions:
>
>
> @Inject
> private IResourceDescriptions resourceDescriptions;
> @Inject
> @Named(AbstractGlobalScopeProvider.NAMED_BUILDER_SCOPE)
> private Provider<IResourceDescriptions>
> builderScopeResourceDescriptionsProvider;
>
> public boolean isReferenced(final EObject object) {
> IResourceDescriptions descriptions = resourceDescriptions;
> Map<Object, Object> loadOptions =
> object.eResource().getResourceSet().getLoadOptions();
> if
> (Boolean.TRUE.equals(loadOptions.get(AbstractGlobalScopeProv ider.NAMED_BUILDER_SCOPE)))
> {
> descriptions =
> builderScopeResourceDescriptionsProvider.get();
> }
> //this throws the exception after save:
> final Iterable<IResourceDescription> allResourceDescriptions =
> descriptions.getAllResourceDescriptions();
>


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Previous Topic:Back references
Next Topic:Internationalisation with Xtext
Goto Forum:
  


Current Time: Sun Jul 20 23:54:56 EDT 2025

Powered by FUDForum. Page generated in 0.66564 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top