Search in sources :

Example 56 with EClassifier

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

the class GrammarAccessExtensions method getSingleElementDescription.

private List<String> getSingleElementDescription(final AbstractElement ele) {
    final ArrayList<String> r = new ArrayList<String>(2);
    boolean _matched = false;
    if (ele instanceof Keyword) {
        _matched = true;
        String _value = ((Keyword) ele).getValue();
        r.add(_value);
    }
    if (!_matched) {
        if (ele instanceof Assignment) {
            _matched = true;
            String _feature = ((Assignment) ele).getFeature();
            r.add(_feature);
        }
    }
    if (!_matched) {
        if (ele instanceof RuleCall) {
            _matched = true;
            String _name = ((RuleCall) ele).getRule().getName();
            r.add(_name);
        }
    }
    if (!_matched) {
        if (ele instanceof Action) {
            _matched = true;
            TypeRef _type = ((Action) ele).getType();
            EClassifier _classifier = null;
            if (_type != null) {
                _classifier = _type.getClassifier();
            }
            boolean _tripleNotEquals = (_classifier != null);
            if (_tripleNotEquals) {
                String _name = ((Action) ele).getType().getClassifier().getName();
                r.add(_name);
            }
            boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(((Action) ele).getFeature());
            boolean _not = (!_isNullOrEmpty);
            if (_not) {
                String _feature = ((Action) ele).getFeature();
                r.add(_feature);
            }
        }
    }
    if (!_matched) {
        if (ele instanceof CrossReference) {
            _matched = true;
            TypeRef _type = ((CrossReference) ele).getType();
            EClassifier _classifier = null;
            if (_type != null) {
                _classifier = _type.getClassifier();
            }
            boolean _tripleNotEquals = (_classifier != null);
            if (_tripleNotEquals) {
                String _name = ((CrossReference) ele).getType().getClassifier().getName();
                r.add(_name);
            }
        }
    }
    if (!_matched) {
        if (ele instanceof EnumLiteralDeclaration) {
            _matched = true;
            String _name = ((EnumLiteralDeclaration) ele).getEnumLiteral().getName();
            r.add(_name);
        }
    }
    return r;
}
Also used : Assignment(org.eclipse.xtext.Assignment) Action(org.eclipse.xtext.Action) Keyword(org.eclipse.xtext.Keyword) EnumLiteralDeclaration(org.eclipse.xtext.EnumLiteralDeclaration) TypeRef(org.eclipse.xtext.TypeRef) ArrayList(java.util.ArrayList) EClassifier(org.eclipse.emf.ecore.EClassifier) CrossReference(org.eclipse.xtext.CrossReference) RuleCall(org.eclipse.xtext.RuleCall)

Example 57 with EClassifier

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

the class Xtext2EcoreTransformer method collectClassInfosOf.

