示例#1
0
        public override void Execute(TextArea textArea)
        {
            WorkbenchServiceFactory.Workbench.ErrorsListWindow.ClearErrorList();
            CodeFormatters.CodeFormatter          cf     = new CodeFormatters.CodeFormatter(VisualPABCSingleton.MainForm.UserOptions.TabIndent);
            List <PascalABCCompiler.Errors.Error> Errors = new List <PascalABCCompiler.Errors.Error>();
            //PascalABCCompiler.SyntaxTree.syntax_tree_node sn =
            //    MainForm.VisualEnvironmentCompiler.Compiler.ParsersController.Compile(
            //    FileName, TextEditor.Text, null, Errors, PascalABCCompiler.Parsers.ParseMode.Normal);
            string text = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.SourceFilesProvider(VisualPABCSingleton.MainForm.CurrentCodeFileDocument.FileName, PascalABCCompiler.SourceFileOperation.GetText) as string;

            PascalABCCompiler.SyntaxTree.compilation_unit cu =
                CodeCompletion.CodeCompletionController.ParsersController.GetCompilationUnitForFormatter(
                    VisualPABCSingleton.MainForm.CurrentCodeFileDocument.FileName,
                    text, //VisualPascalABC.Form1.Form1_object._currentCodeFileDocument.TextEditor.Text,
                    Errors,
                    new List <PascalABCCompiler.Errors.CompilerWarning>());
            if (Errors.Count == 0)
            {
                string formattedText = cf.FormatTree(text, cu, textArea.Caret.Line + 1, textArea.Caret.Column + 1);
                bool   success       = true;
                if (success)
                {
                    //WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.ExecuteAction(VisualPascalABCPlugins.VisualEnvironmentCompilerAction.SetCurrentSourceFileTextFormatting, "");
                    WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.ExecuteAction(VisualPascalABCPlugins.VisualEnvironmentCompilerAction.SetCurrentSourceFileTextFormatting, formattedText);
                    WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.ExecuteSourceLocationAction(
                        new PascalABCCompiler.SourceLocation(VisualPABCSingleton.MainForm.CurrentCodeFileDocument.FileName, cf.Line, cf.Column, cf.Line, cf.Column), VisualPascalABCPlugins.SourceLocationAction.GotoBeg);
                }
            }
            else
            {
                WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.ExecuteAction(VisualPascalABCPlugins.VisualEnvironmentCompilerAction.AddMessageToErrorListWindow, new List <PascalABCCompiler.Errors.Error>(new PascalABCCompiler.Errors.Error[] { Errors[0] }));
            }
        }
示例#2
0
        public static void Test()
        {
            string test_dir = GetTestSuiteDir() + @"\formatter_tests";

            string[]           files = Directory.GetFiles(test_dir + @"\input", "*.pas");
            StreamWriter       log   = new StreamWriter(test_dir + @"\output\log.txt", false, Encoding.GetEncoding(1251));
            SyntaxTreeComparer stc   = new SyntaxTreeComparer();

            foreach (string s in files)
            {
                string                 Text     = new StreamReader(s, System.Text.Encoding.GetEncoding(1251)).ReadToEnd();
                List <Error>           Errors   = new List <Error>();
                List <CompilerWarning> Warnings = new List <CompilerWarning>();
                compilation_unit       cu       = CodeCompletionController.ParsersController.GetCompilationUnitForFormatter(s, Text, Errors, Warnings);
                if (Errors.Count == 0)
                {
                    CodeFormatters.CodeFormatter cf = new CodeFormatters.CodeFormatter(2);
                    Text = cf.FormatTree(Text, cu, 1, 1);
                    StreamWriter sw = new StreamWriter(Path.Combine(test_dir + @"\output", Path.GetFileName(s)), false, Encoding.GetEncoding(1251));
                    sw.Write(Text);
                    sw.Close();
                    Errors.Clear();
                    Warnings.Clear();
                    compilation_unit cu2 = CodeCompletionController.ParsersController.GetCompilationUnitForFormatter(Path.Combine(test_dir + @"\output", Path.GetFileName(s)), Text, Errors, Warnings);
                    if (Errors.Count > 0)
                    {
                        for (int i = 0; i < Errors.Count; i++)
                        {
                            log.WriteLine(Errors[i].ToString());
                        }
                    }
                    else
                    {
                        try
                        {
                            stc.Compare(cu, cu2);
                        }
                        catch (Exception ex)
                        {
                            log.WriteLine("SyntaxTreeNotEquals " + s + Environment.NewLine);
                        }
                    }
                }
            }
            files = Directory.GetFiles(test_dir + @"\output", "*.pas");
            foreach (string s in files)
            {
                string                       Text     = new StreamReader(s, System.Text.Encoding.GetEncoding(1251)).ReadToEnd();
                List <Error>                 Errors   = new List <Error>();
                List <CompilerWarning>       Warnings = new List <CompilerWarning>();
                compilation_unit             cu       = CodeCompletionController.ParsersController.GetCompilationUnitForFormatter(s, Text, Errors, Warnings);
                CodeFormatters.CodeFormatter cf       = new CodeFormatters.CodeFormatter(2);
                string                       Text2    = cf.FormatTree(Text, cu, 1, 1);
                if (Text != Text2)
                {
                    log.WriteLine("Inavlid formatting of File " + s);
                }
            }
            log.Close();
        }
