public DialogResult ShowDialog()
        {
            TextDocument activeDoc = null;
            DTE          dte       = null;

            try
            {
                dte       = Package.GetGlobalService(typeof(DTE)) as DTE;
                activeDoc = dte.ActiveDocument.Object() as TextDocument;
            }
            catch
            {
                MessageBox.Show("Please open a Dafny file befor using the aplication.", "File not open", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                //this.Close();
                return(DialogResult.Abort);
            }

            //get position
            var cursPoint = activeDoc.Selection.ActivePoint;

            // to insert
            toInsert = (EnvDTE.TextSelection)(activeDoc.Selection);

            //get all text
            var text = activeDoc.CreateEditPoint(activeDoc.StartPoint).GetText(activeDoc.EndPoint);

            // get input to spesific class
            // get input
            string name = get_method_name(text, cursPoint);

            if (name == String.Empty)
            {
                MessageBox.Show("Method not found.", "Method not found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                // this.Close();
                return(DialogResult.Abort);
            }
            label1.Text = "Please insert the postcondition and lemma name for the method \"" + name + "\" :";
            try
            {
                p.parse_file(dte.ActiveDocument.FullName, name);


                List <String> postcond = p.get_ens();
                this.post_lable.Text      = string.Join("\n", postcond);
                this.post_cond1.Location  = new Point(this.post_cond1.Location.X, this.post_cond1.Location.Y + 10 * postcond.Count);
                this.button_more.Location = new Point(this.button_more.Location.X, this.button_more.Location.Y + 10 * postcond.Count);
                this.Height += 10 * postcond.Count;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Exception caught during parsing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                // this.Close();
                return(DialogResult.Abort);
            }
            return(base.ShowDialog());
        }
Exemple #2
0
        private void button_ok_Click(object sender, EventArgs e)
        {
            try
            {
                assertiveToolDS dafnyCreate = new assertiveToolDS();
                TextDocument    activeDoc   = null;
                DTE             dte         = null;

                try
                {
                    dte       = Package.GetGlobalService(typeof(DTE)) as DTE;
                    activeDoc = dte.ActiveDocument.Object() as TextDocument;
                }
                catch
                {
                    MessageBox.Show("Please open a Dafny file befor using the aplication.", "File not open", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.Close();
                    return;
                }

                //get position
                var cursPoint = activeDoc.Selection.ActivePoint;

                // to insert
                TextSelection toInsert = (EnvDTE.TextSelection)(activeDoc.Selection);

                //get all text
                var text = activeDoc.CreateEditPoint(activeDoc.StartPoint).GetText(activeDoc.EndPoint);

                // get input
                string name = get_method_name(text, cursPoint);
                if (name == String.Empty)
                {
                    MessageBox.Show("Method not found.", "Method not found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.Close();
                    return;
                }
                dafnyCreate.Name = name;

                //validation:
                if (this.methodName.Text == string.Empty)
                {
                    MessageBox.Show("Please enter Method Name.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                if (preCondName.Text == string.Empty)
                {
                    MessageBox.Show("Please enter Lema name.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }


                bool isFound = false;
                foreach (Control x in this.Controls)
                {
                    if (x is TextBox && x.Name.StartsWith("pre_cond") && x.Text != String.Empty)
                    {
                        isFound = true;
                        dafnyCreate.weakenPreCond(x.Text);
                    }
                }

                if (!isFound)
                {
                    MessageBox.Show("Please enter at least one preCondition.", "Empty input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                // add the new pre_condition and method

                dafnyCreate.WeakLemma.Name = this.preCondName.Text;
                dafnyCreate.NewMethod.Name = this.methodName.Text;

                // input from parser
                try
                {
                    DafnyCodeParser p = new DafnyCodeParser();
                    p.parse_file(dte.ActiveDocument.FullName, dafnyCreate.Name);

                    //vars:
                    List <String> varNames = p.get_var_names();
                    List <String> varTypes = p.get_var_types();
                    for (int i = 0; i < varNames.Count; i++)
                    {
                        Variable arg1 = new Variable(varNames[i], varTypes[i]);
                        dafnyCreate.AddArgument(arg1);
                    }
                    // returns
                    List <String> retNames = p.get_ret_names();
                    List <String> retTypes = p.get_ret_types();
                    for (int i = 0; i < retNames.Count; i++)
                    {
                        Variable arg1 = new Variable(retNames[i], retTypes[i]);
                        dafnyCreate.AddRetValue(arg1);
                    }

                    // preconditions
                    List <String> precond = p.get_req();
                    for (int i = 0; i < precond.Count; i++)
                    {
                        dafnyCreate.AddPreCond(precond[i]);
                    }

                    //post conditions
                    List <String> postcond = p.get_ens();
                    for (int i = 0; i < postcond.Count; i++)
                    {
                        dafnyCreate.AddPostCond(postcond[i]);
                    }
                }
                catch
                {
                    MessageBox.Show("Error in parsing the file.", "Parser Exeption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.Close();
                    return;
                }

                // insert text
                toInsert.Insert("{\n" + dafnyCreate.generateBody() + "}\n\n" + dafnyCreate.generateMethod() + "\n\n" + dafnyCreate.generateWeakLemma() + "\n\n");
                this.Close();
            }
            catch
            {
                MessageBox.Show("Unexpected Exeption occurred during the execution.", "Unexpected Exeption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Close();
                return;
            }
        }