/// <summary>Generates a C# file from a T4 file.</summary> /// <param name="modificationInfo">The modifications that occurred in the T4 file.</param> public override ISecondaryDocumentGenerationResult Generate(PrimaryFileModificationInfo modificationInfo) { if (!(modificationInfo.NewPsiFile is IT4File t4File)) { return(null); } var generator = new T4CSharpCodeGenerator(t4File, _directiveInfoManager); GenerationResult result = generator.Generate(); LanguageService csharpLanguageService = CSharpLanguage.Instance.LanguageService(); if (csharpLanguageService == null) { return(null); } var includedFiles = new OneToSetMap <FileSystemPath, FileSystemPath>(); includedFiles.AddRange(modificationInfo.SourceFile.GetLocation(), t4File.GetNonEmptyIncludePaths()); ISolution solution = modificationInfo.SourceFile.GetSolution(); var t4FileDependencyManager = solution.GetComponent <T4FileDependencyManager>(); return(new T4SecondaryDocumentGenerationResult( modificationInfo.SourceFile, result.Builder.ToString(), csharpLanguageService.LanguageType, new RangeTranslatorWithGeneratedRangeMap(result.GeneratedRangeMap), csharpLanguageService.GetPrimaryLexerFactory(), t4FileDependencyManager, t4File.GetNonEmptyIncludePaths() )); }
private IList<MethodArgumentStatus> CalculateArgumentStatuses() { var argumentStatuses = new List<MethodArgumentStatus>(); var allInvokedExpressions = new OneToSetMap<IVariableDeclaration, InvokedExpressionData>(); var allStatuses = new OneToSetMap<IVariableDeclaration, VariableDisposeStatus>(); DoForEachExit(data => { data.InvokedExpressions.ForEach(kvp => allInvokedExpressions.AddRange(kvp.Key, kvp.Value)); data.Status.ForEach(kvp => allStatuses.Add(kvp.Key, kvp.Value)); }); var generalStatuses = new Dictionary<IVariableDeclaration, VariableDisposeStatus>(); allStatuses.ForEach(kvp => generalStatuses[kvp.Key] = GetGeneralStatus(kvp.Value)); if (_disposableArguments == null) return null; _disposableArguments.ForEach( kvp => argumentStatuses.Add(new MethodArgumentStatus(kvp.Value, generalStatuses[kvp.Key], allInvokedExpressions[kvp.Key].OrderBy(im => im.Offset).ToList(), _psiSourceFile))); if (_processThis) { var allThisInvokedExpressions = new HashSet<InvokedExpressionData>(); var allThisStatuses = new HashSet<VariableDisposeStatus>(); DoForEachExit(data => { allThisInvokedExpressions.UnionWith(data.ThisInvokedExpressions); if (data.ThisStatus.HasValue) allThisStatuses.Add(data.ThisStatus.Value); }); argumentStatuses.Add(new MethodArgumentStatus(0, GetGeneralStatus(allThisStatuses), allThisInvokedExpressions.OrderBy(im => im.Offset).ToList(), _psiSourceFile)); } return argumentStatuses.OrderBy(mas => mas.Number).ToList(); }
/// <summary> /// Generates a C# file from a T4 file. /// </summary> /// <param name="modificationInfo">The modifications that occurred in the T4 file.</param> public override ISecondaryDocumentGenerationResult Generate(PrimaryFileModificationInfo modificationInfo) { var t4File = modificationInfo.NewPsiFile as IT4File; if (t4File == null) return null; var generator = new T4CSharpCodeGenerator(t4File, _directiveInfoManager); GenerationResult result = generator.Generate(); LanguageService csharpLanguageService = CSharpLanguage.Instance.LanguageService(); if (csharpLanguageService == null) return null; var includedFiles = new OneToSetMap<FileSystemPath, FileSystemPath>(); includedFiles.AddRange(modificationInfo.SourceFile.GetLocation(), t4File.GetNonEmptyIncludePaths()); ISolution solution = modificationInfo.SourceFile.GetSolution(); var t4FileDependencyManager = solution.GetComponent<T4FileDependencyManager>(); return new T4SecondaryDocumentGenerationResult( modificationInfo.SourceFile, result.Builder.ToString(), csharpLanguageService.LanguageType, new RangeTranslatorWithGeneratedRangeMap(result.GeneratedRangeMap), csharpLanguageService.GetPrimaryLexerFactory(), t4FileDependencyManager, t4File.GetNonEmptyIncludePaths()); }
public void UpdateIncludes([NotNull] FileSystemPath includer, [NotNull] ICollection <FileSystemPath> includees) { lock (_locker) { foreach (FileSystemPath includee in _includerToIncludees[includer]) { _includeeToIncluders.Remove(includee, includer); } _includerToIncludees.RemoveKey(includer); if (includees.Count > 0) { _includerToIncludees.AddRange(includer, includees); foreach (FileSystemPath includee in includees) { _includeeToIncluders.Add(includee, includer); } } } }
// Обновляет список вызванных методов для переменных со статусом DependsOnInvocation. // Удаляет список вызванных методов для переменных, лишившихся этого статуса. private OneToSetMap<IVariableDeclaration, InvokedExpressionData> GetInvokedExpressions(ICollection<ControlFlowElementData> previousElems, IDictionary<IVariableDeclaration, VariableDisposeStatus> statusDictionary, OneToSetMap<IVariableDeclaration, InvokedExpressionData> invokedExpressions) { var result = new OneToSetMap<IVariableDeclaration, InvokedExpressionData>(invokedExpressions); foreach (var status in statusDictionary) { if (status.Value != VariableDisposeStatus.DependsOnInvocation) { if (invokedExpressions.ContainsKey(status.Key)) result.RemoveKey(status.Key); continue; } foreach (var previousElem in previousElems) { if (previousElem == null || !previousElem.IsVisited()) continue; var previousStatus = previousElem[status.Key]; if (previousStatus == null) continue; if (previousStatus != VariableDisposeStatus.DependsOnInvocation) continue; if (previousElem.InvokedExpressions.ContainsKey(status.Key)) result.AddRange(status.Key, previousElem.InvokedExpressions[status.Key]); } } return result; }