예제 #1
0
        public void parseSourceCode(string file, string code)
        {
            var text = textEditor.get_Text();

            //textEditor.set(")
            if (false == code.valid())
            {
                return;
            }

            if (false == mappedCompilationUnits.ContainsKey(file))
            {
                mappedCompilationUnits.Add(file, null);
            }

            var lastCompilationUnit = mappedCompilationUnits[file];

            var textReader = new StringReader(code);
            ICompilationUnit newCompilationUnit;
            var supportedLanguage = SupportedLanguage.CSharp;

            using (IParser p = ParserFactory.CreateParser(supportedLanguage, textReader))
            {
                // we only need to parse types and method definitions, no method bodies
                // so speed up the parser and make it more resistent to syntax
                // errors in methods
                p.ParseMethodBodies = false;
                p.Parse();
                newCompilationUnit = ConvertCompilationUnit(p.CompilationUnit);
            }
            // Remove information from lastCompilationUnit and add information from newCompilationUnit.
            myProjectContent.UpdateCompilationUnit(lastCompilationUnit, newCompilationUnit, DummyFileName);
            mappedCompilationUnits[file] = newCompilationUnit;
            //            lastCompilationUnit = newCompilationUnit;
            parseInformation.SetCompilationUnit(newCompilationUnit);

            try {
                //    if (file.exists())
                textEditor.Document.FoldingManager.UpdateFoldings(this.DummyFileName, parseInformation);
            } catch //(Exception ex)
            {
                //ex.log(ex);
            }
        }