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());
}
}
}
}
}
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());
}
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());
}
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);
}
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());
}
Aggregations