Beispiel #1
0
        public ISet <IMethodReference> GetEntryPoints(WholeProgram wholeProgram)
        {
            ISet <string> entryPointAttributeIDs = new HashSet <string>(System.IO.File.ReadAllLines(pathToFile));

            ISet <IMethodReference> foundEntryPoints   = new HashSet <IMethodReference>();
            ISet <string>           foundEntryPointIDs = new HashSet <string>();

            foreach (IMethodDefinition methodDefinition in wholeProgram.AllDefinedMethods())
            {
                foreach (ICustomAttribute attribute in methodDefinition.Attributes)
                {
                    string attributeDefinitionID = GarbageCollectHelper.GetIDStringForReference(attribute.Type);

                    if (entryPointAttributeIDs.Contains(attributeDefinitionID))
                    {
                        foundEntryPoints.Add(methodDefinition);
                        foundEntryPointIDs.Add(attributeDefinitionID);
                    }
                }
            }

            // A poor attempt at slightly more humane error-reporting
            foreach (string desiredEntryPointID in entryPointAttributeIDs)
            {
                if (!foundEntryPointIDs.Contains(desiredEntryPointID))
                {
                    Console.WriteLine("Couldn't find any entry points with attribute {0}", desiredEntryPointID);
                    Environment.Exit(-1);
                }
            }


            return(foundEntryPoints);
        }
Beispiel #2
0
        private void WriteDefinitionIdentifiersToFile(IEnumerable <IDefinition> definitions, string path)
        {
            using (StreamWriter outfile = new StreamWriter(path)) {
                foreach (var definition in definitions)
                {
                    string definitionID = GarbageCollectHelper.GetIDStringForReference(definition);

                    outfile.WriteLine(definitionID);
                }
            }
        }
Beispiel #3
0
        public IMethodDefinition FindMethodWithIdentifierInAssembly(string docCommentMethodIdentifier, IAssembly assembly)
        {
            // We could be more efficient here, but for now we go with simplicity
            foreach (IMethodDefinition method in GetAllMethodsInAssembly(assembly))
            {
                if (GarbageCollectHelper.GetIDStringForReference(method) == docCommentMethodIdentifier)
                {
                    return(method);
                }
            }

            return(null);
        }
Beispiel #4
0
        public ISet <IDefinition> FindDefinitionsMatchingRegularExpressionInAssembly(Regex regex, IAssembly assembly)
        {
            // Maybe figure out how to factor out commons parts of this with FindDefinitionWithIdentifierInAssembly?

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

            string regexPattern = regex.ToString();

            // We could be more efficient here, but for now we go with simplicity

            if (regexPattern.StartsWith("M:"))
            {
                foreach (IMethodDefinition method in GetAllMethodsInAssembly(assembly))
                {
                    if (regex.IsMatch(GarbageCollectHelper.GetIDStringForReference(method)))
                    {
                        results.Add(method);
                    }
                }
            }
            else if (regexPattern.StartsWith("T:"))
            {
                foreach (ITypeDefinition type in assembly.GetAllTypes())
                {
                    if (regex.IsMatch(GarbageCollectHelper.GetIDStringForReference(type)))
                    {
                        results.Add(type);
                    }
                }
            }
            else if (regexPattern.StartsWith("F:"))
            {
                foreach (IFieldDefinition field in GetAllFieldsInAssembly(assembly))
                {
                    if (regex.IsMatch(GarbageCollectHelper.GetIDStringForReference(field)))
                    {
                        results.Add(field);
                    }
                }
            }
            else
            {
                throw new Exception("Un recognized doc comment definition identifier prefix in: " + regexPattern + " (expected T:, M:, or F:)");
            }


            return(results);
        }
Beispiel #5
0
        public IDefinition FindDefinitionWithIdentifierInAssembly(string docCommentIdentifier, IAssembly assembly)
        {
            // We could be more efficient here, but for now we go with simplicity

            if (docCommentIdentifier.StartsWith("M:"))
            {
                foreach (IMethodDefinition method in GetAllMethodsInAssembly(assembly))
                {
                    if (GarbageCollectHelper.GetIDStringForReference(method) == docCommentIdentifier)
                    {
                        return(method);
                    }
                }
            }
            else if (docCommentIdentifier.StartsWith("T:"))
            {
                foreach (ITypeDefinition type in assembly.GetAllTypes())
                {
                    if (GarbageCollectHelper.GetIDStringForReference(type) == docCommentIdentifier)
                    {
                        return(type);
                    }
                }
            }
            else if (docCommentIdentifier.StartsWith("F:"))
            {
                foreach (IFieldDefinition field in GetAllFieldsInAssembly(assembly))
                {
                    if (GarbageCollectHelper.GetIDStringForReference(field) == docCommentIdentifier)
                    {
                        return(field);
                    }
                }
            }
            else
            {
                throw new Exception("Un recognized doc comment definition identifier prefix in: " + docCommentIdentifier + " (expected T:, M:, or F:)");
            }


            return(null);
        }
Beispiel #6
0
        internal DocumentationCommentDefinitionIdStringMap(IEnumerable <IAssembly> assemblies)
        {
            foreach (IAssembly assembly in assemblies)
            {
                foreach (ITypeDefinition typeDefinition in assembly.GetAllTypes())
                {
                    AddIdStringForDefinition(GarbageCollectHelper.GetIDStringForReference(typeDefinition), typeDefinition);

                    foreach (IMethodDefinition methodDefinition in typeDefinition.Methods)
                    {
                        AddIdStringForDefinition(GarbageCollectHelper.GetIDStringForReference(methodDefinition), methodDefinition);
                    }

                    foreach (IFieldDefinition fieldDefinition in typeDefinition.Fields)
                    {
                        AddIdStringForDefinition(GarbageCollectHelper.GetIDStringForReference(fieldDefinition), fieldDefinition);
                    }
                }
            }
        }