Exemplo n.º 1
0
        public override List <String> doRule(SQLElement eaElement, SQLWrapperClasses.SQLRepository repository)
        {
            List <String> results = new List <string>();

            if (eaElement.Stereotype == TGGModelingMain.TggRuleStereotype)
            {
                SQLPackage rulesPackage     = repository.GetPackageByID(eaElement.PackageID);
                SQLPackage tggSchemaPackage = repository.GetPackageByID(rulesPackage.ParentID);
                foreach (SQLElement corrType in tggSchemaPackage.Elements)
                {
                    if (corrType.Stereotype == TGGModelingMain.TggCorrespondenceTypeStereotype)
                    {
                        if (corrType.Name == eaElement.Name)
                        {
                            results.Add("TGG Rule name shouldnt be equal to TGG CorrespondenceType name");
                        }
                    }
                }

                if (!ConsistencyUtil.isValidTGGRuleName(eaElement.Name))
                {
                    results.Add("TGG Rule name should consist of the following letters: a-z,A-Z,0-9,_,-");
                }
            }
            return(results);
        }
        public override List <String> doRule(SQLElement eaElement, SQLWrapperClasses.SQLRepository repository)
        {
            List <String> results = new List <string>();

            if (eaElement.Stereotype == ECOREModelingMain.EEnumStereotype)
            {
                bool foundEnumConstant = false;
                SQLCollection <SQLAttribute> attributes = eaElement.Attributes;
                foreach (SQLAttribute attribute in attributes)
                {
                    if (ConsistencyUtil.isValidConstantName(attribute.Name))
                    {
                        foundEnumConstant = true;
                    }
                    else
                    {
                        try
                        {
                            Int32.Parse(attribute.Default);
                            foundEnumConstant = true;
                        }
                        catch (FormatException)
                        {
                            //ignore
                        }
                    }
                }
                if (!foundEnumConstant)
                {
                    results.Add("EEnum should contain at least one enum constant consisting of uppercase letters, digits, and underscores with an integer default value.");
                }
            }
            return(results);
        }
