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