Search in sources :

Example 11 with EDataType

use of org.eclipse.emf.ecore.EDataType 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 12 with EDataType

use of org.eclipse.emf.ecore.EDataType 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 13 with EDataType

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

the class DefaultReferenceDescriptionTest method testLazyLinkingProxyReferences.

/**
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=330812
 */
@Test
public void testLazyLinkingProxyReferences() {
    URI resourceUri = URI.createPlatformResourceURI("test.ecore", true);
    LazyURIEncoder lazyURIEncoder = new LazyURIEncoder();
    ResourceSet resourceSet = new ResourceSetImpl();
    Resource testResource = resourceSet.createResource(resourceUri);
    EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
    ePackage.setName("test");
    ePackage.setNsPrefix("test");
    ePackage.setNsURI("test");
    testResource.getContents().add(ePackage);
    EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    eClass.setName("Test");
    ePackage.getEClassifiers().add(eClass);
    EClass multiRefType = EcoreFactory.eINSTANCE.createEClass();
    ((InternalEObject) multiRefType).eSetProxyURI(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE));
    eClass.getESuperTypes().add(multiRefType);
    EClass multiRefType2 = EcoreFactory.eINSTANCE.createEClass();
    URI dummyProxyUri = resourceUri.appendFragment(lazyURIEncoder.encode(eClass, EcorePackage.Literals.ECLASS__ESUPER_TYPES, null));
    ((InternalEObject) multiRefType2).eSetProxyURI(dummyProxyUri);
    eClass.getESuperTypes().add(multiRefType2);
    EAttribute nameAttribute = EcoreFactory.eINSTANCE.createEAttribute();
    nameAttribute.setName("name");
    eClass.getEStructuralFeatures().add(nameAttribute);
    EDataType singleRefType = EcoreFactory.eINSTANCE.createEDataType();
    ((InternalEObject) singleRefType).eSetProxyURI(EcoreUtil.getURI(EcorePackage.Literals.ESTRING));
    nameAttribute.setEType(singleRefType);
    assertTrue(multiRefType.eIsProxy());
    assertTrue(multiRefType2.eIsProxy());
    assertTrue(lazyURIEncoder.isCrossLinkFragment(testResource, EcoreUtil.getURI(multiRefType2).fragment()));
    assertTrue(singleRefType.eIsProxy());
    IResourceDescription resourceDescription = createResourceDescription(testResource);
    Iterable<IReferenceDescription> referenceDescriptions = resourceDescription.getReferenceDescriptions();
    assertEquals("Unexpected additional resources were loaded", 1, resourceSet.getResources().size());
    assertEquals("Unexpected reference was exported", 3, Iterables.size(referenceDescriptions));
    IReferenceDescription referenceDescription = Iterables.get(referenceDescriptions, 0);
    assertEquals(0, referenceDescription.getIndexInList());
    assertEquals(EcoreUtil.getURI(eClass), referenceDescription.getSourceEObjectUri());
    assertEquals(EcorePackage.Literals.ECLASS__ESUPER_TYPES, referenceDescription.getEReference());
    assertEquals(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE), referenceDescription.getTargetEObjectUri());
    referenceDescription = Iterables.get(referenceDescriptions, 1);
    assertEquals(-1, referenceDescription.getIndexInList());
    assertEquals(EcoreUtil.getURI(nameAttribute.getEGenericType()), referenceDescription.getSourceEObjectUri());
    assertEquals(EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, referenceDescription.getEReference());
    assertEquals(EcoreUtil.getURI(EcorePackage.Literals.ESTRING), referenceDescription.getTargetEObjectUri());
    referenceDescription = Iterables.get(referenceDescriptions, 2);
    assertEquals(-1, referenceDescription.getIndexInList());
    assertEquals(EcoreUtil.getURI(eClass.getEGenericSuperTypes().get(0)), referenceDescription.getSourceEObjectUri());
    assertEquals(EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, referenceDescription.getEReference());
    assertEquals(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE), referenceDescription.getTargetEObjectUri());
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) EDataType(org.eclipse.emf.ecore.EDataType) LazyURIEncoder(org.eclipse.xtext.linking.lazy.LazyURIEncoder) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) EPackage(org.eclipse.emf.ecore.EPackage) EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) InternalEObject(org.eclipse.emf.ecore.InternalEObject) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Example 14 with EDataType

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

the class EcoreUtil2Test method testGetCompatibleType_01.

@Test
public void testGetCompatibleType_01() {
    EDataType aString = createEDataType("a", String.class);
    EDataType anotherString = createEDataType("b", String.class);
    assertSame(aString, EcoreUtil2.getCompatibleType(aString, anotherString, null));
    assertSame(anotherString, EcoreUtil2.getCompatibleType(anotherString, aString, null));
}
Also used : EDataType(org.eclipse.emf.ecore.EDataType) Test(org.junit.Test)

Example 15 with EDataType

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

the class EcoreUtil2Test method testGetCompatibleType_05.

@Test
public void testGetCompatibleType_05() {
    EDataType aString = createEDataType("a", String.class);
    EDataType anObject = createEDataType("b", Object.class);
    assertSame(anObject, EcoreUtil2.getCompatibleType(aString, anObject));
    assertSame(anObject, EcoreUtil2.getCompatibleType(anObject, aString));
}
Also used : EDataType(org.eclipse.emf.ecore.EDataType) Test(org.junit.Test)

Aggregations

EDataType (org.eclipse.emf.ecore.EDataType)25 Test (org.junit.Test)10 EObject (org.eclipse.emf.ecore.EObject)8 EClassifier (org.eclipse.emf.ecore.EClassifier)7 EClass (org.eclipse.emf.ecore.EClass)5 EAttribute (org.eclipse.emf.ecore.EAttribute)3 AbstractRule (org.eclipse.xtext.AbstractRule)3 ArrayList (java.util.ArrayList)2 EPackage (org.eclipse.emf.ecore.EPackage)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 Grammar (org.eclipse.xtext.Grammar)2 RuleCall (org.eclipse.xtext.RuleCall)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 Collection (java.util.Collection)1 List (java.util.List)1 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 DiagnosticChain (org.eclipse.emf.common.util.DiagnosticChain)1 URI (org.eclipse.emf.common.util.URI)1 EEnum (org.eclipse.emf.ecore.EEnum)1 EEnumLiteral (org.eclipse.emf.ecore.EEnumLiteral)1