Przeglądaj źródła

#669: Support for multiple super types in type system.

Thomas Kutz 9 lat temu
rodzic
commit
603d598e08

+ 1 - 1
plugins/org.yakindu.base.types.test/src/org/yakindu/base/types/test/AbstractTypeSystemTest.java

@@ -71,7 +71,7 @@ public class AbstractTypeSystemTest extends AbstractTypeSystem {
 
 	@Test
 	public void testGetSuperType() throws Exception {
-		assertTrue(isSame(superType, getSuperType(subType)));
+		assertTrue(isSame(superType, getSuperTypes(subType).get(0)));
 
 	}
 

+ 16 - 10
plugins/org.yakindu.base.types/src/org/yakindu/base/types/typesystem/AbstractTypeSystem.java

@@ -24,6 +24,7 @@ import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
 import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.yakindu.base.types.ComplexType;
 import org.yakindu.base.types.PrimitiveType;
 import org.yakindu.base.types.Type;
 import org.yakindu.base.types.TypesFactory;
@@ -64,15 +65,20 @@ public abstract class AbstractTypeSystem implements ITypeSystem {
 		return result;
 	}
 
-	public Type getSuperType(Type type) {
+	public List<Type> getSuperTypes(Type type) {
+		List<Type> superTypes = new ArrayList<Type>();
 		Set<Entry<Type, Type>> entrySet = extendsRegistry.entrySet();
 		for (Entry<Type, Type> entry : entrySet) {
 			if (isSame(type, entry.getKey())) {
-				return entry.getValue();
+				superTypes.add(entry.getValue());
 			}
-
 		}
-		return null;
+		if (type instanceof ComplexType) {
+			ComplexType complexType = (ComplexType) type;
+			superTypes.addAll(complexType.getSuperTypes());
+		}
+		
+		return superTypes;
 	}
 
 	public boolean isSuperType(Type subtype, Type supertype) {
@@ -86,15 +92,15 @@ public abstract class AbstractTypeSystem implements ITypeSystem {
 		return false;
 	}
 
-	private void collectSupertypes(Type subtypeClass, List<Type> typehierachy) {
+	private void collectSupertypes(Type subtypeClass, List<Type> typeHierachy) {
 		if (subtypeClass == null)
 			return;
-		Type superType = getSuperType(subtypeClass);
-		if (superType != null) {
-			typehierachy.add(superType);
-			collectSupertypes(superType, typehierachy);
+		
+		List<Type> superTypes = getSuperTypes(subtypeClass);
+		for (Type superType : superTypes) {
+			typeHierachy.add(superType);
+			collectSupertypes(superType, typeHierachy);
 		}
-
 	}
 
 	public Collection<Type> getTypes(EObject context) {

+ 5 - 3
plugins/org.yakindu.base.types/src/org/yakindu/base/types/typesystem/GenericTypeValueProvider.java

@@ -16,6 +16,8 @@ import static org.yakindu.base.types.typesystem.ITypeSystem.REAL;
 import static org.yakindu.base.types.typesystem.ITypeSystem.STRING;
 import static org.yakindu.base.types.typesystem.ITypeSystem.VOID;
 
+import java.util.List;
+
 import org.yakindu.base.types.Type;
 
 import com.google.inject.Inject;
@@ -48,9 +50,9 @@ public class GenericTypeValueProvider implements ITypeValueProvider {
 		if (is(type, STRING)) {
 			return new String("");
 		}
-		Type superType = typeSystem.getSuperType(type);
-		if (superType != null)
-			return defaultValue(superType);
+		List<Type> superTypes = typeSystem.getSuperTypes(type);
+		if (!superTypes.isEmpty())
+			return defaultValue(superTypes.get(0));
 		throw new IllegalArgumentException("Unknown type " + type);
 	}
 

+ 2 - 1
plugins/org.yakindu.base.types/src/org/yakindu/base/types/typesystem/ITypeSystem.java

@@ -11,6 +11,7 @@
 package org.yakindu.base.types.typesystem;
 
 import java.util.Collection;
+import java.util.List;
 
 import org.eclipse.emf.ecore.EObject;
 import org.yakindu.base.types.Type;
@@ -50,7 +51,7 @@ public interface ITypeSystem {
 
 	public Type getCommonTypeWithConversion(Type type1, Type type2);
 	
-	public Type getSuperType(Type type);
+	public List<Type> getSuperTypes(Type type);
 
 	public boolean isSuperType(Type subtype, Type supertype);