|
|
|
|
|
Re: Split model [message #1154764 is a reply to message #1154739] |
Fri, 25 October 2013 12:39 |
|
Hi,
you can traverste the index for references too...
@Inject
private ResourceDescriptionsProvider resourceDescriptionsProvider;
public boolean isReferenced(final EObject object) {
if (object.eIsProxy()) {
return false;
final IResourceDescriptions descriptions = getResourceDescriptions(object);
if (descriptions == null) {
LOG.error("'resourceDescriptions' wurden nicht gefunden.", new IllegalStateException());
} else {
final URI objectUri = EcoreUtil.getURI(object);
if (objectUri != null) {
final Iterable<IResourceDescription> allResourceDescriptions = descriptions
.getAllResourceDescriptions();
for (final IResourceDescription rd : allResourceDescriptions) {
for (final IReferenceDescription refd : rd.getReferenceDescriptions()) {
final URI targetEObjectUri = refd.getTargetEObjectUri();
if (objectUri.equals(targetEObjectUri)) {
return true;
}
}
}
}
}
return false;
}
public IResourceDescriptions getResourceDescriptions(final EObject object) {
Resource resource = object.eResource();
if (resource != null) {
return resourceDescriptionsProvider.getResourceDescriptions(resource);
} else {
//TODO
return null;
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
|
Re: Split model [message #1160752 is a reply to message #1160746] |
Tue, 29 October 2013 10:27 |
|
Depends on your implementation of checkUniqueAccounts
(if you set it to CheckType.NORMAL and use the index as i sugessted it should work)
same for the checkNotUsedAccounts (maybe it is better to make this check expensive)
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Re: Split model [message #1160905 is a reply to message #1160894] |
Tue, 29 October 2013 12:40 |
|
Hi,
i got it to download the zip.
it works as expected.
if i add an account to acounts and save it i get the warning as expected.
P.S: you have to retouch the account file if you added it to a settlement or
run a clean build on the project
P.PS: has your sample project any spaces in the name? or umlauts? maybe the normalzing/comparing of uris doesnt work as expected.
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Tue, 29 October 2013 12:43] Report message to a moderator
|
|
|
|
|
|
|
Re: Split model [message #1161077 is a reply to message #1161063] |
Tue, 29 October 2013 15:07 |
|
p.s.
maybe this one helps
import java.util.HashSet;
import java.util.Set;
import javax.inject.Inject;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.resource.IContainer;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.IResourceDescriptions;
import org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider;
public class Util {
@Inject
private IContainer.Manager containerManager;
@Inject
private ResourceDescriptionsProvider rdp;
public <T extends EObject> Set<T> getFromIndex(EObject ctx, final EClass type) {
final Set<T> result = new HashSet<T>();
ResourceSet rs = ctx.eResource().getResourceSet();
final IResourceDescriptions resDesc = rdp.getResourceDescriptions(rs);
final IResourceDescription resourceDescription = resDesc.getResourceDescription(ctx.eResource().getURI());
if (resourceDescription == null) {
return result;
}
final IContainer container = containerManager.getContainer(resourceDescription, resDesc);
for (final IResourceDescription indexedResourceDesc : container.getResourceDescriptions()) {
for (final IEObjectDescription ieod : indexedResourceDesc.getExportedObjectsByType(type)) {
if (ieod.getEClass().eIsProxy()) {
continue;
}
EObject proxy = ieod.getEObjectOrProxy();
rs.getResource(ieod.getEObjectURI().trimFragment(), true);
proxy = EcoreUtil.resolve(proxy, rs);
if (!proxy.eIsProxy()) {
result.add((T) proxy);
}
}
}
return result;
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
Re: Split model [message #1169950 is a reply to message #1169937] |
Mon, 04 November 2013 09:51 |
Gunnar Boström Messages: 26 Registered: February 2013 |
Junior Member |
|
|
Hi,
You have all the code in the uploaded project.
The result form getAllResourceDescriptions when accounts and settlements are in the same file:
[org.eclipse.xtext.builder.builderState.impl.ResourceDescriptionImpl@6c08ae6f (URI: platform:/resource/MyDsl/Both.mydsl, importedNames: null)]
The result form getAllResourceDescriptions when accounts and settlements are in different files:
[org.eclipse.xtext.builder.builderState.impl.ResourceDescriptionImpl@5afbfbc2 (URI: platform:/resource/MyDsl/Both.mydsl, importedNames: [c3, b2, a1, c5]), org.eclipse.xtext.builder.builderState.impl.ResourceDescriptionImpl@554dac38 (URI: platform:/resource/MyDsl/Accounts.mydsl, importedNames: null), org.eclipse.xtext.builder.builderState.impl.ResourceDescriptionImpl@5e65bc48 (URI: platform:/resource/MyDsl/Settlements.mydsl, importedNames: [])]
/Gunnar
|
|
|
|
|
|
|
Re: Split model [message #1170673 is a reply to message #1170190] |
Mon, 04 November 2013 20:18 |
|
Hi,
ok, i now see the problem.
the problem is that local references are actually not indexed. you have to check them yourself.
(you may have a look at org.eclipse.xtext.ui.editor.findrefs.DefaultReferenceFinder.findReferences(Iterable<URI>, Iterable<URI>, ILocalResourceAccess, IAcceptor<IReferenceDescription>, IProgressMonitor))
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05904 seconds