Search in sources :

Example 11 with EClassInfo

use of org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo in project xtext-core by eclipse.

the class TypeHierarchyHelperTest method testSimpeCase01.

@Test
public void testSimpeCase01() throws Exception {
    EClassInfo a = addClass("a");
    EClassInfo b = addClass("b");
    EClassInfo c = addClass("c");
    b.addSupertype(a);
    c.addSupertype(a);
    addAttribute(b, INT, "f1");
    addAttribute(c, INT, "f1");
    assertEquals(0, a.getEClass().getEStructuralFeatures().size());
    assertEquals(1, b.getEClass().getEStructuralFeatures().size());
    assertEquals(1, c.getEClass().getEStructuralFeatures().size());
    liftUpFeatures();
    assertEquals(1, a.getEClass().getEStructuralFeatures().size());
    assertEquals(0, b.getEClass().getEStructuralFeatures().size());
    assertEquals(0, c.getEClass().getEStructuralFeatures().size());
}
Also used : EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) Test(org.junit.Test)

Example 12 with EClassInfo

use of org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo in project xtext-core by eclipse.

the class TypeHierarchyHelperTest method testReferences.

@Test
public void testReferences() throws Exception {
    EClassInfo a = addClass("a");
    EClassInfo b = addClass("b");
    EClassInfo c = addClass("c");
    EClassInfo d = addClass("d");
    b.addSupertype(a);
    c.addSupertype(a);
    addReference(b, d, "r1");
    addReference(c, d, "r1");
    assertEquals(0, a.getEClass().getEStructuralFeatures().size());
    assertEquals(1, b.getEClass().getEStructuralFeatures().size());
    assertEquals(1, c.getEClass().getEStructuralFeatures().size());
    liftUpFeatures();
    assertEquals(1, a.getEClass().getEStructuralFeatures().size());
    assertEquals(0, b.getEClass().getEStructuralFeatures().size());
    assertEquals(0, c.getEClass().getEStructuralFeatures().size());
}
Also used : EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) Test(org.junit.Test)

Example 13 with EClassInfo

use of org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo in project xtext-core by eclipse.

the class TypeHierarchyHelperTest method testNikolaus.

@Test
public void testNikolaus() throws Exception {
    // no uplift for less than two children
    EClassInfo a = addClass("a");
    EClassInfo b = addClass("b");
    EClassInfo c = addClass("c");
    EClassInfo d = addClass("d");
    EClassInfo e = addClass("e");
    b.addSupertype(a);
    c.addSupertype(a);
    d.addSupertype(b);
    d.addSupertype(c);
    e.addSupertype(b);
    e.addSupertype(c);
    addAttribute(b, STRING, "f2");
    addAttribute(c, STRING, "f2");
    addAttribute(d, INT, "f1");
    addAttribute(e, INT, "f1");
    assertEquals(0, a.getEClass().getEStructuralFeatures().size());
    assertEquals(1, b.getEClass().getEStructuralFeatures().size());
    assertEquals(1, c.getEClass().getEStructuralFeatures().size());
    assertEquals(1, d.getEClass().getEStructuralFeatures().size());
    assertEquals(1, e.getEClass().getEStructuralFeatures().size());
    liftUpFeatures();
    assertEquals(1, a.getEClass().getEStructuralFeatures().size());
    assertEquals(0, b.getEClass().getEStructuralFeatures().size());
    assertEquals(0, c.getEClass().getEStructuralFeatures().size());
    assertEquals(1, d.getEClass().getEStructuralFeatures().size());
    assertEquals(1, e.getEClass().getEStructuralFeatures().size());
}
Also used : EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) Test(org.junit.Test)

Example 14 with EClassInfo

use of org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo in project xtext-core by eclipse.

the class TypeHierarchyHelper method liftUpFeaturesInto.

// TODO has multiple inheritance been taken into account?
@SuppressWarnings("unchecked")
public void liftUpFeaturesInto(EClassInfo superType, Map<EClass, Collection<EStructuralFeature>> featuresToRemove) {
    // do not look at types twice (might happen due to multiple inheritance)
    if (!traversedTypes.add(superType))
        return;
    Collection<EClassInfo> subTypes = getSubTypesOf(superType);
    if (subTypes.isEmpty())
        return;
    // lift up features recursively, deepest first
    for (EClassInfo subType : subTypes) {
        liftUpFeaturesInto(subType, featuresToRemove);
    }
    // do not modify sealed types
    if (!superType.isGenerated())
        return;
    // only if all subtypes' compatible type is superType itself
    // features can be lifted into superType
    Collection<? extends EClassifierInfo> subTypesAsClassifiers = subTypes;
    if (superType.equals(infos.getCompatibleTypeOf((Collection<EClassifierInfo>) subTypesAsClassifiers))) {
        Collection<EStructuralFeature> commonFeatures = getCommonDirectFeatures(subTypes);
        Collection<EStructuralFeature> liftedFeatures = joinFeaturesInto(commonFeatures, superType);
        for (EClassInfo subClassInfo : subTypes) // XXX: we may not remove features at this point, because a subtype may have many supertypes
        // and a feature may be lifted up into more than supertype
        removeFeatures(subClassInfo, liftedFeatures, featuresToRemove);
    }
}
Also used : EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) Collection(java.util.Collection)

Example 15 with EClassInfo

use of org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo in project xtext-core by eclipse.

the class TypeHierarchyHelperTest method testRecursiveUplift01.

@Test
public void testRecursiveUplift01() throws Exception {
    // no uplift for less than two children
    EClassInfo a = addClass("a");
    EClassInfo b = addClass("b");
    EClassInfo c = addClass("c");
    EClassInfo d = addClass("d");
    EClassInfo e = addClass("e");
    b.addSupertype(a);
    c.addSupertype(a);
    d.addSupertype(c);
    e.addSupertype(c);
    addAttribute(b, INT, "f1");
    addAttribute(d, INT, "f1");
    addAttribute(e, INT, "f1");
    assertEquals(0, a.getEClass().getEStructuralFeatures().size());
    assertEquals(1, b.getEClass().getEStructuralFeatures().size());
    assertEquals(0, c.getEClass().getEStructuralFeatures().size());
    assertEquals(1, d.getEClass().getEStructuralFeatures().size());
    assertEquals(1, e.getEClass().getEStructuralFeatures().size());
    liftUpFeatures();
    assertEquals(1, a.getEClass().getEStructuralFeatures().size());
    assertEquals(0, b.getEClass().getEStructuralFeatures().size());
    assertEquals(0, c.getEClass().getEStructuralFeatures().size());
    assertEquals(0, d.getEClass().getEStructuralFeatures().size());
    assertEquals(0, e.getEClass().getEStructuralFeatures().size());
}
Also used : EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) Test(org.junit.Test)

Aggregations

EClassInfo (org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo)16 Test (org.junit.Test)10 EClass (org.eclipse.emf.ecore.EClass)7 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)3 EcorePackage (org.eclipse.emf.ecore.EcorePackage)3 EReference (org.eclipse.emf.ecore.EReference)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 URI (org.eclipse.emf.common.util.URI)1 EClassifier (org.eclipse.emf.ecore.EClassifier)1 EObject (org.eclipse.emf.ecore.EObject)1 EcoreFactory (org.eclipse.emf.ecore.EcoreFactory)1