Search in sources :

Example 81 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.

the class DefaultResourceDescriptionTest method setUp.

@Before
public void setUp() throws Exception {
    resource = new XMLResourceImpl();
    resource.setURI(URI.createURI("foo:/test"));
    nameProvider = new IQualifiedNameProvider.AbstractImpl() {

        @Override
        public QualifiedName getFullyQualifiedName(EObject obj) {
            if (obj instanceof ENamedElement)
                return QualifiedName.create(((ENamedElement) obj).getName());
            return null;
        }
    };
    strategy = new DefaultResourceDescriptionStrategy();
    strategy.setQualifiedNameProvider(nameProvider);
    description = new DefaultResourceDescription(resource, strategy);
    EcoreFactory f = EcoreFactory.eINSTANCE;
    pack = f.createEPackage();
    pack.setName("MyPackage");
    eClass = f.createEClass();
    eClass.setName("MyEClass");
    dtype = f.createEDataType();
    dtype.setName("MyDatatype");
    pack.getEClassifiers().add(eClass);
    pack.getEClassifiers().add(dtype);
    resource.getContents().add(pack);
}
Also used : XMLResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl) IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ENamedElement(org.eclipse.emf.ecore.ENamedElement) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) Before(org.junit.Before)

Example 82 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.

the class ResourceSetBasedResourceDescriptionsTest method testOneElement_Mismatch.