Exemplo n.º 3
0
        public override List <RuleResult> getRuleResult(Object eaObject, SQLRepository repository)
        {
            List <RuleResult> results = new List <RuleResult>();

            foreach (String ruleOutput in doRule(eaObject as SQLConnector, repository))
            {
                results.Add(ConsistencyUtil.computeRuleResult(this, eaObject as SQLConnector, ruleOutput));
            }
            return(results);
        }
        public void testIsValidTGGRuleName()
        {
            Assert.IsTrue(ConsistencyUtil.isValidTGGRuleName("MyRule"));
            Assert.IsTrue(ConsistencyUtil.isValidTGGRuleName("myRule1"));
            Assert.IsTrue(ConsistencyUtil.isValidTGGRuleName("_withUnderscore"));
            Assert.IsTrue(ConsistencyUtil.isValidTGGRuleName("HouseToBungalowRule"));

            Assert.IsFalse(ConsistencyUtil.isValidTGGRuleName(""));
            Assert.IsFalse(ConsistencyUtil.isValidTGGRuleName("aQuote\""));
            Assert.IsFalse(ConsistencyUtil.isValidTGGRuleName("someWhitespaceX X"));
        }
        public override List <String> doRule(SQLPackage eaPackage, SQLWrapperClasses.SQLRepository repository)
        {
            List <String> results = new List <string>();

            foreach (string segment in eaPackage.Name.Split('.'))
            {
                if (ConsistencyUtil.nameIsKeyword(segment))
                {
                    results.Add("The segment " + segment + " of package " + eaPackage.Name + " is a Java keyword and may not be used.");
                }
            }
            return(results);
        }
        public void testIsValidActivityNodeName()
        {
            Assert.IsTrue(ConsistencyUtil.isValidActivityNodeName("MyActivity"));
            Assert.IsTrue(ConsistencyUtil.isValidActivityNodeName("MyActivity1"));
            Assert.IsTrue(ConsistencyUtil.isValidActivityNodeName("myActivityNode1"));
            Assert.IsTrue(ConsistencyUtil.isValidActivityNodeName("_withUnderscore"));
            Assert.IsTrue(ConsistencyUtil.isValidActivityNodeName("someWhitespaceX X"));
            Assert.IsTrue(ConsistencyUtil.isValidActivityNodeName("activity-activity"));
            Assert.IsTrue(ConsistencyUtil.isValidActivityNodeName(""));
            Assert.IsTrue(ConsistencyUtil.isValidActivityNodeName(null));

            Assert.IsFalse(ConsistencyUtil.isValidActivityNodeName("aQuote\""));
        }
        public void TestIsConventionalConstantName()
        {
            Assert.IsTrue(ConsistencyUtil.isValidConstantName("CONST"));
            Assert.IsTrue(ConsistencyUtil.isValidConstantName("CONST_NAME"));
            Assert.IsTrue(ConsistencyUtil.isValidConstantName("_CONST_NAME"));
            Assert.IsTrue(ConsistencyUtil.isValidConstantName("_CONST_NAME_123"));

            Assert.IsFalse(ConsistencyUtil.isValidConstantName(""));
            Assert.IsFalse(ConsistencyUtil.isValidConstantName("aMember"));
            Assert.IsFalse(ConsistencyUtil.isValidConstantName("1CONST"));
            Assert.IsFalse(ConsistencyUtil.isValidConstantName("1_CONST"));
            Assert.IsFalse(ConsistencyUtil.isValidConstantName("COnST"));
        }
        public override List <String> doRule(SQLElement eaElement, SQLWrapperClasses.SQLRepository repository)
        {
            List <String> results = new List <string>();

            if (eaElement.Stereotype == SDMModelingMain.StatementNodeStereotype)
            {
                StatementNode statementNode = new StatementNode(repository, eaElement);
                statementNode.loadTreeFromTaggedValue();

                if (statementNode.StatementExpression != null)
                {
                    String result = statementNode.StatementExpression.ToString();
                    if (!ConsistencyUtil.checkExpression(eaElement, statementNode.StatementExpression, repository))
                    {
                        results.Add("StatementExpression is invalid: (" + result + ")");
                    }
                }
                else
                {
                    results.Add("StatementExpression is missing");
                }

                foreach (SQLConnector outgoingCon in eaElement.Connectors)
                {
                    if (outgoingCon.ClientID == eaElement.ElementID)
                    {
                        ActivityEdge edge = new ActivityEdge(repository, outgoingCon);
                        edge.loadTreeFromTaggedValue();
                        if (edge.GuardType == EdgeGuard.FAILURE || edge.GuardType == EdgeGuard.SUCCESS)
                        {
                            if (statementNode.StatementExpression is MethodCallExpression)
                            {
                                MethodCallExpression mCe    = statementNode.StatementExpression as MethodCallExpression;
                                SQLMethod            method = repository.GetMethodByGuid(mCe.MethodGuid);

                                if (method != null && method.ReturnType != "EBoolean")
                                {
                                    results.Add("Method must be of type EBoolean if StatementNode has success/failure guards");
                                }
                            }
                        }
                    }
                }
            }
            return(results);
        }
Exemplo n.º 9
0
        public override List <String> doRule(SQLElement eaElement, SQLWrapperClasses.SQLRepository repository)
        {
            List <String> results = new List <string>();

            if (eaElement.Stereotype == SDMModelingMain.SdmContainerStereotype)
            {
                Activity activity = new Activity(eaElement, repository);
                if (eaElement.ParentID != activity.OwningOperation.EaMethod.ParentID)
                {
                    results.Add("SDM Activity and related EOperation are no children of the same EClass");
                }

                if (!ConsistencyUtil.isValidActivityNodeName(activity.Name))
                {
                    results.Add("SDM Activity names should consist of: a-z, A-Z, 0-9, _, -, whitespaces,");
                }
            }
            return(results);
        }
