示例#1
0
        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);
            }
        }
示例#2
0
        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());
        }
示例#3
0
        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"));
        }
示例#4
0
        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());
        }
示例#5
0
        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"));
        }
示例#6
0
 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);
 }
示例#7
0
        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"));
        }
示例#8
0
        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"));
        }
示例#9
0
        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);
        }