Search in sources :

Example 1 with ENamedElement

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

the class XtextValidator method createMessageForNameClashes.

public void createMessageForNameClashes(Multimap<String, ENamedElement> nameToElement) {
    for (Entry<String, Collection<ENamedElement>> entry : nameToElement.asMap().entrySet()) {
        if (entry.getValue().size() > 1) {
            if (!Iterables.isEmpty(Iterables.filter(entry.getValue(), EStructuralFeature.class)) && !Iterables.isEmpty(Iterables.filter(entry.getValue(), EClassifier.class))) {
                String constantName = entry.getKey();
                String message = "Name clash in generated code: '" + constantName + "'.";
                for (ENamedElement element : entry.getValue()) {
                    String myMessage = message;
                    if (element.getName().indexOf('_') >= 0) {
                        myMessage = myMessage + " Try to avoid underscores in names to prevent conflicts.";
                    }
                    createMessageForSource(myMessage, null, Diagnostic.ERROR, element, getMessageAcceptor());
                }
            }
        }
    }
}
Also used : ENamedElement(org.eclipse.emf.ecore.ENamedElement) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) Collection(java.util.Collection) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 2 with ENamedElement

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

the class NamesAreUniqueValidationHelperTest method testCreatedErrors_04.

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

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

the class NamesAreUniqueValidationHelperTest method testCreatedErrors_03.

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

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

the class NamesAreUniqueValidationHelperTest method testCreatedErrors_06.

@Test
public void testCreatedErrors_06() {
    maxCallCount = 1;
    ImmutableList<ENamedElement> elements = ImmutableList.of(createEPackage(), createEDataType(), createEPackage());
    for (ENamedElement classifier : elements) {
        classifier.setName("Same");
    }
    try {
        helper.checkUniqueNames(Scopes.scopedElementsFor(elements), this, this);
        fail("cancellation expected");
    } catch (OperationCanceledError e) {
    }
    assertEquals(1, callCount);
}
Also used : OperationCanceledError(org.eclipse.xtext.service.OperationCanceledError) ENamedElement(org.eclipse.emf.ecore.ENamedElement) Test(org.junit.Test)

Example 5 with ENamedElement

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

the class NamesAreUniqueValidationHelperTest method testCreatedErrors_07.

@Test
public void testCreatedErrors_07() {
    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(Scopes.scopedElementsFor(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)15 Test (org.junit.Test)8 EClass (org.eclipse.emf.ecore.EClass)4 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 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 DefaultResourceDescription (org.eclipse.xtext.resource.impl.DefaultResourceDescription)1 DefaultResourceDescriptionManager (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager)1