public OutputWriter Parse(string file) { var dirtyFile = _getDirtyFile(file); var usingDirtyFile = false; if (dirtyFile != null) { dirtyFile = parseDirtyFile(dirtyFile); if (dirtyFile.Trim() != "") { usingDirtyFile = true; file = dirtyFile.Trim(); } } var parser = new NRefactoryParser(); if (_parseLocalVariables) parser.ParseLocalVariables(); var cache = new OutputWriter(new NullResponseWriter()); parser.SetOutputWriter(cache); var fileRef = new FileRef(file, null); parser.ParseFile(fileRef, () => _fileReader(file)); if (usingDirtyFile) _fileRemover(file); cache.BuildTypeIndex(); new TypeResolver(new OutputWriterCacheReader(cache, _globalCache)) .ResolveAllUnresolved(cache); return cache; }
private void createLocalCache() { var sb = new StringBuilder(); Action <string> a = (s) => sb.AppendLine(s); a("using System;"); a(""); a("namespace MyNS"); a("{"); a(" public class MyClass"); a(" {"); a(" private void MyMethod(string word) {"); a(" var str = \"Hello World\";"); a(" Console.WriteLine(str + word);"); a(" var bleh = 15;"); a(" Console.WriteLine(bleh.ToString());"); a(" if (_isValid)"); a(" Console.WriteLine(\"meh\");"); a(" }"); a(" "); a(" private bool _isValid = false;"); a(" }"); a("}"); _fileContent = sb.ToString(); _cache = new OutputWriter(new NullResponseWriter()); _cache.SetTypeVisibility(true); var parser = new NRefactoryParser() .ParseLocalVariables(); parser.SetOutputWriter(_cache); parser.ParseFile(new FileRef("MyFile", null), () => _fileContent); _cache.BuildTypeIndex(); new TypeResolver(new OutputWriterCacheReader(_cache, _globalCache)) .ResolveAllUnresolved(_cache); }
public OutputWriter Parse(string file) { var dirtyFile = _getDirtyFile(file); var usingDirtyFile = false; if (dirtyFile != null) { dirtyFile = parseDirtyFile(dirtyFile); if (dirtyFile.Trim() != "") { usingDirtyFile = true; file = dirtyFile.Trim(); } } var parser = new NRefactoryParser(); if (_parseLocalVariables) { parser.ParseLocalVariables(); } var cache = new OutputWriter(new NullResponseWriter()); parser.SetOutputWriter(cache); var fileRef = new FileRef(file, null); parser.ParseFile(fileRef, () => _fileReader(file)); if (usingDirtyFile) { _fileRemover(file); } cache.BuildTypeIndex(); new TypeResolver(new OutputWriterCacheReader(cache, _globalCache)) .ResolveAllUnresolved(cache); return(cache); }
static void TestInsertionPoints(string text) { TextEditorData data = new TextEditorData(); List <InsertionPoint> loc = new List <InsertionPoint> (); for (int i = 0; i < text.Length; i++) { char ch = text[i]; if (ch == '@') { i++; ch = text[i]; NewLineInsertion insertBefore = NewLineInsertion.None; NewLineInsertion insertAfter = NewLineInsertion.None; switch (ch) { case 'n': break; case 'd': insertAfter = NewLineInsertion.Eol; break; case 'D': insertAfter = NewLineInsertion.BlankLine; break; case 'u': insertBefore = NewLineInsertion.Eol; break; case 'U': insertBefore = NewLineInsertion.BlankLine; break; case 's': insertBefore = insertAfter = NewLineInsertion.Eol; break; case 'S': insertBefore = insertAfter = NewLineInsertion.BlankLine; break; case 't': insertBefore = NewLineInsertion.Eol; insertAfter = NewLineInsertion.BlankLine; break; case 'v': insertBefore = NewLineInsertion.BlankLine; insertAfter = NewLineInsertion.Eol; break; default: Assert.Fail("unknown insertion point:" + ch); break; } loc.Add(new InsertionPoint(data.Document.OffsetToLocation(data.Document.Length), insertBefore, insertAfter)); } else { data.Insert(data.Document.Length, ch.ToString()); } } var parseResult = new NRefactoryParser().Parse(null, "a.cs", data.Document.Text); var foundPoints = HelperMethods.GetInsertionPoints(data.Document, parseResult.CompilationUnit.Types[0]); Assert.AreEqual(loc.Count, foundPoints.Count, "point count doesn't match"); for (int i = 0; i < loc.Count; i++) { Console.WriteLine(loc[i] + "/" + foundPoints[i]); Assert.AreEqual(loc[i].Location, foundPoints[i].Location, "point " + i + " doesn't match"); Assert.AreEqual(loc[i].LineAfter, foundPoints[i].LineAfter, "point " + i + " ShouldInsertNewLineAfter doesn't match"); Assert.AreEqual(loc[i].LineBefore, foundPoints[i].LineBefore, "point " + i + " ShouldInsertNewLineBefore doesn't match"); } }
private void createLocalCache() { var sb = new StringBuilder(); Action<string> a = (s) => sb.AppendLine(s); a("using System;"); a(""); a("namespace MyNS"); a("{"); a(" public class MyClass"); a(" {"); a(" private void MyMethod(string word) {"); a(" var str = \"Hello World\";"); a(" Console.WriteLine(str + word);"); a(" var bleh = 15;"); a(" Console.WriteLine(bleh.ToString());"); a(" if (_isValid)"); a(" Console.WriteLine(\"meh\");"); a(" }"); a(" "); a(" private bool _isValid = false;"); a(" }"); a("}"); _fileContent = sb.ToString(); _cache = new OutputWriter(new NullResponseWriter()); _cache.SetTypeVisibility(true); var parser = new NRefactoryParser() .ParseLocalVariables(); parser.SetOutputWriter(_cache); parser.ParseFile(new FileRef("MyFile", null), () => _fileContent); _cache.BuildTypeIndex(); new TypeResolver(new OutputWriterCacheReader(_cache, _globalCache)) .ResolveAllUnresolved(_cache); }