Пример #1
0
        /*
         * A whole program identifier consists of an (optional) dll name and a doc comment identifier, separated by a '!'.
         *
         * assemblyname!M:Foo.Bar.GetBlam(System.String)
         */
        private ISet <D> FindDefinitionsMatchingWholeProgramQuery <D, E>(WholeProgramSearchQuery query)
            where D : IDefinition
            where E : IEqualityComparer <D>, new()
        {
            WholeProgramDefinitionSearchResult queryResult = SearchWholeProgram(query);

            // WholeProgramDefinitionSearchResult works over fields, methods, and types
            // but clients usually only care about one of these, so we do
            // some casting for them. This may be too clever for its own good.

            HashSet <D> foundDefinitions = new HashSet <D>(new E());

            foundDefinitions.UnionWith(from d in queryResult.FoundDefinitions select(D) d);

            return(foundDefinitions);
        }
Пример #2
0
        private WholeProgramDefinitionSearchResult SearchWholeProgram(WholeProgramSearchQuery query)
        {
            query.Validate();


            ISet <IAssembly> assembliesToSearch = new HashSet <IAssembly>();

            if (query.AssemblySpecifier != null)
            {
                string assemblyName = query.AssemblySpecifier;

                ISet <IAssembly> assemblies = FindAssembliesWithName(assemblyName);

                int foundAssemblyCount = assemblies.Count();

                if (foundAssemblyCount == 1)
                {
                    assembliesToSearch.Add(assemblies.First());
                }
                else if (foundAssemblyCount == 0)
                {
                    // Need to turn these exceptions into flags on the result so the client can deal with them appropriately

                    throw new Exception("Couldn't find assembly with name " + assemblyName);
                }
                else
                {
                    throw new Exception("Found " + foundAssemblyCount + " assemblies with name " + assemblyName + ". Unfortunately we don't support unification at this time.");
                }
            }
            else
            {
                assembliesToSearch.UnionWith(AllAssemblies());
            }

            ISet <IDefinition> foundDefinitions = new HashSet <IDefinition>(new DefinitionEqualityComparer());

            foreach (IAssembly assembly in allAssemblies)
            {
                if (query.PerformRegexpMatch)
                {
                    Regex regexp = new Regex(query.DefinitionSpecifier);

                    ISet <IDefinition> matchingDefinitions = FindDefinitionsMatchingRegularExpressionInAssembly(regexp, assembly);

                    foundDefinitions.UnionWith(matchingDefinitions);
                }
                else
                {
                    IDefinition foundDefinition = FindDefinitionWithIdentifierInAssembly(query.DefinitionSpecifier, assembly);

                    if (foundDefinition != null)
                    {
                        foundDefinitions.Add(foundDefinition);
                    }
                }
            }

            return(new WholeProgramDefinitionSearchResult()
            {
                AssemblySpecificationAmbiguous = false, FoundDefinitions = foundDefinitions
            });
        }
Пример #3
0
 public ISet <IFieldDefinition> FindFieldsMatchingWholeProgramQuery(WholeProgramSearchQuery query)
 {
     return(FindDefinitionsMatchingWholeProgramQuery <IFieldDefinition, FieldDefinitionEqualityComparer>(query));
 }