public IType inferCommonCategoryType(Context context, CategoryType type1, CategoryType type2, bool trySwap) { CategoryDeclaration decl1 = context.getRegisteredDeclaration <CategoryDeclaration>(type1.GetTypeName()); if (decl1.getDerivedFrom() != null) { foreach (String name in decl1.getDerivedFrom()) { CategoryType parentType = new CategoryType(name); if (parentType.isAssignableFrom(context, type2)) { return(parentType); } } // climb up the tree foreach (String name in decl1.getDerivedFrom()) { CategoryType parentType = new CategoryType(name); IType commonType = inferCommonBaseType(context, parentType, type2); if (commonType != null) { return(commonType); } } } if (trySwap) { return(inferCommonCategoryType(context, type2, type1, false)); } else { return(null); } }
public void testCategory2DerivedNoAttribute() { String statement = "define Entrepreneur as Person and Company"; ETestParser parser = new ETestParser(statement, false); CategoryDeclaration cd = parser.parse_category_declaration(); Assert.IsNotNull(cd); Assert.AreEqual("Entrepreneur", cd.GetName()); Assert.IsNotNull(cd.getDerivedFrom()); Assert.IsTrue(cd.getDerivedFrom().Contains("Person")); Assert.IsTrue(cd.getDerivedFrom().Contains("Company")); Assert.IsNull(cd.GetLocalAttributes()); }
public void testCategory1Derived1Attribute() { String statement = "define Employee as Person with attribute company"; ETestParser parser = new ETestParser(statement, false); CategoryDeclaration cd = parser.parse_category_declaration(); Assert.IsNotNull(cd); Assert.AreEqual("Employee", cd.GetName()); Assert.IsNotNull(cd.getDerivedFrom()); Assert.IsTrue(cd.getDerivedFrom().Contains("Person")); Assert.IsNotNull(cd.GetLocalAttributes()); Assert.IsTrue(cd.GetLocalAttributes().Contains("company")); }
public void parsesCategory2DerivedNoAttribute() { String statement = "category Entrepreneur extends Person, Company;"; OTestParser parser = new OTestParser(statement); CategoryDeclaration cd = parser.parse_category_declaration(); Assert.IsNotNull(cd); Assert.AreEqual("Entrepreneur", cd.GetName()); Assert.IsNotNull(cd.getDerivedFrom()); Assert.IsTrue(cd.getDerivedFrom().Contains("Person")); Assert.IsTrue(cd.getDerivedFrom().Contains("Company")); Assert.IsNull(cd.GetLocalAttributes()); }
public void parsesCategory1Derived1Attribute() { String statement = "category Employee( company ) extends Person ;"; OTestParser parser = new OTestParser(statement); CategoryDeclaration cd = parser.parse_category_declaration(); Assert.IsNotNull(cd); Assert.AreEqual("Employee", cd.GetName()); Assert.IsNotNull(cd.getDerivedFrom()); Assert.IsTrue(cd.getDerivedFrom().Contains("Person")); Assert.IsNotNull(cd.GetLocalAttributes()); Assert.IsTrue(cd.GetLocalAttributes().Contains("company")); }
public bool isDerivedFrom(Context context, CategoryDeclaration decl, CategoryType other) { if (decl.getDerivedFrom() == null) { return(false); } foreach (String derived in decl.getDerivedFrom()) { CategoryType ct = new CategoryType(derived); if (ct.Equals(other) || ct.isDerivedFrom(context, other)) { return(true); } } return(false); }
public void parsesCategory1Attribute() { String statement = "category Person ( id );"; OTestParser parser = new OTestParser(statement); CategoryDeclaration cd = parser.parse_category_declaration(); Assert.IsNotNull(cd); Assert.AreEqual("Person", cd.GetName()); Assert.IsNull(cd.getDerivedFrom()); Assert.IsNotNull(cd.GetLocalAttributes()); Assert.IsTrue(cd.GetLocalAttributes().Contains("id")); }
public void testCategory2Attributes() { String statement = "define Person as category with attributes id, name"; ETestParser parser = new ETestParser(statement, false); CategoryDeclaration cd = parser.parse_category_declaration(); Assert.IsNotNull(cd); Assert.AreEqual("Person", cd.GetName()); Assert.IsNull(cd.getDerivedFrom()); Assert.IsNotNull(cd.GetLocalAttributes()); Assert.IsTrue(cd.GetLocalAttributes().Contains("id")); Assert.IsTrue(cd.GetLocalAttributes().Contains("name")); }
public bool isDerivedFromAnonymous(Context context, CategoryDeclaration thisDecl, CategoryDeclaration otherDecl) { // an anonymous category extends 1 and only 1 category String baseName = otherDecl.getDerivedFrom()[0]; // check we derive from root category (if not extending 'any') if (!"any".Equals(baseName) && !thisDecl.isDerivedFrom(context, new CategoryType(baseName))) { return(false); } foreach (String attribute in otherDecl.GetAllAttributes(context)) { if (!thisDecl.hasAttribute(context, attribute)) { return(false); } } return(true); }