public void Should_cache_added_items() { var cache = new OutputWriter(new NullResponseWriter()); cache.WriteProject(new Project("")); var file = new FileRef("", null); cache.WriteFile(file); cache.WriteUsing(new Using(file, "", 0, 1)); cache.WriteNamespace(new Namespce(file, "", 0, 1)); cache.WriteClass(new Class(file, "", "", "", 0, 0)); cache.WriteInterface(new Interface(file, "", "", "", 0, 0)); cache.WriteStruct(new Struct(file, "", "", "", 0, 0)); cache.WriteEnum(new EnumType(file, "", "", "", 0, 0)); cache.WriteField(new Field(file, "", "", "", 0, 0, "")); cache.WriteMethod( new Method(file, "", "", "", 0, 0, "", new Parameter[] { new Parameter(file, "", "", "", 0, 0, "") })); cache.WriteVariable(new Variable(file, "", "", "", 0, 0, "")); Assert.That(cache.Projects.Count, Is.EqualTo(1)); Assert.That(cache.Files.Count, Is.EqualTo(1)); Assert.That(cache.Usings.Count, Is.EqualTo(1)); Assert.That(cache.Namespaces.Count, Is.EqualTo(1)); Assert.That(cache.Classes.Count, Is.EqualTo(1)); Assert.That(cache.Interfaces.Count, Is.EqualTo(1)); Assert.That(cache.Structs.Count, Is.EqualTo(1)); Assert.That(cache.Enums.Count, Is.EqualTo(1)); Assert.That(cache.Fields.Count, Is.EqualTo(1)); Assert.That(cache.Methods.Count, Is.EqualTo(1)); Assert.That(cache.Parameters.Count, Is.EqualTo(1)); Assert.That(cache.Variables.Count, Is.EqualTo(1)); }
public void ParseFile(FileRef file, Func<string> getContent) { lock (_padLock) { _builder.WriteFile(file); _file = file; _content = getContent(); _currentLocation = Location.Root; _currentNamespace = null; _navigator = new CSharpCodeNavigator( _content.ToCharArray(), () => { _locationHierarchy.Push(_currentLocation); _locationHierarchyActivity.Add( new LocationHierarchyActivity() { Push = true, Location = _currentLocation }); _currentLocation = _suggestedLocation; _suggestedLocation = Location.Unknown; }, () => { _currentLocation = _locationHierarchy.Pop(); _locationHierarchyActivity.Add( new LocationHierarchyActivity() { Push = false, Location = _currentLocation }); }, (ifdef) => positionForIfDef(ifdef)); parse(); } }
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; }
public PartialType(FileRef file, Point location, string type, string parent, Action<string> resolve) { File = file; Location = location; Type = type; Parent = parent; _resolve = resolve; }
public Namespce(FileRef file, string name, int line, int column) { File = file; Name = name; Scope = ""; Line = line; Column = column; JSON = ""; }
public Using(FileRef file, string name, int line, int column) { File = file; Parent = ""; Name = name; Scope = ""; Line = line; Column = column; JSON = ""; }
public void When_merging_it_will_replace_info_for_the_entire_file() { var cache = new OutputWriter(new NullResponseWriter()); var file = new FileRef("file1", null); cache.WriteFile(file); cache.WriteUsing(new Using(file, "", 0, 1)); cache.WriteNamespace(new Namespce(file, "", 0, 1)); cache.WriteClass(new Class(file, "", "", "", 0, 0)); cache.WriteInterface(new Interface(file, "", "", "", 0, 0)); cache.WriteStruct(new Struct(file, "", "", "", 0, 0)); cache.WriteEnum(new EnumType(file, "", "", "", 0, 0)); cache.WriteField(new Field(file, "", "", "", 0, 0, "")); cache.WriteMethod( new Method(file, "", "", "", 0, 0, "", new Parameter[] { new Parameter(file, "", "", "", 0, 0, "") })); cache.WriteVariable(new Variable(file, "", "", "", 0, 0, "")); var cacheToMerge = new OutputWriter(new NullResponseWriter()); file = new FileRef("file1", null); cacheToMerge.WriteFile(file); cacheToMerge.WriteUsing(new Using(file, "", 0, 1)); cacheToMerge.WriteUsing(new Using(file, "", 0, 1)); cacheToMerge.WriteNamespace(new Namespce(file, "", 0, 1)); cacheToMerge.WriteNamespace(new Namespce(file, "", 0, 1)); cacheToMerge.WriteClass(new Class(file, "", "", "", 0, 0)); cacheToMerge.WriteClass(new Class(file, "", "", "", 0, 0)); cacheToMerge.WriteInterface(new Interface(file, "", "", "", 0, 0)); cacheToMerge.WriteInterface(new Interface(file, "", "", "", 0, 0)); cacheToMerge.WriteStruct(new Struct(file, "", "", "", 0, 0)); cacheToMerge.WriteStruct(new Struct(file, "", "", "", 0, 0)); cacheToMerge.WriteEnum(new EnumType(file, "", "", "", 0, 0)); cacheToMerge.WriteEnum(new EnumType(file, "", "", "", 0, 0)); cacheToMerge.WriteField(new Field(file, "", "", "", 0, 0, "")); cacheToMerge.WriteField(new Field(file, "", "", "", 0, 0, "")); cacheToMerge.WriteMethod( new Method(file, "", "", "", 0, 0, "", new Parameter[] { new Parameter(file, "", "", "", 0, 0, "") })); cacheToMerge.WriteMethod( new Method(file, "", "", "", 0, 0, "", new Parameter[] { new Parameter(file, "", "", "", 0, 0, "") })); cacheToMerge.WriteVariable(new Variable(file, "", "", "", 0, 0, "")); cacheToMerge.WriteVariable(new Variable(file, "", "", "", 0, 0, "")); cache.MergeWith(cacheToMerge); Assert.That(cache.Projects.Count, Is.EqualTo(0)); Assert.That(cache.Files.Count, Is.EqualTo(1)); Assert.That(cache.Usings.Count, Is.EqualTo(2)); Assert.That(cache.Namespaces.Count, Is.EqualTo(2)); Assert.That(cache.Classes.Count, Is.EqualTo(2)); Assert.That(cache.Interfaces.Count, Is.EqualTo(2)); Assert.That(cache.Structs.Count, Is.EqualTo(2)); Assert.That(cache.Enums.Count, Is.EqualTo(2)); Assert.That(cache.Fields.Count, Is.EqualTo(2)); Assert.That(cache.Methods.Count, Is.EqualTo(2)); Assert.That(cache.Parameters.Count, Is.EqualTo(2)); Assert.That(cache.Variables.Count, Is.EqualTo(2)); }
public void Can_resolve_regular_class_from_file() { var resolvedWith = ""; var file = new FileRef("File1", new Project("Project1")); _resolver .ResolveMatchingType( new PartialType( file, new Point(3, 1), "FirstClass", "Project1", (s) => resolvedWith = s)); Assert.That(resolvedWith, Is.EqualTo("Project1.FirstClass")); }
public void When_not_able_to_resolve_file_it_will_not_be_in_the_list_of_resolved_types() { var resolvedWith = "not_set"; var file = new FileRef("File1", new Project("Project1")); _resolver .ResolveMatchingType( new PartialType( file, new Point(3, 1), "WillNotExist", "Project1", (s) => resolvedWith = s)); Assert.That(resolvedWith, Is.EqualTo("not_set")); }
public void Will_not_resolve_variable_assignment_expression_from_non_static_type_members() { var resolvedWith = "not_set"; var file = new FileRef("File1", new Project("Project1")); _resolver .ResolveMatchingType( new PartialType( file, new Point(14, 4), "SecondClass.Count", "Project1.FirstClass.myMethod", (s) => resolvedWith = s)); Assert.That(resolvedWith, Is.EqualTo("not_set")); }
public void Parse(string asm) { _file = new FileRef(asm, null); AssemblyDefinition assembly; if (File.Exists(_file.File)) assembly = AssemblyDefinition.ReadAssembly(_file.File); else assembly = new DefaultAssemblyResolver().Resolve(_file.File); _writer.WriteFile(_file); assembly .Modules.ToList() .ForEach(x => x.GetTypes().ToList() .ForEach(y => handleType(y))); }
public void Will_resolve_based_on_available_usings() { var resolvedWith = "not_set"; var file = new FileRef("File1", new Project("Project1")); _resolver .ResolveMatchingType( new PartialType( file, new Point(3, 1), "ThirdClass", "Project1", (s) => resolvedWith = s)); Assert.That(resolvedWith, Is.EqualTo("Project1.SecondNamespace.ThirdClass")); _resolver .ResolveMatchingType( new PartialType( file, new Point(3, 1), "SecondClass", "Project1", (s) => resolvedWith = s)); Assert.That(resolvedWith, Is.EqualTo("Project1.FirstNamespace.SecondClass")); }
public List<ICodeReference> ParseRefs(string resultString) { var refs = new List<ICodeReference>(); foreach (var command in resultString.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { try { var chunks = command.Trim() .Split(new char[] { '|' }, StringSplitOptions.None); if (chunks.Length == 0) continue; if (chunks[0] == "file") _currentFile = handleFile(chunks); if (chunks[1] == "signature") { var reference = handleSignature(chunks); if (reference != null) refs.Add(reference); } } catch { } } return refs; }
public UsingAlias(FileRef file, string alias, string type, int line, int column) { File = file; Parent = type; Name = alias; Scope = ""; Line = line; Column = column; JSON = ""; }
public void Will_resolve_variable_assignment_expression_local_scope_using_this() { var resolvedWith = "not_set"; var file = new FileRef("File1", new Project("Project1")); _resolver .ResolveMatchingType( new PartialType( file, new Point(14, 4), "this.str.ToString()", "Project1.FirstClass.myMethod", (s) => resolvedWith = s)); Assert.That(resolvedWith, Is.EqualTo("System.String")); }
private void parseFile(FileRef x) { Logger.Write("Parsing file " + x.File); try { new NRefactoryParser() .SetOutputWriter(_builder) .ParseFile(x, () => { return File.ReadAllText(x.File); }); } catch (Exception ex) { parseError(x.File, ex); } Logger.Write("Done parsing file " + x.File); }
private void buildCache() { var project1 = new Project("Project1"); _cache.WriteProject(project1); var file = new FileRef("File1", project1); _cache.WriteFile(file); _cache.WriteUsing(new Using(file, "Project1.FirstNamespace", 1, 1)); _cache.WriteNamespace(new Namespce(file, "Project1", 2, 1)); _cache.WriteClass( new Class(file, "Project1", "FirstClass", "public", 5, 1)); _cache.WriteField( new Field(file, "Project1.FirstClass", "FCls", "public", 6, 2, "SecondClass")); _cache.WriteMethod( new Method(file, "Project1.FirstClass", "myMethod", "private", 7, 5, "System.Void", new Parameter[]{})); _cache.WriteVariable( new Variable(file, "Project1.FirstClass.myMethod", "str", "local", 9, 3, "System.String")); var file2 = new FileRef("File2", project1); _cache.WriteFile(file2); _cache.WriteNamespace(new Namespce(file2, "Project1.SecondNamespace", 10, 1)); _cache.WriteClass( new Class(file2, "Project1.SecondNamespace", "ThirdClass", "public", 12, 2)); _cache.WriteClass( new Class(file2, "Project1.SecondNamespace", "SecondClass", "public", 2, 1)); _cache.WriteNamespace(new Namespce(file2, "Project1.FirstNamespace", 1, 1)); _cache.WriteClass( new Class(file2, "Project1.FirstNamespace", "SecondClass", "public", 2, 1)); _cache.WriteField( new Field(file, "Project1.FirstNamespace.SecondClass", "Count", "public", 3, 2, "System.Int32")); var staticField = new Field(file, "Project1.FirstNamespace.SecondClass", "NAME", "public", 3, 2, "System.String"); staticField.AddModifiers(new[]{ "static" }); _cache.WriteField(staticField); var project2 = new Project("Project2"); _cache.WriteProject(project2); var system = new FileRef("mscorlib", null); _cache.WriteFile(system); _cache.WriteNamespace(new Namespce(system, "System",0,0)); _cache.WriteNamespace(new Namespce(system, "System.More", 0, 0)); _cache.WriteClass( new Class(system, "System", "String", "public", 0, 0)); _cache.WriteMethod( new Method(system, "System.Object", "ToString", "public", 0, 0, "System.String", new Parameter[] {})); _cache.WriteEnum( new EnumType(system, "System.More", "FunnyBool", "public", 0, 0)); _cache.WriteField( new Field(system, "System.More.FunnyBool", "True", "public", 0, 0, "System.Int32").AddModifiers(new[] { "static" })); _cache.BuildTypeIndex(); }
private static void getPartials(IEnumerable<ICodeReference> codeRefs, FileRef file, List<PartialType> partials) { codeRefs .Where(x => !x.AllTypesAreResolved && x.File.File == file.File).ToList() .ForEach(x => { x.AllTypesAreResolved = true; partials.AddRange( x.GetResolveStatements() .Select(stmnt => new PartialType( file, new Point(x.Line, x.Column), stmnt.Value, stmnt.Namespace, stmnt.Replace))); }); }
public void Will_resolve_variable_assignment_expression_from_private_scope() { var resolvedWith = "not_set"; var file = new FileRef("File1", new Project("Project1")); _resolver .ResolveMatchingType( new PartialType( file, new Point(14, 4), "FCls.Count", "Project1.FirstClass.myMethod", (s) => resolvedWith = s)); Assert.That(resolvedWith, Is.EqualTo("System.Int32")); }
public void Will_resolve_based_on_local_variables() { var resolvedWith = "not_set"; var file = new FileRef("File1", new Project("Project1")); _resolver .ResolveMatchingType( new PartialType( file, new Point(12, 4), "str", "Project1.FirstClass.myMethod", (s) => resolvedWith = s)); Assert.That(resolvedWith, Is.EqualTo("System.String")); }