use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-core by eclipse.
the class DefaultReferenceDescriptionTest method testgetReferenceDescriptions.
@Test
public void testgetReferenceDescriptions() throws Exception {
with(new LangATestLanguageStandaloneSetup());
XtextResource targetResource = getResource("type C", "bar.langatestlanguage");
EObject typeC = targetResource.getContents().get(0).eContents().get(0);
XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
resource.load(new StringInputStream("type A extends C type B extends A"), null);
EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
assertEquals(1, collection.size());
IReferenceDescription refDesc = descriptions.iterator().next();
Main m = (Main) resource.getParseResult().getRootASTElement();
assertEquals(m.getTypes().get(0), resource.getResourceSet().getEObject(refDesc.getSourceEObjectUri(), false));
assertEquals(typeC, resource.getResourceSet().getEObject(refDesc.getTargetEObjectUri(), false));
assertEquals(-1, refDesc.getIndexInList());
assertEquals(LangATestLanguagePackage.Literals.TYPE__EXTENDS, refDesc.getEReference());
}
use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-core by eclipse.
the class ResourceStorageWritable method convertExternalURIsToPortableURIs.
protected void convertExternalURIsToPortableURIs(final SerializableResourceDescription description, final StorageAwareResource resource) {
Iterable<IReferenceDescription> _referenceDescriptions = description.getReferenceDescriptions();
for (final IReferenceDescription ref : _referenceDescriptions) {
URI _trimFragment = ref.getTargetEObjectUri().trimFragment();
URI _uRI = resource.getURI();
boolean _notEquals = (!Objects.equal(_trimFragment, _uRI));
if (_notEquals) {
URI _elvis = null;
URI _portableURI = resource.getPortableURIs().toPortableURI(resource, ref.getTargetEObjectUri());
if (_portableURI != null) {
_elvis = _portableURI;
} else {
URI _targetEObjectUri = ref.getTargetEObjectUri();
_elvis = _targetEObjectUri;
}
((SerializableReferenceDescription) ref).setTargetEObjectUri(_elvis);
}
}
}
use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-core by eclipse.
the class DefaultCallHierarchyBuilder method findSourceDeclarations.
protected void findSourceDeclarations(final URI targetDeclarationURI, final IProgressMonitor monitor, final Procedure2<? super IEObjectDescription, ? super IReferenceDescription> acceptor) {
final TargetURIs targetURIs = this.collectTargetURIs(targetDeclarationURI);
IResourceServiceProvider.Registry _resourceServiceProviderRegistry = this.getResourceServiceProviderRegistry();
final IAcceptor<IReferenceDescription> _function = (IReferenceDescription reference) -> {
boolean _filterReference = this.filterReference(reference);
if (_filterReference) {
IEObjectDescription _findSourceDeclaration = null;
if (reference != null) {
_findSourceDeclaration = this.findSourceDeclaration(reference);
}
final IEObjectDescription sourceDeclaration = _findSourceDeclaration;
acceptor.apply(sourceDeclaration, reference);
}
};
ReferenceAcceptor _referenceAcceptor = new ReferenceAcceptor(_resourceServiceProviderRegistry, _function);
this.getReferenceFinder().findAllReferences(targetURIs, this.getResourceAccess(), this.getIndexData(), _referenceAcceptor, monitor);
}
use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-core by eclipse.
the class DefaultReferenceDescriptionTest method testgetReferenceDescriptionForMultiValue.
@Test
public void testgetReferenceDescriptionForMultiValue() throws Exception {
with(new LangATestLanguageStandaloneSetup());
XtextResource targetResource = getResource("type C type D", "bar.langatestlanguage");
EObject typeC = targetResource.getContents().get(0).eContents().get(0);
EObject typeD = targetResource.getContents().get(0).eContents().get(1);
XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
resource.load(new StringInputStream("type A implements B,C,D type B"), null);
EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
assertEquals(2, collection.size());
Iterator<IReferenceDescription> iterator = descriptions.iterator();
IReferenceDescription refDesc1 = iterator.next();
IReferenceDescription refDesc2 = iterator.next();
Main m = (Main) resource.getParseResult().getRootASTElement();
assertEquals(m.getTypes().get(0), resource.getResourceSet().getEObject(refDesc1.getSourceEObjectUri(), false));
assertEquals(typeC, resource.getResourceSet().getEObject(refDesc1.getTargetEObjectUri(), false));
assertEquals(1, refDesc1.getIndexInList());
assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS, refDesc1.getEReference());
assertEquals(m.getTypes().get(0), resource.getResourceSet().getEObject(refDesc2.getSourceEObjectUri(), false));
assertEquals(typeD, resource.getResourceSet().getEObject(refDesc2.getTargetEObjectUri(), false));
assertEquals(2, refDesc2.getIndexInList());
assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS, refDesc2.getEReference());
}
use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-core by eclipse.
the class DefaultReferenceDescriptionTest method testSpecialReferences.
@Test
public void testSpecialReferences() {
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("test");
ePackage.setNsPrefix("test");
ePackage.setNsURI("test");
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("Test");
eClass.getESuperTypes().add(EcorePackage.Literals.EPACKAGE);
ePackage.getEClassifiers().add(eClass);
EReference eReference1 = EcoreFactory.eINSTANCE.createEReference();
eReference1.setContainment(false);
eReference1.setName("onlyExportedRef");
eReference1.setEType(EcorePackage.Literals.EPACKAGE);
eClass.getEStructuralFeatures().add(eReference1);
EReference eReference2 = EcoreFactory.eINSTANCE.createEReference();
eReference2.setContainment(true);
eReference2.setName("containmentRef");
eReference2.setEType(EcorePackage.Literals.EPACKAGE);
eClass.getEStructuralFeatures().add(eReference2);
EReference eReference3 = EcoreFactory.eINSTANCE.createEReference();
eReference3.setContainment(false);
eReference3.setTransient(true);
eReference3.setName("transientRef");
eReference3.setEType(EcorePackage.Literals.EPACKAGE);
eClass.getEStructuralFeatures().add(eReference3);
EReference eReference4 = EcoreFactory.eINSTANCE.createEReference();
eReference4.setContainment(false);
eReference4.setVolatile(true);
eReference4.setName("volatileRef");
eReference4.setEType(EcorePackage.Literals.EPACKAGE);
eClass.getEStructuralFeatures().add(eReference4);
EReference eReference5 = EcoreFactory.eINSTANCE.createEReference();
eReference5.setContainment(false);
eReference5.setDerived(true);
eReference5.setName("derivedRef");
eReference5.setEType(EcorePackage.Literals.EPACKAGE);
eClass.getEStructuralFeatures().add(eReference5);
EObject object = ePackage.getEFactoryInstance().create(eClass);
object.eSet(EcorePackage.Literals.ENAMED_ELEMENT__NAME, "testname");
object.eSet(eReference1, EcorePackage.eINSTANCE);
object.eSet(eReference2, ePackage.getEFactoryInstance().create(eClass));
object.eSet(eReference3, EcorePackage.eINSTANCE);
object.eSet(eReference4, EcorePackage.eINSTANCE);
object.eSet(eReference5, EcorePackage.eINSTANCE);
Resource testResource = new XMIResourceImpl(URI.createPlatformResourceURI("test.ecore", true));
testResource.getContents().add(object);
IResourceDescription resourceDescription = createResourceDescription(testResource);
assertEquals("Only one external reference expected", 1, size(resourceDescription.getReferenceDescriptions()));
IReferenceDescription referenceDescription = resourceDescription.getReferenceDescriptions().iterator().next();
assertEquals(-1, referenceDescription.getIndexInList());
assertEquals(EcoreUtil.getURI(object), referenceDescription.getSourceEObjectUri());
assertEquals(eReference1, referenceDescription.getEReference());
assertEquals(EcoreUtil.getURI(EcorePackage.eINSTANCE), referenceDescription.getTargetEObjectUri());
assertEquals(EcoreUtil.getURI(object), referenceDescription.getContainerEObjectURI());
}
Aggregations