Example #1
0
        void ParseStep()
        {
            string code = null;

            Invoke(new MethodInvoker(delegate {
                code = textEditorControl1.Text;
            }));
            TextReader textReader = new StringReader(code);

            Dom.ICompilationUnit newCompilationUnit;
            if (Language == "C#")
            {
                using (NRefactory.IParser p = NRefactory.ParserFactory.CreateParser(NRefactory.SupportedLanguage.CSharp, textReader))
                {
                    p.Parse();
                    newCompilationUnit = ConvertCompilationUnit(p.CompilationUnit);
                }
            }
            else
            {
                using (NRefactory.IParser p = NRefactory.ParserFactory.CreateParser(NRefactory.SupportedLanguage.VBNet, textReader))
                {
                    p.Parse();
                    newCompilationUnit = ConvertCompilationUnit(p.CompilationUnit);
                }
            }
            // Remove information from lastCompilationUnit and add information from newCompilationUnit.
            myProjectContent.UpdateCompilationUnit(lastCompilationUnit, newCompilationUnit, DummyFileName);
            lastCompilationUnit = newCompilationUnit;
        }
Example #2
0
        void ParseStep()
        {
            string code = null;

            Invoke(new MethodInvoker(delegate {
                code = textEditorControl1.Text;
            }));
            TextReader textReader = new StringReader(code);

            Dom.ICompilationUnit         newCompilationUnit;
            NRefactory.SupportedLanguage supportedLanguage;
            if (IsVisualBasic)
            {
                supportedLanguage = NRefactory.SupportedLanguage.VBNet;
            }
            else
            {
                supportedLanguage = NRefactory.SupportedLanguage.CSharp;
            }
            using (NRefactory.IParser p = NRefactory.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);
            lastCompilationUnit = newCompilationUnit;
            parseInformation.SetCompilationUnit(newCompilationUnit);
        }
		public void SetUpFixture()
		{
			string python = 
				"import unittest\r\n" +
				"\r\n" +
				"class BaseTest(unittest.TestCase):\r\n" +
				"    def testSuccess(self):\r\n" +
				"        assert True\r\n" +
				"\r\n" +
				"class DerivedTest(BaseTest):\r\n" +
				"    pass\r\n" +
				"\r\n";
			
			projectContent = new DefaultProjectContent();
			PythonParser parser = new PythonParser();
			string fileName = @"C:\test.py";
			compilationUnit = parser.Parse(projectContent, fileName, python);
			projectContent.UpdateCompilationUnit(null, compilationUnit, fileName);
			if (compilationUnit.Classes.Count > 1) {
				c = compilationUnit.Classes[1];
			}
		}