Exemplo n.º 1
0
 public CodeElement ConvertToDataModel(CodeSection codeSection)
 {
     CodeElement currentElement = null;
     codeSection.BlockType = codeSection.ReturnType;
     switch (codeSection.ReturnType)
     {
         case "namespace":
             currentElement = new ElementNamespace();
             break;
         case "class":
             currentElement = new ElementClass();
             break;
         default:
             currentElement = new ElementMethod();
             break;
     }
     currentElement.BlockType = codeSection.BlockType;
     currentElement.Name = codeSection.Identifier;
     currentElement.ReturnType = codeSection.ReturnType;
     currentElement.Parameters = codeSection.Parameters;
     currentElement.Extend = codeSection.Extend;
     if (codeSection.Header.Contains("("))
     {
         if (codeSection.Identifier.Contains("_"))
         {
             currentElement.ReturnType = "eventHandler";
         }
         else
         {
             //currentElement.ReturnType = "method";
         }
     }
     currentElement.Modifiers = codeSection.Modifiers;
     currentElement.Visibility = codeSection.Visibility;
     if (codeSection.CodeSections.Count > 0)
     {
         currentElement.Childs = new List<CodeElement>();
     }
     foreach (CodeSection codeSectionChild in codeSection.CodeSections)
     {
         CodeElement child = ConvertToDataModel(codeSectionChild);
         if (!string.IsNullOrEmpty(child.Name))
         {
             currentElement.Childs.Add(child);
         }
     }
     return currentElement;
 }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            List<CodeElement> codeElements = new List<CodeElement>();
            string expression = "cat is an animal";
            CodeElement objA = new ElementClass();
            objA.Name = "Cat";
            CodeElement objB = new ElementClass();
            objB.Name = "Leg";
            CodeElement objC = new ElementClass();
            objC.Name = "Head";
            CodeElement objD = new ElementClass();
            objD.Name = "Tail";
            CreateRelationHasA(objA, objB, CodeRelation.ReletionType.HasA, CodeRelation.ReletionMultiplicity.Some);
            CreateRelationHasA(objA, objC, CodeRelation.ReletionType.HasA, CodeRelation.ReletionMultiplicity.One);
            CreateRelationHasA(objA, objD, CodeRelation.ReletionType.HasA, CodeRelation.ReletionMultiplicity.One);

            DataModel.BL.DataModel.rootCodeElements = new List<CodeElement>() {objA};
        }