@Test
public void testOneElement_Mismatch() {
    QualifiedName qualifiedName = QualifiedName.create("SomeName");
    EClass type = EcorePackage.Literals.EPACKAGE;
    Resource resource = createResource();
    createNamedElement(qualifiedName, type, resource);
    Iterable<IEObjectDescription> iterable = container.getExportedObjectsByType(EcorePackage.Literals.ECLASS);
    assertTrue(Iterables.isEmpty(iterable));
    iterable = container.getExportedObjects(EcorePackage.Literals.ECLASS, qualifiedName, false);
    assertTrue(Iterables.isEmpty(iterable));
    iterable = container.getExportedObjects(EcorePackage.Literals.EPACKAGE, QualifiedName.create("AnotherName"), false);
    assertTrue(Iterables.isEmpty(iterable));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Resource(org.eclipse.emf.ecore.resource.Resource) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 83 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.

the class ResourceSetBasedResourceDescriptionsTest method testTwoElements_OneMatch.

@Test
public void testTwoElements_OneMatch() {
    QualifiedName qualifiedName = QualifiedName.create("SomeName");
    EClass type = EcorePackage.Literals.EPACKAGE;
    Resource resource = createResource();
    ENamedElement element = createNamedElement(qualifiedName, type, resource);
    ENamedElement other = createNamedElement(null, EcorePackage.Literals.ECLASS, resource);
    Iterable<IEObjectDescription> iterable = container.getExportedObjectsByType(EcorePackage.Literals.EPACKAGE);
    assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
    iterable = container.getExportedObjectsByType(EcorePackage.Literals.ECLASSIFIER);
    assertSame(other, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
    iterable = container.getExportedObjects(EcorePackage.Literals.EPACKAGE, qualifiedName, false);
    assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
    iterable = container.getExportedObjects(EcorePackage.Literals.ENAMED_ELEMENT, qualifiedName, false);
    assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
    iterable = container.getExportedObjects(EcorePackage.Literals.EOBJECT, qualifiedName, false);
    assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ENamedElement(org.eclipse.emf.ecore.ENamedElement) Resource(org.eclipse.emf.ecore.resource.Resource) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 84 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.

the class ResourceSetBasedResourceDescriptionsTest method testDataBasedResourceSetBasedResourceDescriptions.

@Test
public void testDataBasedResourceSetBasedResourceDescriptions() throws Exception {
    ResourceDescriptionsData data = new ResourceDescriptionsData(new ArrayList<IResourceDescription>());
    ResourceDescriptionsData.ResourceSetAdapter.installResourceDescriptionsData(resourceSet, data);
    resDescs.setContext(resourceSet);
    Resource resource = createResource();
    QualifiedName name = QualifiedName.create("SomeName");
    createNamedElement(name, EcorePackage.Literals.ECLASS, resource);
    // still empty
    assertFalse(resDescs.getAllResourceDescriptions().iterator().hasNext());
    assertTrue(resDescs.isEmpty());
    assertFalse(resDescs.getExportedObjectsByType(EcorePackage.Literals.ECLASS).iterator().hasNext());
    assertFalse(resDescs.getExportedObjects(EcorePackage.Literals.ECLASS, name, false).iterator().hasNext());
    assertFalse(resDescs.getExportedObjects().iterator().hasNext());
    // add resource description to data
    IResourceDescription description = resourceDescriptionManager.getResourceDescription(resource);
    data.addDescription(description.getURI(), description);
    // now contained
    assertSame(description, resDescs.getAllResourceDescriptions().iterator().next());
    assertFalse(resDescs.isEmpty());
    assertTrue(resDescs.getExportedObjectsByType(EcorePackage.Literals.ECLASS).iterator().hasNext());
    assertTrue(resDescs.getExportedObjects(EcorePackage.Literals.ECLASS, name, false).iterator().hasNext());
    assertFalse(resDescs.getExportedObjects(EcorePackage.Literals.EATTRIBUTE, name, false).iterator().hasNext());
    assertTrue(resDescs.getExportedObjects().iterator().hasNext());
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Resource(org.eclipse.emf.ecore.resource.Resource) Test(org.junit.Test)

Example 85 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.

the class ResourceSetBasedResourceDescriptionsTest method testTwoResources_TwoMatches.

@Test
public void testTwoResources_TwoMatches() {
    QualifiedName qualifiedName = QualifiedName.create("SomeName");
    EClass type = EcorePackage.Literals.EPACKAGE;
    Resource resource = createResource();
    ENamedElement first = createNamedElement(qualifiedName, type, resource);
    resource = createResource();
    ENamedElement second = createNamedElement(qualifiedName, type, resource);
    List<ENamedElement> expected = Lists.newArrayList(first, second);
    Iterable<IEObjectDescription> iterable = container.getExportedObjectsByType(EcorePackage.Literals.EPACKAGE);
    checkFindAllEObjectsResult(expected, iterable);
    iterable = container.getExportedObjects(EcorePackage.Literals.EPACKAGE, qualifiedName, false);
    checkFindAllEObjectsResult(expected, iterable);
    iterable = container.getExportedObjects(EcorePackage.Literals.ENAMED_ELEMENT, qualifiedName, false);
    checkFindAllEObjectsResult(expected, iterable);
    iterable = container.getExportedObjects(EcorePackage.Literals.EOBJECT, qualifiedName, false);
    checkFindAllEObjectsResult(expected, iterable);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ENamedElement(org.eclipse.emf.ecore.ENamedElement) Resource(org.eclipse.emf.ecore.resource.Resource) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Aggregations

QualifiedName (org.eclipse.xtext.naming.QualifiedName)97 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)32 Test (org.junit.Test)31 EObject (org.eclipse.emf.ecore.EObject)27 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)16 EClass (org.eclipse.emf.ecore.EClass)12 Resource (org.eclipse.emf.ecore.resource.Resource)12 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)12 IScope (org.eclipse.xtext.scoping.IScope)10 Set (java.util.Set)9 URI (org.eclipse.emf.common.util.URI)7 XtextResource (org.eclipse.xtext.resource.XtextResource)7 StringInputStream (org.eclipse.xtext.util.StringInputStream)7 JvmType (org.eclipse.xtext.common.types.JvmType)6 Function (com.google.common.base.Function)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 InternalEObject (org.eclipse.emf.ecore.InternalEObject)4 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4