Java Code Examples for org.eclipse.xtext.resource.IResourceDescription#getReferenceDescriptions()
The following examples show how to use
org.eclipse.xtext.resource.IResourceDescription#getReferenceDescriptions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuilderUtil.java From n4js with Eclipse Public License 1.0 | 6 votes |
/***/ public static Set<IReferenceDescription> getIncomingReferences(URI uri) { Set<IReferenceDescription> desc = Sets.newHashSet(); Iterable<IResourceDescription> descriptions = getAllResourceDescriptions(); for (IResourceDescription res : descriptions) { Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions(); for (IReferenceDescription ref : descriptions2) { if (uri.hasFragment()) { if (ref.getTargetEObjectUri().equals(uri)) desc.add(ref); } else { if (ref.getTargetEObjectUri().trimFragment().equals(uri.trimFragment())) desc.add(ref); } } } return desc; }
Example 2
Source File: BuilderUtil.java From n4js with Eclipse Public License 1.0 | 6 votes |
/***/ public static Set<IReferenceDescription> getContainedReferences(URI uri) { Set<IReferenceDescription> desc = Sets.newHashSet(); Iterable<IResourceDescription> descriptions = getAllResourceDescriptions(); for (IResourceDescription res : descriptions) { Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions(); for (IReferenceDescription ref : descriptions2) { if (uri.hasFragment()) { if (ref.getSourceEObjectUri().equals(uri)) desc.add(ref); } else { if (ref.getSourceEObjectUri().trimFragment().equals(uri.trimFragment())) desc.add(ref); } } } return desc; }
Example 3
Source File: BuilderUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public static Set<IReferenceDescription> getIncomingReferences(URI uri) { Set<IReferenceDescription> desc = Sets.newHashSet(); Iterable<IResourceDescription> descriptions = getBuilderState().getAllResourceDescriptions(); for (IResourceDescription res : descriptions) { Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions(); for (IReferenceDescription ref : descriptions2) { if (uri.hasFragment()) { if (ref.getTargetEObjectUri().equals(uri)) desc.add(ref); } else { if (ref.getTargetEObjectUri().trimFragment().equals(uri.trimFragment())) desc.add(ref); } } } return desc; }
Example 4
Source File: BuilderUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public static Set<IReferenceDescription> getContainedReferences(URI uri) { Set<IReferenceDescription> desc = Sets.newHashSet(); Iterable<IResourceDescription> descriptions = getBuilderState().getAllResourceDescriptions(); for (IResourceDescription res : descriptions) { Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions(); for (IReferenceDescription ref : descriptions2) { if (uri.hasFragment()) { if (ref.getSourceEObjectUri().equals(uri)) desc.add(ref); } else { if (ref.getSourceEObjectUri().trimFragment().equals(uri.trimFragment())) desc.add(ref); } } } return desc; }
Example 5
Source File: DefaultReferenceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example 6
Source File: DefaultReferenceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example 7
Source File: StatefulResourceDescription.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public Iterable<IReferenceDescription> getReferenceDescriptions() { // find references was triggered - use up-to-date reference descriptions // the content of this copied description is updated as soon as the exported // objects of a resource change thus the default algorithm of the find // references UI for the display string should work IResourceDescription snapShot = snapShotProvider.get(); if (snapShot != null) return snapShot.getReferenceDescriptions(); return Collections.emptyList(); }
Example 8
Source File: ReferenceFinder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void findReferencesInDescription(TargetURIs targetURIs, IResourceDescription resourceDescription, IResourceAccess resourceAccess, Acceptor acceptor, IProgressMonitor monitor) { for (IReferenceDescription referenceDescription : resourceDescription.getReferenceDescriptions()) { if (targetURIs.contains(referenceDescription.getTargetEObjectUri())) { acceptor.accept(referenceDescription); } } }
Example 9
Source File: DefaultReferenceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=330812 */ @Test public void testLazyLinkingProxyReferences() { URI resourceUri = URI.createPlatformResourceURI("test.ecore", true); LazyURIEncoder lazyURIEncoder = new LazyURIEncoder(); ResourceSet resourceSet = new ResourceSetImpl(); Resource testResource = resourceSet.createResource(resourceUri); EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); ePackage.setName("test"); ePackage.setNsPrefix("test"); ePackage.setNsURI("test"); testResource.getContents().add(ePackage); EClass eClass = EcoreFactory.eINSTANCE.createEClass(); eClass.setName("Test"); ePackage.getEClassifiers().add(eClass); EClass multiRefType = EcoreFactory.eINSTANCE.createEClass(); ((InternalEObject) multiRefType).eSetProxyURI(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE)); eClass.getESuperTypes().add(multiRefType); EClass multiRefType2 = EcoreFactory.eINSTANCE.createEClass(); URI dummyProxyUri = resourceUri.appendFragment(lazyURIEncoder.encode(eClass, EcorePackage.Literals.ECLASS__ESUPER_TYPES, null)); ((InternalEObject) multiRefType2).eSetProxyURI(dummyProxyUri); eClass.getESuperTypes().add(multiRefType2); EAttribute nameAttribute = EcoreFactory.eINSTANCE.createEAttribute(); nameAttribute.setName("name"); eClass.getEStructuralFeatures().add(nameAttribute); EDataType singleRefType = EcoreFactory.eINSTANCE.createEDataType(); ((InternalEObject) singleRefType).eSetProxyURI(EcoreUtil.getURI(EcorePackage.Literals.ESTRING)); nameAttribute.setEType(singleRefType); assertTrue(multiRefType.eIsProxy()); assertTrue(multiRefType2.eIsProxy()); assertTrue(lazyURIEncoder.isCrossLinkFragment(testResource, EcoreUtil.getURI(multiRefType2).fragment())); assertTrue(singleRefType.eIsProxy()); IResourceDescription resourceDescription = createResourceDescription(testResource); Iterable<IReferenceDescription> referenceDescriptions = resourceDescription.getReferenceDescriptions(); assertEquals("Unexpected additional resources were loaded", 1, resourceSet.getResources().size()); assertEquals("Unexpected reference was exported", 3, Iterables.size(referenceDescriptions)); IReferenceDescription referenceDescription = Iterables.get(referenceDescriptions, 0); assertEquals(0, referenceDescription.getIndexInList()); assertEquals(EcoreUtil.getURI(eClass), referenceDescription.getSourceEObjectUri()); assertEquals(EcorePackage.Literals.ECLASS__ESUPER_TYPES, referenceDescription.getEReference()); assertEquals(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE), referenceDescription.getTargetEObjectUri()); referenceDescription = Iterables.get(referenceDescriptions, 1); assertEquals(-1, referenceDescription.getIndexInList()); assertEquals(EcoreUtil.getURI(nameAttribute.getEGenericType()), referenceDescription.getSourceEObjectUri()); assertEquals(EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, referenceDescription.getEReference()); assertEquals(EcoreUtil.getURI(EcorePackage.Literals.ESTRING), referenceDescription.getTargetEObjectUri()); referenceDescription = Iterables.get(referenceDescriptions, 2); assertEquals(-1, referenceDescription.getIndexInList()); assertEquals(EcoreUtil.getURI(eClass.getEGenericSuperTypes().get(0)), referenceDescription.getSourceEObjectUri()); assertEquals(EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, referenceDescription.getEReference()); assertEquals(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE), referenceDescription.getTargetEObjectUri()); }