Exemple #1
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.SymbolType.ToLower()));
                    }), results);
                }
            }

            using (Afrodite.Ast parseTree = engine.TryAcquireAst()) {
                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.Symbol directive in file.UsingDirectives)
                    {
                        Afrodite.Symbol ns = parseTree.Lookup(directive.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.SymbolType, StringComparison.OrdinalIgnoreCase))
                                    {
                                        containers.Add(child);
                                    }
                                }
                            }
                            AddResults(containers, results);
                        }
                    }
                }
            }
        }        // GetTypesVisibleFrom
Exemple #2
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);
        }