Esempio n. 1
0
        /// <summary>
        /// Get a list of symbols declared in a given file
        /// </summary>
        /// <param name="file">
        /// A <see cref="System.String"/>: The file to check
        /// </param>
        /// <param name="desiredTypes">
        /// A <see cref="IEnumerable<System.String>"/>: The types of symbols to allow
        /// </param>
        List <Afrodite.Symbol> GetSymbolsForFile(string file, IEnumerable <string> desiredTypes)
        {
            List <Afrodite.Symbol> symbols = null;
            List <Afrodite.Symbol> classes = new List <Afrodite.Symbol> ();

            if (!DepsInstalled)
            {
                return(classes);
            }

            using (Afrodite.CodeDom parseTree = engine.TryAcquireCodeDom()) {
                if (null != parseTree)
                {
                    Afrodite.SourceFile sourceFile = parseTree.LookupSourceFile(file);
                    if (null != sourceFile)
                    {
                        symbols = sourceFile.Symbols;
                        if (null != symbols)
                        {
                            foreach (Afrodite.Symbol symbol in symbols)
                            {
                                foreach (string containerType in desiredTypes)
                                {
                                    if (containerType.Equals(symbol.MemberType, StringComparison.OrdinalIgnoreCase))
                                    {
                                        classes.Add(symbol);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        LoggingService.LogDebug("GetClassesForFile: Unable to lookup source file {0}", file);
                    }
                }
                else
                {
                    LoggingService.LogDebug("GetClassesForFile: Unable to acquire codedom");
                }
            }

            return(classes);
        }
Esempio n. 2
0
        }        // GetConstructorsForExpression

        /// <summary>
        /// Get types visible from a given source location
        /// </summary>
        internal void GetTypesVisibleFrom(string filename, int line, int column, ValaCompletionDataList results)
        {
            if (!DepsInstalled)
            {
                return;
            }

            // Add contents of parents
            ICollection <Afrodite.Symbol> containers = GetClassesForFile(filename);

            AddResults(containers, results);
            foreach (Afrodite.Symbol klass in containers)
            {
                // TODO: check source references once afrodite reliably captures the entire range
                for (Afrodite.Symbol parent = klass.Parent;
                     parent != null;
                     parent = parent.Parent)
                {
                    AddResults(parent.Children.FindAll(delegate(Afrodite.Symbol sym){
                        return(0 <= Array.IndexOf(containerTypes, sym.MemberType.ToLower()));
                    }), results);
                }
            }

            using (Afrodite.CodeDom parseTree = engine.TryAcquireCodeDom()) {
                if (null == parseTree)
                {
                    return;
                }

                AddResults(GetNamespacesForFile(filename), results);
                AddResults(GetClassesForFile(filename), results);
                Afrodite.SourceFile file = parseTree.LookupSourceFile(filename);
                if (null != file)
                {
                    Afrodite.Symbol parent;
                    foreach (Afrodite.DataType directive in file.UsingDirectives)
                    {
                        if (directive.Symbol == null)
                        {
                            continue;
                        }
                        Afrodite.Symbol ns = parseTree.Lookup(directive.Symbol.FullyQualifiedName, out parent);
                        if (null != ns)
                        {
                            containers = new List <Afrodite.Symbol> ();
                            AddResults(new Afrodite.Symbol[] { ns }, results);
                            foreach (Afrodite.Symbol child in ns.Children)
                            {
                                foreach (string containerType in containerTypes)
                                {
                                    if (containerType.Equals(child.MemberType, StringComparison.OrdinalIgnoreCase))
                                    {
                                        containers.Add(child);
                                    }
                                }
                            }
                            AddResults(containers, results);
                        }
                    }
                }
            }
        }        // GetTypesVisibleFrom