Exemplo n.º 10
0
        public override List <String> doRule(SQLElement eaElement, SQLWrapperClasses.SQLRepository repository)
        {
            List <String> results = new List <string>();

            if (eaElement.Stereotype == SDMModelingMain.ObjectVariableStereotype ||
                eaElement.Stereotype == TGGModelingMain.TggObjectVariableStereotype ||
                eaElement.Stereotype == TGGModelingMain.TggCorrespondenceStereotype)
            {
                ObjectVariable ov = new ObjectVariable(eaElement, repository);
                ov.loadTreeFromTaggedValue();
                if (ov.BindingExpression != null)
                {
                    if (!ConsistencyUtil.checkExpression(eaElement, ov.BindingExpression, repository))
                    {
                        results.Add("BindingExpression is Invalid: (" + ov.BindingExpression.ToString() + ")");
                    }
                }
            }
            return(results);
        }
        public void isConstantLiteralNumbers()
        {
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("1"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("1.0"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral(".234"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("0x123"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("123L"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("1.2d"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("1d"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("1.2f"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("1f"));

            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("-1"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("-1.0"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("-.234"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("-123L"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("-1.2d"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("-1d"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("-1.2f"));
            Assert.IsTrue(ConsistencyUtil.isConstantLiteral("-1f"));
        }
        public override List <String> doRule(SQLAttribute eaAttribute, SQLWrapperClasses.SQLRepository repository)
        {
            List <String> results     = new List <string>();
            SQLElement    parentClass = repository.GetElementByID(eaAttribute.ParentID);

            if (parentClass.Stereotype == ECOREModelingMain.EEnumStereotype)
            {
                if (ConsistencyUtil.isValidConstantName(eaAttribute.Name))
                {
                    try
                    {
                        Int32.Parse(eaAttribute.Default);
                    }
                    catch (FormatException)
                    {
                        results.Add("EEnums constants must provide an integer default value.");
                    }
                }
            }
            return(results);
        }
Exemplo n.º 13
0
        public void doGlobalRules(SQLRepository repository)
        {
            //end validation and write output

            foreach (Rule rule in listOfRules)
            {
                if (rule.getRuleExecutionPoint() == ruleExecutionPoint || ruleExecutionPoint == RuleExecutionPoint.OnRequest)
                {
                    if (rule is GlobalRule <SQLConnector> )
                    {
                        GlobalRule <SQLConnector>         connectorRule = rule as GlobalRule <SQLConnector>;
                        Dictionary <SQLConnector, String> results       = (rule as GlobalRule <SQLConnector>).doGlobalRule(repository);
                        foreach (SQLConnector con in results.Keys)
                        {
                            RuleResult ruleResult = ConsistencyUtil.computeRuleResult(rule, con, results[con]);
                            if (connectorRule.getCustomName(con, repository) != "")
                            {
                                ruleResult.NameOfObject = connectorRule.getCustomName(con, repository);
                            }
                            handleRuleResult(ruleResult, repository);
                        }
                    }
                    else if (rule is GlobalRule <SQLElement> )
                    {
                        GlobalRule <SQLElement>         elementRule = rule as GlobalRule <SQLElement>;
                        Dictionary <SQLElement, String> results     = (rule as GlobalRule <SQLElement>).doGlobalRule(repository);

                        foreach (SQLElement con in results.Keys)
                        {
                            RuleResult ruleResult = ConsistencyUtil.computeRuleResult(rule, con, results[con]);
                            if (elementRule.getCustomName(con, repository) != "")
                            {
                                ruleResult.NameOfObject = elementRule.getCustomName(con, repository);
                            }
                            handleRuleResult(ruleResult, repository);
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
        public override List <String> doRule(SQLElement eaElement, SQLWrapperClasses.SQLRepository repository)
        {
            List <String> results = new List <string>();

            if (eaElement.Stereotype == SDMModelingMain.StopNodeStereotype)
            {
                StopNode stopNode = new StopNode(repository, eaElement);
                stopNode.loadTreeFromTaggedValue();

                if (stopNode.ReturnValue != null)
                {
                    Boolean isValid = ConsistencyUtil.checkExpression(eaElement, stopNode.ReturnValue, repository);
                    if (!isValid)
                    {
                        String output = "StopNode returnValue is invalid and must be updated manually";
                        output += ConsistencyUtil.getExpressionOutput(stopNode.ReturnValue, repository);
                        results.Add(output);
                    }
                }
            }
            return(results);
        }
Exemplo n.º 15
0
        public override List <String> doRule(SQLElement eaElement, SQLWrapperClasses.SQLRepository repository)
        {
            List <String> results = new List <string>();

            if (eaElement.Stereotype == SDMModelingMain.ObjectVariableStereotype ||
                eaElement.Stereotype == TGGModelingMain.TggObjectVariableStereotype ||
                eaElement.Stereotype == TGGModelingMain.TggCorrespondenceStereotype)
            {
                ObjectVariable ov = new ObjectVariable(eaElement, repository);
                ov.loadTreeFromTaggedValue();

                String output = "";

                foreach (Constraint constraint in ov.Constraints)
                {
                    if (!ConsistencyUtil.checkConstraint(eaElement, constraint, repository))
                    {
                        output += " - (" + constraint.ToString() + ")";
                    }
                }

                foreach (AttributeAssignment attrAssignment in ov.AttributeAssignments)
                {
                    if (!ConsistencyUtil.checkAttributeAssignment(eaElement, attrAssignment, repository))
                    {
                        output += " - (" + attrAssignment.ToString() + ")";
                    }
                }

                if (output != "")
                {
                    output = "ObjectVariable contains invalid Constraints / Assignments: " + output;
                    results.Add(output);
                }
            }

            return(results);
        }
Exemplo n.º 16
0
        public override List <string> doRule(SQLElement eaElement, SQLWrapperClasses.SQLRepository repository)
        {
            List <String> results = new List <string>();

            if (eaElement.Stereotype == TGGModelingMain.CSPConstraintStereotype || eaElement.Stereotype == "TGGCsp")
            {
                SQLElement parentElement = repository.GetElementByID(eaElement.ParentID);
                if (parentElement.Stereotype != SDMModelingMain.StoryNodeStereotype)
                {
                    CSPInstance csp = new CSPInstance(repository, eaElement);
                    if (csp.loadTreeFromTaggedValue())
                    {
                        foreach (CSPInstanceEntry instance in csp.createdEntries)
                        {
                            foreach (Expression exp in instance.typedInExpressions)
                            {
                                if (!ConsistencyUtil.checkExpression(eaElement, exp, repository))
                                {
                                    results.Add("Tgg CSP expression is invalid: " + exp);
                                }
                            }
                        }
                    }
                    else
                    {
                        results.Add("Tgg CSP is outdated and maybe erroneous - updating it manually is recommended");
                    }
                }
            }
            else if (eaElement.Type == "Constraint")
            {
                results.Add("Tgg CSP is outdated and cant be modified - quickfix is recommended");
            }

            return(results);
        }
 private static bool isEnumConstant(EA.Attribute attribute)
 {
     return(ConsistencyUtil.isValidConstantName(attribute.Name));
 }
 public void isConstantLiteralEnum()
 {
     Assert.IsTrue(ConsistencyUtil.isConstantLiteral("EnumConstant"));
     Assert.IsTrue(ConsistencyUtil.isConstantLiteral("EnumName.EnumConstant"));
 }
 public void isConstantLiteralStrings()
 {
     Assert.IsTrue(ConsistencyUtil.isConstantLiteral("'A'"));
     Assert.IsTrue(ConsistencyUtil.isConstantLiteral("\"abc\""));
     Assert.IsTrue(ConsistencyUtil.isConstantLiteral("\"\\\"abc\\\"\""));
 }