Search in sources :

Example 26 with ENamedElement

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

the class XtextValidator method checkGeneratedPackageForNameClashes.

@Check
public void checkGeneratedPackageForNameClashes(GeneratedMetamodel metamodel) {
    EPackage pack = metamodel.getEPackage();
    Multimap<String, ENamedElement> constantNameToElement = HashMultimap.create();
    Multimap<String, ENamedElement> accessorNameToElement = HashMultimap.create();
    if (pack != null) {
        for (EClassifier classifier : pack.getEClassifiers()) {
            String accessorName = classifier.getName();
            if ("Class".equals(accessorName) || "Name".equals(accessorName))
                accessorName += "_";
            accessorNameToElement.put("get" + accessorName, classifier);
            String classifierConstantName = CodeGenUtil2.format(classifier.getName(), '_', null, true, true).toUpperCase();
            constantNameToElement.put(classifierConstantName, classifier);
            if (classifier instanceof EClass) {
                for (EStructuralFeature feature : ((EClass) classifier).getEAllStructuralFeatures()) {
                    String featureConstantPart = CodeGenUtil2.format(feature.getName(), '_', null, false, false).toUpperCase();
                    String featureConstantName = classifierConstantName + "__" + featureConstantPart;
                    constantNameToElement.put(featureConstantName, feature);
                    String featureAccessorName = "get" + classifier.getName() + "_" + Strings.toFirstUpper(feature.getName());
                    accessorNameToElement.put(featureAccessorName, feature);
                }
            }
        }
    }
    createMessageForNameClashes(constantNameToElement);
    createMessageForNameClashes(accessorNameToElement);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ENamedElement(org.eclipse.emf.ecore.ENamedElement) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage) Check(org.eclipse.xtext.validation.Check)

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