示例#3
0
 public static void Test()
 {
     string test_dir = GetTestSuiteDir() + @"\formatter_tests";
     string[] files = Directory.GetFiles(test_dir+@"\input","*.pas");
     StreamWriter log = new StreamWriter(test_dir + @"\output\log.txt", false, Encoding.GetEncoding(1251));
     SyntaxTreeComparer stc = new SyntaxTreeComparer();
     foreach (string s in files)
     {
         string Text = new StreamReader(s,System.Text.Encoding.GetEncoding(1251)).ReadToEnd();
         List<Error> Errors = new List<Error>();
         compilation_unit cu = CodeCompletionController.ParsersController.GetCompilationUnitForFormatter(s, Text, Errors);
         if (Errors.Count == 0)
         {
             CodeFormatters.CodeFormatter cf = new CodeFormatters.CodeFormatter(2);
             Text = cf.FormatTree(Text, cu, 1, 1);
             StreamWriter sw = new StreamWriter(Path.Combine(test_dir + @"\output", Path.GetFileName(s)), false, Encoding.GetEncoding(1251));
             sw.Write(Text);
             sw.Close();
             Errors.Clear();
             compilation_unit cu2 = CodeCompletionController.ParsersController.GetCompilationUnitForFormatter(Path.Combine(test_dir + @"\output", Path.GetFileName(s)), Text, Errors);
             if (Errors.Count > 0)
             {
                 for (int i = 0; i < Errors.Count; i++)
                     log.WriteLine(Errors[i].ToString());
             }
             else
                 try
                 {
                     stc.Compare(cu, cu2);
                 }
                 catch (Exception ex)
                 {
                     log.WriteLine("SyntaxTreeNotEquals " + s + Environment.NewLine);
                 }
         }
     }
     files = Directory.GetFiles(test_dir+@"\output", "*.pas");
     foreach (string s in files)
     {
         string Text = new StreamReader(s, System.Text.Encoding.GetEncoding(1251)).ReadToEnd();
         List<Error> Errors = new List<Error>();
         compilation_unit cu = CodeCompletionController.ParsersController.GetCompilationUnitForFormatter(s, Text, Errors);
         CodeFormatters.CodeFormatter cf = new CodeFormatters.CodeFormatter(2);
         string Text2 = cf.FormatTree(Text, cu, 1, 1);
         if (Text != Text2)
             log.WriteLine("Inavlid formatting of File " + s);
     }
     log.Close();
 }
 public override void Execute(TextArea textArea)
 {
     WorkbenchServiceFactory.Workbench.ErrorsListWindow.ClearErrorList();
     CodeFormatters.CodeFormatter cf = new CodeFormatters.CodeFormatter(VisualPABCSingleton.MainForm.UserOptions.TabIndent);
     List<PascalABCCompiler.Errors.Error> Errors = new List<PascalABCCompiler.Errors.Error>();
     //PascalABCCompiler.SyntaxTree.syntax_tree_node sn =
     //    MainForm.VisualEnvironmentCompiler.Compiler.ParsersController.Compile(
     //    FileName, TextEditor.Text, null, Errors, PascalABCCompiler.Parsers.ParseMode.Normal);
     string text = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.SourceFilesProvider(VisualPABCSingleton.MainForm.CurrentCodeFileDocument.FileName, PascalABCCompiler.SourceFileOperation.GetText) as string;
     PascalABCCompiler.SyntaxTree.compilation_unit cu =
         CodeCompletion.CodeCompletionController.ParsersController.GetCompilationUnitForFormatter(
         VisualPABCSingleton.MainForm.CurrentCodeFileDocument.FileName,
        text, //VisualPascalABC.Form1.Form1_object._currentCodeFileDocument.TextEditor.Text,
         Errors);
     if (Errors.Count == 0)
     {
         string formattedText = cf.FormatTree(text, cu, textArea.Caret.Line + 1, textArea.Caret.Column + 1);
         bool success = true;
         if (success)
         {
             //WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.ExecuteAction(VisualPascalABCPlugins.VisualEnvironmentCompilerAction.SetCurrentSourceFileTextFormatting, "");
             WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.ExecuteAction(VisualPascalABCPlugins.VisualEnvironmentCompilerAction.SetCurrentSourceFileTextFormatting, formattedText);
             WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.ExecuteSourceLocationAction(
                         new PascalABCCompiler.SourceLocation(VisualPABCSingleton.MainForm.CurrentCodeFileDocument.FileName, cf.Line, cf.Column, cf.Line, cf.Column), VisualPascalABCPlugins.SourceLocationAction.GotoBeg);
         }
     }
     else
     {
         WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.ExecuteAction(VisualPascalABCPlugins.VisualEnvironmentCompilerAction.AddMessageToErrorListWindow, new List<PascalABCCompiler.Errors.Error>(new PascalABCCompiler.Errors.Error[] { Errors[0] }));
     }
 }