Exemplo n.º 1
0
        /// <summary>
        /// Collects the handlers that implement installation against the assembly attributes, see <see cref="InstallAttributesAttribute"/>.
        /// Do not call, use <see cref="MapAttributeToInstallers"/>.
        /// </summary>
        protected void CollectAttributeInstallers()
        {
            // Init only once
            if (myMapAttributeToInstallers != null)
            {
                return;
            }
            myMapAttributeToInstallers = new OneToSetMap <Type, IInstallAttributes>();

            // Cache the installer objects to singleton them in case they handle multiple attrs
            myMapInstallerTypeToInstance = new Dictionary <Type, IInstallAttributes>();

            foreach (Assembly assembly in Assemblies)            // All the assemblies
            {
                try
                {
                    foreach (Type typeInstaller in assembly.GetTypes())                    // All the types
                    {
                        // Does the current type declare it installs any attrs?
                        object[] attributes = typeInstaller.GetCustomAttributes(typeof(InstallAttributesAttribute), false);
                        if (attributes.Length == 0)
                        {
                            continue;
                        }

                        // Create the installer instance, if not created yet
                        IInstallAttributes installer;
                        if (!myMapInstallerTypeToInstance.TryGetValue(typeInstaller, out installer))
                        {
                            object objectInstaller = Activator.CreateInstance(typeInstaller);
                            installer = objectInstaller as IInstallAttributes;
                            if (installer == null)
                            {
                                throw new InvalidOperationException(string.Format("The attribute-installer object of type “{0}” does not implement the required “{1}” interface.", typeInstaller.FullName, typeof(IInstallAttributes).FullName));
                            }
                            myMapInstallerTypeToInstance.Add(typeInstaller, installer);
                        }

                        // Add attributes
                        foreach (InstallAttributesAttribute attribute in attributes)
                        {
                            if (attribute.AttributeToInstall != null)                            // A single-time installer
                            {
                                // Duplicate?
                                if ((myMapAttributeToInstallers.ContainsKey(attribute.AttributeToInstall)) && (myMapAttributeToInstallers[attribute.AttributeToInstall].Contains(installer)))
                                {
                                    throw new InvalidOperationException(string.Format("The installer class “{0}” registers for the “{1}” attribute twice.", typeInstaller.FullName, attribute.AttributeToInstall.FullName));
                                }
                                myMapAttributeToInstallers.Add(attribute.AttributeToInstall, installer);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException(string.Format("Failed to collect attribute-installers from the “{0}” assembly. {1}", assembly.FullName, ex.Message), ex);
                }
            }
        }
 // Обновляет список вызванных методов для переменных со статусом 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;
 }
Exemplo n.º 3
0
 public bool UpToDate(IPsiSourceFile sourceFile)
 {
     myShellLocks.AssertReadAccessAllowed();
     if (!Accepts(sourceFile))
     {
         return(true);
     }
     return(!myDirtyFiles.Contains(sourceFile) && (myFilesWithoutAnnotations.Contains(sourceFile) || mySourceFileToNodes.ContainsKey(sourceFile)));
 }