private void collectClassInfosOf(EClassifierInfos target, EPackage referencedEPackage, AbstractMetamodelDeclaration metaModel, boolean generated) {
    for (EClassifier eClassifier : referencedEPackage.getEClassifiers()) {
        if (eClassifier instanceof EClass) {
            EClass eClass = (EClass) eClassifier;
            EClassifierInfo info = EClassifierInfo.createEClassInfo(eClass, generated, getGeneratedEPackageURIs(), GrammarUtil.getGrammar(metaModel));
            target.addInfo(metaModel, eClassifier.getName(), info);
        } else if (eClassifier instanceof EDataType) {
            EDataType eDataType = (EDataType) eClassifier;
            EClassifierInfo info = EClassifierInfo.createEDataTypeInfo(eDataType, generated);
            target.addInfo(metaModel, eClassifier.getName(), info);
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EDataType(org.eclipse.emf.ecore.EDataType) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 58 with EClassifier

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

the class Xtext2EcoreTransformer method addSuperType.

private void addSuperType(ParserRule rule, TypeRef subTypeRef, EClassifierInfo superTypeInfo) throws TransformationException {
    final EClassifier subType = subTypeRef.getClassifier();
    final EClassifierInfo subTypeInfo = subType == null ? findOrCreateEClassifierInfo(subTypeRef, null, true) : eClassifierInfos.getInfoOrNull(subType);
    if (subTypeInfo == null)
        throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Type '" + superTypeInfo.getEClassifier().getName() + "' is not available.", rule.getType());
    if (superTypeInfo.isAssignableFrom(subTypeInfo))
        return;
    if (subTypeInfo.getEClassifier() instanceof EDataType)
        throw new TransformationException(TransformationErrorCode.InvalidSupertype, "Cannot add supertype '" + superTypeInfo.getEClassifier().getName() + "' to simple datatype '" + subTypeInfo.getEClassifier().getName() + "'.", rule.getType());
    if (!subTypeInfo.isGenerated())
        throw new TransformationException(TransformationErrorCode.CannotCreateTypeInSealedMetamodel, "Cannot add supertype '" + superTypeInfo.getEClassifier().getName() + "' to sealed type '" + subTypeInfo.getEClassifier().getName() + "'.", rule.getType());
    subTypeInfo.addSupertype(superTypeInfo);
}
Also used : EDataType(org.eclipse.emf.ecore.EDataType) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 59 with EClassifier

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

the class Xtext2EcoreTransformer method clearPackage.

protected void clearPackage(Resource resource, EPackage pack) {
    Map<InternalEObject, URI> uris = Maps.newHashMap();
    for (EClassifier classifier : pack.getEClassifiers()) {
        InternalEObject internalEObject = (InternalEObject) classifier;
        URI appendFragment = resource.getURI().appendFragment(resource.getURIFragment(internalEObject));
        uris.put(internalEObject, appendFragment);
    }
    pack.getEClassifiers().clear();
    for (Map.Entry<InternalEObject, URI> entry : uris.entrySet()) {
        entry.getKey().eSetProxyURI(entry.getValue());
    }
}
Also used : EClassifier(org.eclipse.emf.ecore.EClassifier) URI(org.eclipse.emf.common.util.URI) Map(java.util.Map) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 60 with EClassifier

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

the class TypeHierarchyHelper method pushFeaturesUp.

private void pushFeaturesUp(EClassInfo info, Collection<EClass> traversedClasses) {
    EClass eClass = info.getEClass();
    if (info.isGenerated()) {
        if (traversedClasses.add(eClass)) {
            if (eClass.getESuperTypes().isEmpty())
                return;
            for (EClass superType : eClass.getESuperTypes()) {
                EClassInfo superInfo = (EClassInfo) infos.getInfoOrNull(superType);
                pushFeaturesUp(superInfo, traversedClasses);
            }
            Map<String, EStructuralFeature> allFeatures = Maps.newLinkedHashMap();
            Set<String> skippedNames = Sets.newLinkedHashSet();
            for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
                if (feature.getEContainingClass() != eClass) {
                    if (allFeatures.containsKey(feature.getName())) {
                        allFeatures.remove(feature.getName());
                    } else if (skippedNames.add(feature.getName())) {
                        allFeatures.put(feature.getName(), feature);
                    }
                }
            }
            Iterator<EStructuralFeature> iter = eClass.getEStructuralFeatures().iterator();
            while (iter.hasNext()) {
                EStructuralFeature declared = iter.next();
                EStructuralFeature existing = allFeatures.get(declared.getName());
                if (existing != null) {
                    EClassifier compatibleType = EcoreUtil2.getCompatibleType(declared.getEType(), existing.getEType(), grammar);
                    if (compatibleType != null) {
                        iter.remove();
                        existing.setEType(compatibleType);
                    }
                }
            }
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EClassifier(org.eclipse.emf.ecore.EClassifier)

Aggregations

EClassifier (org.eclipse.emf.ecore.EClassifier)153 EClass (org.eclipse.emf.ecore.EClass)94 Test (org.junit.Test)36 EPackage (org.eclipse.emf.ecore.EPackage)32 EReference (org.eclipse.emf.ecore.EReference)22 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)16 AbstractRule (org.eclipse.xtext.AbstractRule)14 EDataType (org.eclipse.emf.ecore.EDataType)13 EObject (org.eclipse.emf.ecore.EObject)13 XtextResource (org.eclipse.xtext.resource.XtextResource)10 EAttribute (org.eclipse.emf.ecore.EAttribute)8 EEnum (org.eclipse.emf.ecore.EEnum)8 Grammar (org.eclipse.xtext.Grammar)8 ParserRule (org.eclipse.xtext.ParserRule)8 ArrayList (java.util.ArrayList)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Assignment (org.eclipse.xtext.Assignment)7 IScope (org.eclipse.xtext.scoping.IScope)6 HashSet (java.util.HashSet)5 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)5