public Solution(string fileName) { this.Directory = Path.GetDirectoryName(fileName); var projectLinePattern = new Regex("Project\\(\"(?<TypeGuid>.*)\"\\)\\s+=\\s+\"(?<Title>.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\""); foreach (string line in File.ReadLines(fileName)) { Match match = projectLinePattern.Match(line); if (match.Success) { string typeGuid = match.Groups["TypeGuid"].Value; string title = match.Groups["Title"].Value; string location = match.Groups["Location"].Value; string guid = match.Groups["Guid"].Value; switch (typeGuid.ToUpperInvariant()) { case "{2150E333-8FDC-42A3-9474-1A3956D46DE8}": // Solution Folder // ignore folders break; case "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}": // C# project Projects.Add(new CSharpProject(this, title, Path.Combine(Directory, location))); break; default: Console.WriteLine("Project {0} has unsupported type {1}", location, typeGuid); break; } } } // Create compilations (resolved type systems) after all projects have been loaded. // (we can't do this earlier because project A might have a reference to project B, where A is loaded before B) // To allow NRefactory to resolve project references, we need to use a 'DefaultSolutionSnapshot' // instead of calling CreateCompilation() on each project individually. var solutionSnapshot = new DefaultSolutionSnapshot(this.Projects.Select(p => p.ProjectContent)); foreach (CSharpProject project in this.Projects) { project.Compilation = solutionSnapshot.GetCompilation(project.ProjectContent); } }
public SemanticErrorsResponse FindSemanticErrors(Request request) { var clientFilename = request.FileName.ApplyPathReplacementsForClient(); var project = _solution.ProjectContainingFile(request.FileName); project.UpdateFile(request.FileName, request.Buffer); var solutionSnapshot = new DefaultSolutionSnapshot(_solution.Projects.Select(i => i.ProjectContent)); var syntaxTree = new CSharpParser().Parse(request.Buffer, request.FileName); var resolver = new CSharpAstResolver(solutionSnapshot.GetCompilation(project.ProjectContent), syntaxTree); var navigator = new SemanticErrorsNavigator(); resolver.ApplyNavigator(navigator); var errors = navigator.GetErrors().Select(i => new Error { FileName = clientFilename, Message = i.Message, Line = i.TextLocation.Line, Column = i.TextLocation.Column, }); return(new SemanticErrorsResponse { Errors = errors, }); }
public virtual ICompilation CreateCompilation() { var solutionSnapshot = new DefaultSolutionSnapshot(); ICompilation compilation = new SimpleCompilation(solutionSnapshot, this, assemblyReferences); solutionSnapshot.AddCompilation(this, compilation); return(compilation); }
public override ICompilation CreateCompilation() { var solutionSnapshot = new DefaultSolutionSnapshot(); ICompilation compilation = new MonoDevelopCompilation(solutionSnapshot, this, AssemblyReferences); solutionSnapshot.AddCompilation(this, compilation); return(compilation); }
private void LoadProjectCompilations() { var solutionSnapshot = new DefaultSolutionSnapshot(Projects.Select(p => p.ProjectContent)); foreach (var project in Projects) { project.Compilation = solutionSnapshot.GetCompilation(project.ProjectContent); } }
/// <summary> /// TODO: This is an expensive call - create a mechanism to suppress so a Compilations aren't recreated /// multiple times if multiple files are being added /// </summary> public void RecreateCompilations() { var solutionSnapshot = new DefaultSolutionSnapshot(Projects.Select(p => p.ProjectContent)); foreach (CSharpProject project in Projects) { project.Compilation = solutionSnapshot.GetCompilation(project.ProjectContent); } }
public void CreateCompilationUnitsForAllPojects() { var solutionSnapshot = new DefaultSolutionSnapshot(Projects.Select(project => project.ProjectContent)); foreach (var project in Projects) { project.Compilation = solutionSnapshot.GetCompilation(project.ProjectContent); } }
/// <summary> /// Sets <see cref="CSharpProject.Compilation"/> for every project in /// <see cref="Projects"/>. This is only valid once every project /// is fully loaded. /// </summary> public void RecreateCompilations() { var sw = Stopwatch.StartNew(); var solutionSnapshot = new DefaultSolutionSnapshot(Projects.Select(p => p.ProjectContent)); foreach (CSharpProject project in Projects) { project.Compilation = solutionSnapshot.GetCompilation(project.ProjectContent); } _log.DebugFormat("Compilation created in [{0}] ms", sw.ElapsedMilliseconds); }
public Solution(string fileName) { this.Directory = Path.GetDirectoryName(fileName); var projectLinePattern = new Regex("Project\\(\"(?<TypeGuid>.*)\"\\)\\s+=\\s+\"(?<Title>.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\""); foreach (string line in File.ReadLines(fileName)) { Match match = projectLinePattern.Match(line); if (match.Success) { string typeGuid = match.Groups["TypeGuid"].Value; string title = match.Groups["Title"].Value; string location = match.Groups["Location"].Value; string guid = match.Groups["Guid"].Value; switch (typeGuid.ToUpperInvariant()) { case "{2150E333-8FDC-42A3-9474-1A3956D46DE8}": // Solution Folder // ignore folders break; case "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}": // C# project //location=location.Replace("\\","/"); if (location.Contains("Editor")) { break; } Projects.Add(new CSharpProject(this, title, Path.Combine(Directory, location))); break; default: Console.WriteLine("Project {0} has unsupported type {1}", location, typeGuid); break; } } } // Create compilations (resolved type systems) after all projects have been loaded. // (we can't do this earlier because project A might have a reference to project B, where A is loaded before B) // To allow NRefactory to resolve project references, we need to use a 'DefaultSolutionSnapshot' // instead of calling CreateCompilation() on each project individually. var solutionSnapshot = new DefaultSolutionSnapshot(this.Projects.Select(p => p.ProjectContent)); foreach (CSharpProject project in this.Projects) { project.Compilation = solutionSnapshot.GetCompilation(project.ProjectContent); } }
public void ChooseCSProjFile(string fileName) { if (fileName.EndsWith(".csproj")) { projects.Add(new CSharpProject(this, "SampleProj", Path.Combine(directory, fileName))); } else if (fileName.EndsWith(".sln")) { var projectLinePattern = new Regex("Project\\(\"(?<TypeGuid>.*)\"\\)\\s+=\\s+\"(?<Title>.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\""); foreach (string line in File.ReadLines(fileName)) { Match match = projectLinePattern.Match(line); if (match.Success) { string typeGuid = match.Groups["TypeGuid"].Value; string title = match.Groups["Title"].Value; string location = match.Groups["Location"].Value; string guid = match.Groups["Guid"].Value; switch (typeGuid.ToUpperInvariant()) { case "{2150E333-8FDC-42A3-9474-1A3956D46DE8}": // Solution Folder // ignore folders break; case "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}": // C# project projects.Add(new CSharpProject(this, title, Path.Combine(directory, location))); break; default: Console.WriteLine("Project {0} has unsupported type {1}", location, typeGuid); break; } } } } var solutionSnapshot = new DefaultSolutionSnapshot(this.projects.Select(p => p.ProjectContent)); foreach (CSharpProject project in this.projects) { project.Compilation = solutionSnapshot.GetCompilation(project.ProjectContent); } }
public SemanticErrorsResponse FindSemanticErrors(Request request) { var clientFilename = request.FileName.ApplyPathReplacementsForClient(); var project = _solution.ProjectContainingFile(request.FileName); project.UpdateFile(request.FileName, request.Buffer); var solutionSnapshot = new DefaultSolutionSnapshot(_solution.Projects.Select(i => i.ProjectContent)); SyntaxTree syntaxTree; if (project.CompilerSettings != null) { syntaxTree = new CSharpParser(project.CompilerSettings).Parse(request.Buffer, request.FileName); } else { syntaxTree = new CSharpParser().Parse(request.Buffer, request.FileName); } var resolver = new CSharpAstResolver(solutionSnapshot.GetCompilation(project.ProjectContent), syntaxTree); var navigator = new SemanticErrorsNavigator(); resolver.ApplyNavigator(navigator); var errors = navigator.GetErrors() .Where(e => ShouldIncludeIssue(e.Message)) .Select(i => new Error { FileName = clientFilename, Message = i.Message, Line = i.StartLocation.Line, Column = i.EndLocation.Column, EndLine = i.EndLocation.Line, EndColumn = i.EndLocation.Column }); return(new SemanticErrorsResponse { Errors = errors, }); }
public virtual ICompilation CreateCompilation() { var solutionSnapshot = new DefaultSolutionSnapshot(); ICompilation compilation = new SimpleCompilation(solutionSnapshot, this, assemblyReferences); solutionSnapshot.AddCompilation(this, compilation); return compilation; }
public async Task AnalyzeAsync(CancellationToken cancellationToken) { IsBuilding = true; Status = SolutionStatus.LoadingParseTrees; foreach (var project in Projects) { if (cancellationToken.IsCancellationRequested) { return; } await project.LoadContentAsync(); } if (cancellationToken.IsCancellationRequested) { return; } await Task.WhenAll(from pr in _projects where pr.ProjectContent != null select pr.CountLinesAsync()); if (cancellationToken.IsCancellationRequested) { return; } Status = SolutionStatus.CountingLinesOfCode; this.LinesOfCode = _projects.Where(pr => pr.ProjectContent != null).Aggregate(new LineCountResult(0, 0, 0), (c, p) => c + p.LinesOfCode); this._snapshot = new DefaultSolutionSnapshot(_projects.Where(p => p.ProjectContent != null).Select(p => p.ProjectContent)); Status = SolutionStatus.BuildingTypeSystem; IsBuilding = false; foreach (var project in Projects) { if (cancellationToken.IsCancellationRequested) { return; } await project.LoadTypesAsync(); } foreach (var cSharpProject in Projects) { if (cancellationToken.IsCancellationRequested) { return; } await cSharpProject.LoadMethodsAsync(); } Status = SolutionStatus.AnalyzingParseTrees; foreach (var cSharpProject in Projects) { if (cancellationToken.IsCancellationRequested) { return; } await cSharpProject.LoadCallsAsync(); } Status = SolutionStatus.SavingOutput; if (cancellationToken.IsCancellationRequested) { return; } await Task.Run(() => { using (var writer = OpenTruncate(Path.GetFileNameWithoutExtension(FileName) + "-loc.csv")) { writer.WriteCsvLine("LinesOfCode", "LinesOfComment", "BlankLines"); writer.WriteCsvLine(LinesOfCode.CodeCount, LinesOfCode.CommentCount, LinesOfCode.BlankCount); } }); if (cancellationToken.IsCancellationRequested) { return; } await Task.Run(() => { using (var writer = OpenTruncate(Path.GetFileNameWithoutExtension(FileName) + "-dynamic.csv")) { writer.WriteCsvLine("Static Occurrances", "Dynamic Occurrences"); writer.WriteCsvLine(Projects.Sum(p => p.StaticUsageCount), Projects.Sum(p => p.DynamicUsageCount)); } }); if (cancellationToken.IsCancellationRequested) { return; } await Task.Run(() => { using (var writer = OpenTruncate(Path.GetFileNameWithoutExtension(FileName) + "-types.csv")) { writer.WriteCsvLine("TypeName;SystemType"); foreach (var cSharpType in Nodes.Values) { writer.WriteCsvLine(cSharpType.GetLocString(), cSharpType.IsOwnCode); } } }); if (cancellationToken.IsCancellationRequested) { return; } await Task.Run(() => { using (var writer = OpenTruncate(Path.GetFileNameWithoutExtension(FileName) + "-inheritance.csv")) { writer.WriteLine("type;from;to;direct;marker;constants;systemType"); foreach (var inheritanceRelationship in Edges) { var derivedName = inheritanceRelationship.DerivedType.GetLocString(); var type = inheritanceRelationship.InheritanceTypeName; var baseName = inheritanceRelationship.BaseType.GetLocString(); writer.WriteCsvLine(type, derivedName, baseName, true, inheritanceRelationship.Marker, inheritanceRelationship.BaseType.IsConstants, inheritanceRelationship.BaseType.IsOwnCode); } } if (cancellationToken.IsCancellationRequested) { return; } using (var writer = OpenTruncate(Path.GetFileNameWithoutExtension(FileName) + "-internal-reuse.csv")) { writer.WriteLine("direct?;source;from;to;from declaration;to declaration"); foreach (var inheritanceRelationship in Edges) { var derivedName = inheritanceRelationship.DerivedType.GetLocString(); var baseName = inheritanceRelationship.BaseType.GetLocString(); foreach (var reuse in inheritanceRelationship.InternalReuse) { writer.WriteCsvLine(reuse.IsDirect, reuse.Type, derivedName, baseName, reuse.Name, reuse.From); } } } if (cancellationToken.IsCancellationRequested) { return; } using (var writer = OpenTruncate(Path.GetFileNameWithoutExtension(FileName) + "-external-reuse.csv")) { writer.WriteLine("direct?;source;from;to;from declaration;to declaration"); foreach (var inheritanceRelationship in Edges) { var derivedName = inheritanceRelationship.DerivedType.GetLocString(); var baseName = inheritanceRelationship.BaseType.GetLocString(); foreach (var reuse in inheritanceRelationship.ExternalReuse) { writer.WriteCsvLine(reuse.IsDirect, reuse.Type, derivedName, baseName, reuse.Name, reuse.From); } } } if (cancellationToken.IsCancellationRequested) { return; } using (var writer = OpenTruncate(Path.GetFileNameWithoutExtension(FileName) + "-subtype.csv")) { writer.WriteLine("direct?;source;from;to;from declaration"); foreach (var inheritanceRelationship in Edges) { var derivedName = inheritanceRelationship.DerivedType.GetLocString(); var baseName = inheritanceRelationship.BaseType.GetLocString(); foreach (var subtype in inheritanceRelationship.Subtypes) { writer.WriteCsvLine(subtype.IsDirect, subtype.Kind, derivedName, baseName, subtype.FromReference); } } } if (cancellationToken.IsCancellationRequested) { return; } using (var writer = OpenTruncate(Path.GetFileNameWithoutExtension(FileName) + "-downcall.csv")) { writer.WriteLine("fromType;toType;fromMethod;toMethod;calledFrom"); foreach (var inheritanceRelationship in Edges) { var derivedName = inheritanceRelationship.DerivedType.GetLocString(); var baseName = inheritanceRelationship.BaseType.GetLocString(); foreach (var downcall in inheritanceRelationship.Downcalls) { writer.WriteCsvLine(derivedName, baseName, downcall.Method, downcall.Method, downcall.FromReference); } } } if (cancellationToken.IsCancellationRequested) { return; } using (var writer = OpenTruncate(Path.GetFileNameWithoutExtension(FileName) + "-super.csv")) { writer.WriteLine("From;To;Source"); foreach (var inheritanceRelationship in Edges.Where(e => e.Super)) { var derivedName = inheritanceRelationship.DerivedType.GetLocString(); var baseName = inheritanceRelationship.BaseType.GetLocString(); writer.WriteCsvLine(derivedName, baseName, "(not implemented)"); } } if (cancellationToken.IsCancellationRequested) { return; } using (var writer = OpenTruncate(Path.GetFileNameWithoutExtension(FileName) + "-generic.csv")) { writer.WriteLine("From;To;"); foreach (var inheritanceRelationship in Edges.Where(e => e.Generic)) { var derivedName = inheritanceRelationship.DerivedType.GetLocString(); var baseName = inheritanceRelationship.BaseType.GetLocString(); writer.WriteCsvLine(derivedName, baseName); } } }); Status = SolutionStatus.Completed; //enable GC to prevent OutOfMemoryExceptions Nodes = null; Edges = null; _snapshot = null; _assemblyCache.Clear(); foreach (var cSharpProject in _projects) { cSharpProject.Clear(); } }
public override ICompilation CreateCompilation() { var solutionSnapshot = new DefaultSolutionSnapshot(); ICompilation compilation = new MonoDevelopCompilation(solutionSnapshot, this, AssemblyReferences); solutionSnapshot.AddCompilation(this, compilation); return compilation; }