Пример #1
0
        public AttributeCallExp createAttributeCallExp(
            OclExpression source,
            CoreAttribute attribute,
            bool isMarkedPre)
        {
            AttributeCallExp exp = new AttributeCallExpImpl();

            exp.setFactory(this);

            exp.setSource(isMarkedPre ? createAtPreOperation(source) : source);
            exp.setReferredAttribute(attribute);

            CoreClassifier expType;

            if (attribute.isOclDefined())
            {
                expType = attribute.getFeatureType();
            }
            else
            {
                expType = attribute.getModel() != null?attribute.getModel().toOclType(attribute.getFeatureType()) : attribute.getFeatureType();
            }
            exp.setType(((AttributeCallExpImpl)exp).getExpressionType(source, expType));

            if (source != null)
            {
                ((OclExpressionImpl)source).setAppliedProperty(exp);
            }

            return(exp);
        }
Пример #2
0
        public void testDefAttribute()
        {
            getClassifier("Film").addDefinedElement("test.ocl", "myNewAttr", getClassifier("Integer"));

            try
            {
                getClassifier("Film").addDefinedElement("test.ocl", "myNewAttr", getClassifier("Integer"));
                throw new AssertFailedException();
            }
            catch (Exception e)
            {}

            try
            {
                getClassifier("Product").addDefinedElement("test.ocl", "myNewAttr", getClassifier("Integer"));
                throw new AssertFailedException();
            }
            catch (Exception e)
            {}

            try
            {
                getClassifier("Film").addDefinedElement("test.ocl", "name", getClassifier("Integer"));
                throw new AssertFailedException();
            }
            catch (Exception e)
            {}

            CoreAttribute attr = getClassifier("Film").lookupAttribute("myNewAttr");

            Assert.AreEqual("Integer", attr.getFeatureType().getName());
            Assert.IsTrue(attr.isOclDefined());

            CoreAttribute nameAttr = getClassifier("Film").lookupAttribute("name");

            Assert.AreEqual("String", nameAttr.getFeatureType().getName());
            Assert.IsFalse(nameAttr.isOclDefined());

            getClassifier("Film").deleteAllConstraintsForSource("test.ocl");
            Assert.IsNull(getClassifier("Film").lookupAttribute("myNewAttr"));
        }