/// <summary> /// Handles an assembly directive. /// </summary> /// <param name="directive">The directive containing a potential assembly reference.</param> private void HandleAssemblyDirective([NotNull] IT4Directive directive) { string assemblyNameOrFile = directive.GetAttributeValue(_directiveInfoManager.Assembly.NameAttribute.Name); if (assemblyNameOrFile == null || (assemblyNameOrFile = assemblyNameOrFile.Trim()).Length == 0) { // Handle <#@ assembly name="" completion="someassembly" #>, which is a ForTea-specific way // to get completion for an implicit assembly (for example, added by a custom directive). assemblyNameOrFile = directive.GetAttributeValue("completion"); if (assemblyNameOrFile == null || (assemblyNameOrFile = assemblyNameOrFile.Trim()).Length == 0) { return; } } VsBuildMacroHelper.GetMacros(assemblyNameOrFile, _macros); _referencedAssemblies.Add(assemblyNameOrFile); }
/// <summary>Handles an include directive.</summary> /// <param name="directive">The directive containing a potential macro.</param> private void HandleIncludeDirective([NotNull] IT4Directive directive) => VsBuildMacroHelper.GetMacros(directive.GetAttributeValue(_directiveInfoManager.Include.FileAttribute.Name), _macros);
/// <summary> /// Called when the associated data file changed: added/removed assemblies or includes. /// </summary> /// <param name="dataDiff">The difference between the old and new data.</param> private void OnDataFileChanged([NotNull] T4FileDataDiff dataDiff) { _shellLocks.AssertWriteAccessAllowed(); bool hasFileChanges = ResolveMacros(dataDiff.AddedMacros); bool hasChanges = hasFileChanges; IDictionary <string, string> resolvedMacros = GetResolvedMacros(); // removes the assembly references from the old assembly directives foreach (string removedAssembly in dataDiff.RemovedAssemblies) { string assembly = VsBuildMacroHelper.ResolveMacros(removedAssembly, resolvedMacros); IAssemblyCookie cookie; if (!_assemblyReferences.TryGetValue(assembly, out cookie)) { continue; } _assemblyReferences.Remove(assembly); hasChanges = true; cookie.Dispose(); } // adds assembly references from the new assembly directives foreach (string addedAssembly in dataDiff.AddedAssemblies) { string assembly = VsBuildMacroHelper.ResolveMacros(addedAssembly, resolvedMacros); if (_assemblyReferences.ContainsKey(assembly)) { continue; } IAssemblyCookie cookie = TryAddReference(assembly); if (cookie != null) { hasChanges = true; } } if (!hasChanges) { return; } // tells the world the module has changed var changeBuilder = new PsiModuleChangeBuilder(); changeBuilder.AddModuleChange(this, ModifiedChangeType); if (hasFileChanges) { GetPsiServices().MarkAsDirty(_sourceFile); } _shellLocks.ExecuteOrQueue("T4PsiModuleChange", () => _changeManager.ExecuteAfterChange( () => _shellLocks.ExecuteWithWriteLock( () => _changeManager.OnProviderChanged(this, changeBuilder.Result, SimpleTaskExecutor.Instance)) ) ); }