use of org.eclipse.xtext.linking.lazy.LazyURIEncoder in project xtext-core by eclipse.
the class DefaultReferenceDescriptionTest method createResourceDescription.
protected IResourceDescription createResourceDescription(Resource testResource) {
DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy();
strategy.setQualifiedNameProvider(new IQualifiedNameProvider.AbstractImpl() {
@Override
public QualifiedName getFullyQualifiedName(EObject obj) {
String name = SimpleAttributeResolver.NAME_RESOLVER.apply(obj);
return (name != null) ? QualifiedName.create(name) : null;
}
});
strategy.setLazyURIEncoder(new LazyURIEncoder());
IResourceDescription resourceDescription = new DefaultResourceDescription(testResource, strategy);
return resourceDescription;
}
use of org.eclipse.xtext.linking.lazy.LazyURIEncoder in project xtext-core by eclipse.
the class DefaultReferenceDescriptionTest method testLazyLinkingProxyReferences.
/**
* @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());
}
Aggregations