Search in sources :

Example 21 with ENamedElement

use of org.eclipse.emf.ecore.ENamedElement in project xtext-core by eclipse.

the class NamesAreUniqueValidationHelperTest method testCreatedErrors_05_context.

@Test
public void testCreatedErrors_05_context() {
    maxCallCount = 0;
    ImmutableList<ENamedElement> elements = ImmutableList.of(createEPackage(), createEDataType(), createEPackage());
    for (ENamedElement classifier : elements) {
        classifier.setName("Same");
    }
    expected.add(elements.get(0));
    expected.add(elements.get(2));
    helper.checkUniqueNames(new LocalUniqueNameContext(elements, this), this);
    assertEquals(elements.size(), callCount);
    assertTrue(expected.isEmpty());
}
Also used : ENamedElement(org.eclipse.emf.ecore.ENamedElement) Test(org.junit.Test)

Example 22 with ENamedElement

use of org.eclipse.emf.ecore.ENamedElement 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 23 with ENamedElement

use of org.eclipse.emf.ecore.ENamedElement 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)

Example 24 with ENamedElement

use of org.eclipse.emf.ecore.ENamedElement 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 25 with ENamedElement

use of org.eclipse.emf.ecore.ENamedElement in project xtext-core by eclipse.

the class EmfFormatter method refToStr.

private static void refToStr(EObject obj, EReference ref, String indent, Appendable buf) throws Exception {
    Object o = obj.eGet(ref);
    if (o instanceof EObject) {
        EObject eo = (EObject) o;
        if (eo instanceof ENamedElement)
            buf.append("'").append(((ENamedElement) eo).getName()).append("' ");
        buf.append("ref: ");
        getURI(obj, eo, buf);
        return;
    }
    if (o instanceof Collection<?>) {
        String innerIndent = indent + INDENT;
        buf.append("[");
        int counter = 0;
        Collection<?> coll = (Collection<?>) o;
        for (Iterator<?> i = coll.iterator(); i.hasNext(); ) {
            Object item = i.next();
            if (counter == 0)
                buf.append('\n');
            buf.append(innerIndent);
            printInt(counter++, coll.size(), buf);
            buf.append(": ");
            getURI(obj, (EObject) item, buf);
            if (i.hasNext())
                buf.append(",\n");
            else
                buf.append('\n').append(indent);
        }
        buf.append("]");
        return;
    }
    buf.append("?????");
}
Also used : EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) ENamedElement(org.eclipse.emf.ecore.ENamedElement) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Aggregations

ENamedElement (org.eclipse.emf.ecore.ENamedElement)26 Test (org.junit.Test)19 EClass (org.eclipse.emf.ecore.EClass)10 ArrayList (java.util.ArrayList)6 EObject (org.eclipse.emf.ecore.EObject)4 QualifiedName (org.eclipse.xtext.naming.QualifiedName)4 Collection (java.util.Collection)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)3 EClassifier (org.eclipse.emf.ecore.EClassifier)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 IQualifiedNameProvider (org.eclipse.xtext.naming.IQualifiedNameProvider)2 OperationCanceledError (org.eclipse.xtext.service.OperationCanceledError)2 Before (org.junit.Before)2 IdentityHashMap (java.util.IdentityHashMap)1 EPackage (org.eclipse.emf.ecore.EPackage)1 EcoreFactory (org.eclipse.emf.ecore.EcoreFactory)1 ResourceImpl (org.eclipse.emf.ecore.resource.impl.ResourceImpl)1 XMLResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl)1