Search in sources :

Example 16 with ENamedElement

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

the class NamesAreUniqueValidationHelperTest method testManyManyDup.

@SuppressWarnings("deprecation")
@Test
public void testManyManyDup() {
    List<ENamedElement> elements = new ArrayList<>();
    for (int i = 0, j = 0; i < MANY; i++) {
        if (i % 100 == 0) {
            j++;
        }
        EClass c = createEClass();
        c.setName("i" + j);
        elements.add(c);
    }
    maxCallCount = 0;
    expected.addAll(elements);
    helper.checkUniqueNames(Scopes.scopedElementsFor(elements), this, this);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ENamedElement(org.eclipse.emf.ecore.ENamedElement) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 17 with ENamedElement

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

the class NamesAreUniqueValidationHelperTest method testManyOneDup_context.

@Test
public void testManyOneDup_context() {
    List<ENamedElement> elements = new ArrayList<>();
    for (int i = 0; i < MANY; i++) {
        EClass c = createEClass();
        if (i == MANY - 1) {
            c.setName("i1234");
        } else {
            c.setName("i" + i);
        }
        elements.add(c);
    }
    maxCallCount = 0;
    expected.add(elements.get(1_234));
    expected.add(elements.get(MANY - 1));
    helper.checkUniqueNames(new LocalUniqueNameContext(elements, this), this);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ENamedElement(org.eclipse.emf.ecore.ENamedElement) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 18 with ENamedElement

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

the class NamesAreUniqueValidationHelperTest method testCreatedErrors_04_context.

@Test
public void testCreatedErrors_04_context() {
    maxCallCount = 0;
    ImmutableList<ENamedElement> elements = ImmutableList.of(createEClass(), createEDataType(), createEPackage(), createEPackage());
    for (ENamedElement classifier : elements) {
        classifier.setName("Same");
    }
    expected.addAll(elements);
    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 19 with ENamedElement

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

the class NamesAreUniqueValidationHelperTest method testCreatedErrors_05.

@SuppressWarnings("deprecation")
@Test
public void testCreatedErrors_05() {
    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(Scopes.scopedElementsFor(elements), this, this);
    assertEquals(elements.size(), callCount);
    assertTrue(expected.isEmpty());
}
Also used : ENamedElement(org.eclipse.emf.ecore.ENamedElement) Test(org.junit.Test)

Example 20 with ENamedElement

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

the class NamesAreUniqueValidationHelperTest method testCreatedErrors_07_context.

@Test
public void testCreatedErrors_07_context() {
    maxCallCount = 0;
    ImmutableList<ENamedElement> elements = ImmutableList.of(createEPackage(), createEDataType(), EcoreFactory.eINSTANCE.createEEnumLiteral());
    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)

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