Exemplo n.º 3
0
        private void Wrap(SToken token)
        {
            while (token != null)
            {
                if (token.TokenType == SElementType.Symbol)
                {
                    TreeNode classNode = null;
                    CodeFile newCodeFile = new CodeFile();
                    ElementNamespace namespaceItem = new ElementNamespace();
                    ElementClass classItem = new ElementClass();

                    bool isNeededCodeFileCreation = true;
                    if (isNeededCodeFileCreation)
                    {
                        classNode = new TreeNode(token.TokenString);
                        classNode.ImageKey = "class";
                        classNode.Tag = token;
                        treeView1.Nodes.Add(classNode); 
                    }


                    if (token.TokenProperties != null)
                    {
                        SToken tokenToRead = token;
                        if (token.TokenProperties[0].TokenNodeType == SElementType.FoldOpen)
                        {
                            foreach (SToken localTokenF in token.TokenProperties[0].TokenChilds)
                            {
                                SToken localToken = localTokenF;
                                while (localToken != null)
                                {
                                    Wrap(localToken);
                                    ElementProperty newProperty = new ElementProperty();
                                    TreeNode propertyNode = null;
                                    propertyNode.ImageKey = "property";
                                    switch (localToken.TokenMultiplicity)
                                    {
                                        case SElementMultiplicity.Some:
                                            propertyNode = new TreeNode(localToken.TokenString);
                                            propertyNode.Tag = token;
                                            classNode.Nodes.Add(propertyNode);
                                            break;
                                        case SElementMultiplicity.Explicit:
                                            propertyNode = new TreeNode(localToken.TokenString);
                                            propertyNode.Tag = token;
                                            classNode.Nodes.Add(propertyNode);
                                            break;
                                        default:
                                            propertyNode = new TreeNode(localToken.TokenString);
                                            propertyNode.Tag = token;
                                            classNode.Nodes.Add(propertyNode);
                                            break;
                                    }
                                    //newProperty.PropertyType = localToken.TokenString;
                                    newProperty.ElementClassName = ToUp(localToken.TokenString);
                                    classItem.ElementProperties.Add(newProperty);
                                    if (localToken.TokenAfter != null)
                                    {
                                        localToken = localToken.TokenAfter[0];
                                    }
                                    else
                                    {
                                        localToken = null;
                                    }
                                }
                            }
                        }
                        else
                            foreach (SToken localToken in token.TokenProperties)
                            {
                                //Wrap(localToken);
                                ElementProperty newProperty = new ElementProperty();
                                TreeNode propertyNode = null;
                                switch (localToken.TokenMultiplicity)
                                {
                                    case SElementMultiplicity.Some:
                                        propertyNode = new TreeNode(localToken.TokenString);
                                        propertyNode.Tag = token;
                                        propertyNode.ImageKey = "property";
                                classNode.Nodes.Add(propertyNode);
                                        break;
                                    case SElementMultiplicity.Explicit:
                                       propertyNode = new TreeNode(localToken.TokenString);
                                        propertyNode.Tag = token;
                                        propertyNode.ImageKey = "property";
                                classNode.Nodes.Add(propertyNode);
                                        break;
                                    default:
                                        propertyNode = new TreeNode(localToken.TokenString);
                                        propertyNode.Tag = token;
                                        propertyNode.ImageKey = "property";
                                classNode.Nodes.Add(propertyNode);
                                        break;
                                }
                                //newProperty.PropertyType = localToken.TokenString;
                                newProperty.ElementClassName = ToUp(localToken.TokenString);
                                classItem.ElementProperties.Add(newProperty);
                            }
                    }
                    if (token.TokenActivities != null)
                    {
                        TreeNode actionNode = null;
                        foreach (SToken localToken in token.TokenActivities)
                        {
                            Wrap(localToken);
                            actionNode = new TreeNode(localToken.TokenString);
                            actionNode.Tag = token;
                            actionNode.ImageKey = "method";
                            classNode.Nodes.Add(actionNode);

                        }
                    }
                    if (token.TokenInfluenceA != null)
                    {
                        TreeNode actionNode = null;
                        foreach (SToken localToken in token.TokenInfluenceA)
                        {
                            ///if ()
                            //Wrap(localToken);
                            actionNode = new TreeNode(localToken.TokenString);
                            actionNode.Tag = token;
                            actionNode.ImageKey = "increase";
                            classNode.Nodes.Add(actionNode);

                        }
                    }

                    if (token.TokenInfluenceB != null)
                    {
                        TreeNode actionNode = null;
                        foreach (SToken localToken in token.TokenInfluenceB)
                        {
                           // Wrap(localToken);
                            actionNode = new TreeNode(localToken.TokenString);
                            actionNode.Tag = token;
                            actionNode.ImageKey = "decrease";
                            classNode.Nodes.Add(actionNode);

                        }
                    }

                    if (token.TokenInfluenceC != null)
                    {
                        TreeNode actionNode = null;
                        foreach (SToken localToken in token.TokenInfluenceC)
                        {
                            Wrap(localToken);
                            actionNode = new TreeNode(localToken.TokenString);
                            actionNode.Tag = token;
                            actionNode.ImageKey = "increasedBy";
                            classNode.Nodes.Add(actionNode);

                        }
                    }

                    if (token.TokenInfluenceD != null)
                    {
                        TreeNode actionNode = null;
                        foreach (SToken localToken in token.TokenInfluenceD)
                        {
                            Wrap(localToken);
                            actionNode = new TreeNode(localToken.TokenString);
                            actionNode.Tag = token;
                            actionNode.ImageKey = "decreasedBy";
                            classNode.Nodes.Add(actionNode);

                        }
                    }

                }
                foreach (SToken tokenlist in token.TokenChilds)
                {
                    Wrap(tokenlist);
                }
                if (token.TokenAfter != null)
                {
                    token = token.TokenAfter[0];
                }
                else
                {
                    token = null;
                }
            }
        }
