Search in sources :

Example 6 with IReferenceDescription

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());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) LangATestLanguageStandaloneSetup(org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Example 7 with IReferenceDescription

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);
        }
    }
}
Also used : SerializableReferenceDescription(org.eclipse.xtext.resource.persistence.SerializableReferenceDescription) URI(org.eclipse.emf.common.util.URI) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 8 with IReferenceDescription

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);
}
Also used : ReferenceAcceptor(org.eclipse.xtext.findReferences.ReferenceAcceptor) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) TargetURIs(org.eclipse.xtext.findReferences.TargetURIs) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 9 with IReferenceDescription

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());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) LangATestLanguageStandaloneSetup(org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Example 10 with IReferenceDescription

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());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) EReference(org.eclipse.emf.ecore.EReference) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) EPackage(org.eclipse.emf.ecore.EPackage) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Aggregations

IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)12 EObject (org.eclipse.emf.ecore.EObject)9 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)6 Test (org.junit.Test)6 InternalEObject (org.eclipse.emf.ecore.InternalEObject)5 XtextResource (org.eclipse.xtext.resource.XtextResource)5 URI (org.eclipse.emf.common.util.URI)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)4 EClass (org.eclipse.emf.ecore.EClass)3 EPackage (org.eclipse.emf.ecore.EPackage)3 EReference (org.eclipse.emf.ecore.EReference)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 ReferenceAcceptor (org.eclipse.xtext.findReferences.ReferenceAcceptor)3 Main (org.eclipse.xtext.linking.langATestLanguage.Main)3 EAttribute (org.eclipse.emf.ecore.EAttribute)2 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)2 XMIResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)2 TargetURIs (org.eclipse.xtext.findReferences.TargetURIs)2 LangATestLanguageStandaloneSetup (org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup)2