Exemplo n.º 4
0
        private void Wrap(SToken token)
        {

            while (token != null)
            {
                //if (token.TokenType == SElementType.Symbol)
                {

                    CodeFile newCodeFile = new CodeFile();
                    ElementNamespace namespaceItem = new ElementNamespace();
                    ElementClass classItem = new ElementClass();

                    bool isNeededCodeFileCreation = true;
                    foreach (CodeFile existentCodeFile in program.CodeFiles)
                    {
                        if (existentCodeFile.FileName == ToUp(token.TokenString))
                        {
                            isNeededCodeFileCreation = false;
                            newCodeFile = existentCodeFile;
                        }
                    }
                    if (isNeededCodeFileCreation)
                    {
                        newCodeFile.FileName = ToUp(token.TokenString);
                        program.CodeFiles.Add(newCodeFile);
                        namespaceItem.Name = "GeneratedApplication";
                        newCodeFile.Namespaces.Add(namespaceItem);
                        classItem.Name = ToUp(token.TokenString);
                        namespaceItem.ElementClasses.Add(classItem);
                    }


                    if (token.TokenProperties != null)
                    {
                        SToken tokenToRead = token;
                         if (token.TokenProperties[0].TokenNodeType == SElementType.FoldOpen)
                          {
                             foreach (SToken localTokenF in token.TokenProperties[0].TokenChilds)
                              {
                                 SToken localToken = localTokenF;
                                 while (localToken != null)
                                 {
                                     Wrap(localToken);
                                     ElementProperty newProperty = new ElementProperty();
                                     switch (localToken.TokenMultiplicity)
                                     {
                                         case SElementMultiplicity.Some:
                                             newProperty.Name = ToUp(localToken.TokenString) + "s";
                                             newProperty.PropertyType = "List<" + ToUp(localToken.TokenString) + ">";
                                             break;
                                         case SElementMultiplicity.Explicit:
                                             newProperty.Name = ToUp(localToken.TokenString) + "s";
                                             newProperty.PropertyType = "" + ToUp(localToken.TokenString) + " " + token.TokenMultiplicityLevel + "";
                                             break;
                                         default:
                                             newProperty.Name = ToUp(localToken.TokenString) + "P";
                                             newProperty.PropertyType = ToUp(localToken.TokenString);
                                             break;
                                     }
                                     //newProperty.PropertyType = localToken.TokenString;
                                     newProperty.ElementClassName = ToUp(localToken.TokenString);
                                     classItem.ElementProperties.Add(newProperty);
                                     if (localToken.TokenAfter != null)
                                     {
                                         localToken = localToken.TokenAfter[0];
                                     }
                                     else
                                     {
                                         localToken = null;
                                     }
                                 }
                             }
                         }
                         else
                         foreach (SToken localToken in token.TokenProperties)
                        {

                            Wrap(localToken);
                            ElementProperty newProperty = new ElementProperty();
                            switch (localToken.TokenMultiplicity)
                            {
                                case SElementMultiplicity.Some:
                                    newProperty.Name = ToUp(localToken.TokenString) + "s";
                                    newProperty.PropertyType = "List<" + ToUp(localToken.TokenString) + ">";
                                    break;
                                case SElementMultiplicity.Explicit:
                                    newProperty.Name = ToUp(localToken.TokenString) + "s";
                                    newProperty.PropertyType = "" + ToUp(localToken.TokenString) + " " + token.TokenMultiplicityLevel + "";
                                    break;
                                default:
                                    newProperty.Name = ToUp(localToken.TokenString) + "P";
                                    newProperty.PropertyType = ToUp(localToken.TokenString);
                                    break;
                            }
                            //newProperty.PropertyType = localToken.TokenString;
                            newProperty.ElementClassName = ToUp(localToken.TokenString);
                            classItem.ElementProperties.Add(newProperty);
                        }
                    }
                    if (token.TokenActivities != null)
                     {
                        foreach (SToken localToken in token.TokenActivities)
                        {
                            Wrap(localToken);
                            ElementMethod newMethod = new ElementMethod();

                            newMethod.Name = ToUp(localToken.TokenString);
                            newMethod.ElementAccessType = ElementMethod.DataAccessType.isPublic;
                            
                            //newProperty.PropertyType = localToken.TokenString;
                            newMethod.ElementClassName = ToUp(localToken.TokenString);
                            classItem.ElementMethods.Add(newMethod);
                        }
                    }


                    List<string> influencesA = new List<string>();
                    List<string> influencesB = new List<string>();
                    List<string> influencesC = new List<string>();
                    List<string> influencesD = new List<string>();
                        
                    if (token.TokenInfluenceA != null)
                    {

                        foreach (SToken localToken in token.TokenInfluenceA)
                        {
                            /*{
                                foreach (SToken tokenA in token.TokenInfluenceA)
                                {
                                    if (token.TokenString.Equals(tokenA))
                                    {
                                        System.Windows.Forms.MessageBox.Show("No need to repeat yourself");
                                        break;
                                    }
                                }
                            }*/
                            if (!influencesA.Contains(localToken.TokenString))
                            {
                                influencesA.Add(localToken.TokenString);
                            }
                            else
                            {
                                System.Windows.Forms.MessageBox.Show("No need to repeat yourself!");
                                break;
                            }
                            if (influencesB.Contains(localToken.TokenString))
                            {
                                 System.Windows.Forms.MessageBox.Show("Your statement is inconsistent!");
                                break;
                            }
                            if (influencesD.Contains(localToken.TokenString))
                            {
                                System.Windows.Forms.MessageBox.Show("You defined a rebound effect!");
                                break;
                            }
                            
                            //Wrap(localToken);
                            ElementMethod newMethod = new ElementMethod();

                            newMethod.Name = ToUp(localToken.TokenString);
                            newMethod.ElementAccessType = ElementMethod.DataAccessType.isPublic;
                            newMethod.IsStatic = true;
                            //newProperty.PropertyType = localToken.TokenString;
                            newMethod.Name = "Increase" + ToUp(localToken.TokenString);
                            classItem.ElementMethods.Add(newMethod);
                        }
                    }

                    if (token.TokenInfluenceB != null)
                    {
                        foreach (SToken localToken in token.TokenInfluenceB)
                        {
                            if (!influencesB.Contains(localToken.TokenString))
                            {
                                influencesB.Add(localToken.TokenString);
                            }
                            else
                            {
                                System.Windows.Forms.MessageBox.Show("No need to repeat yourself!");
                                break;
                            }
                            if (influencesA.Contains(localToken.TokenString))
                            {
                                System.Windows.Forms.MessageBox.Show("Your statement is inconsistent!");
                                break;
                            }
                            if (influencesC.Contains(localToken.TokenString))
                            {
                                System.Windows.Forms.MessageBox.Show("You defined a rebound effect!");
                                break;
                            }
                            //Wrap(localToken);
                            ElementMethod newMethod = new ElementMethod();

                            newMethod.Name = ToUp(localToken.TokenString);
                            newMethod.ElementAccessType = ElementMethod.DataAccessType.isPublic;
                            newMethod.IsStatic = true;
                            
                            //newProperty.PropertyType = localToken.TokenString;
                            newMethod.Name = "Decrease" + ToUp(localToken.TokenString);
                            classItem.ElementMethods.Add(newMethod);
                        }
                    }

                    if (token.TokenInfluenceC != null)
                    {
                        foreach (SToken localToken in token.TokenInfluenceC)
                        {
                            if (!influencesC.Contains(localToken.TokenString))
                            {
                                influencesC.Add(localToken.TokenString);
                            }
                            else
                            {
                                System.Windows.Forms.MessageBox.Show("No need to repeat yourself!");
                                break;
                            }
                            if (influencesD.Contains(localToken.TokenString))
                            {
                                System.Windows.Forms.MessageBox.Show("Your statement is inconsistent!");
                                break;
                            }
                            if (influencesB.Contains(localToken.TokenString))
                            {
                                System.Windows.Forms.MessageBox.Show("You defined a rebound effect!");
                                break;
                            }
                            Wrap(localToken);
                            ElementMethod newMethod = new ElementMethod();

                            newMethod.Name = ToUp(localToken.TokenString);
                            newMethod.ElementAccessType = ElementMethod.DataAccessType.isPublic;
                            newMethod.IsStatic = true;
                            
                            //newProperty.PropertyType = localToken.TokenString;
                            newMethod.Name = "IncreasedBy" + ToUp(localToken.TokenString);
                            classItem.ElementMethods.Add(newMethod);
                        }
                    }

                    if (token.TokenInfluenceD != null)
                    {
                        foreach (SToken localToken in token.TokenInfluenceD)
                        {
                            if (!influencesD.Contains(localToken.TokenString))
                            {
                                influencesD.Add(localToken.TokenString);
                            }
                            else
                            {
                                System.Windows.Forms.MessageBox.Show("No need to repeat yourself!");
                                break;
                            }
                            if (influencesC.Contains(localToken.TokenString))
                            {
                                System.Windows.Forms.MessageBox.Show("Your statement is inconsistent!");
                                break;
                            }
                            if (influencesA.Contains(localToken.TokenString))
                            {
                                System.Windows.Forms.MessageBox.Show("You defined a rebound effect!");
                                break;
                            }
                            Wrap(localToken);
                            ElementMethod newMethod = new ElementMethod();

                            newMethod.Name = ToUp(localToken.TokenString);
                            newMethod.ElementAccessType = ElementMethod.DataAccessType.isPublic;
                            newMethod.IsStatic = true;
                            
                            //newProperty.PropertyType = localToken.TokenString;
                            newMethod.Name = "DecreasedBy" + ToUp(localToken.TokenString);
                            classItem.ElementMethods.Add(newMethod);
                        }
                    }

                }
                foreach (SToken tokenlist in token.TokenChilds)
                {
                    Wrap(tokenlist);
                }
                if (token.TokenAfter != null)
                {
                    token = token.TokenAfter[0];
                }
                else
                {
                    token = null;
                }
            }
        }