예제 #1
0
        /// <summary>
        /// Get the type of a given expression
        /// </summary>
        public string GetExpressionType(string symbol, string filename, int line, int column)
        {
            if (!DepsInstalled)
            {
                return(symbol);
            }

            using (Afrodite.CodeDom parseTree = engine.TryAcquireCodeDom()) {
                if (null != parseTree)
                {
                    LoggingService.LogDebug("GetExpressionType: Looking up symbol at {0}:{1}:{2}", filename, line, column);
                    Afrodite.Symbol sym = parseTree.LookupSymbolAt(filename, line, column);
                    if (null != sym)
                    {
                        LoggingService.LogDebug("Got {0}", sym.SymbolType.TypeName);
                        return(sym.SymbolType.TypeName);
                    }
                }
                else
                {
                    LoggingService.LogDebug("GetExpressionType: Unable to acquire codedom");
                }
            }

            return(symbol);
        }        // GetExpressionType
예제 #2
0
        }        // GetExpressionType

        /// <summary>
        /// Get overloads for a method
        /// </summary>
        internal List <Afrodite.Symbol> GetOverloads(string name, string filename, int line, int column)
        {
            List <Afrodite.Symbol> overloads = new List <Afrodite.Symbol> ();

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

            using (Afrodite.CodeDom parseTree = engine.TryAcquireCodeDom()) {
                if (null != parseTree)
                {
                    Afrodite.Symbol symbol = parseTree.GetSymbolForNameAndPath(name, filename, line, column);
                    overloads = new List <Afrodite.Symbol> ()
                    {
                        symbol
                    };
                }
                else
                {
                    LoggingService.LogDebug("GetOverloads: Unable to acquire codedom");
                }
            }

            return(overloads);
        }        // GetOverloads
예제 #3
0
        }        // AddPackage

        /// <summary>
        /// Gets the completion list for a given symbol at a given location
        /// </summary>
        internal List <Afrodite.Symbol> Complete(string symbol, string filename, int line, int column, ValaCompletionDataList results)
        {
            List <Afrodite.Symbol> nodes = new List <Afrodite.Symbol> ();

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


            using (Afrodite.CodeDom parseTree = engine.TryAcquireCodeDom()) {
                if (null != parseTree)
                {
                    LoggingService.LogDebug("Complete: Looking up symbol at {0}:{1}:{2}", filename, line, column);
                    Afrodite.Symbol sym = parseTree.GetSymbolForNameAndPath(symbol, filename, line, column);
                    LoggingService.LogDebug("Complete: Got {0}", (null == sym)? "null": sym.Name);
                    if (null != sym)
                    {
                        nodes = sym.Children;
                        AddResults(nodes, results);
                    }
                }
                else
                {
                    LoggingService.LogDebug("Complete: Unable to acquire codedom");
                }
            }

            return(nodes);
        }        // Complete
예제 #4
0
        /// <summary>
        /// Gets the completion list for a given type name in a given file
        /// </summary>
        internal List <Afrodite.Symbol> CompleteType(string typename, string filename, int linenum, int column, ValaCompletionDataList results)
        {
            List <Afrodite.Symbol> nodes = new List <Afrodite.Symbol> ();

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

            using (Afrodite.CodeDom parseTree = engine.TryAcquireCodeDom()) {
                if (null != parseTree)
                {
                    Afrodite.Symbol symbol = parseTree.GetSymbolForNameAndPath(typename, filename, linenum, column);
                    if (null == symbol)
                    {
                        LoggingService.LogDebug("CompleteType: Unable to lookup {0} in {1} at {2}:{3}", typename, filename, linenum, column);
                    }
                    else
                    {
                        nodes = symbol.Children;
                    }
                }
                else
                {
                    LoggingService.LogDebug("CompleteType: Unable to acquire codedom");
                }
            }

            return(nodes);
        }
예제 #5
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);
        }
예제 #6
0
        }        // Complete

        internal Afrodite.Symbol GetFunction(string name, string filename, int line, int column)
        {
            if (!DepsInstalled)
            {
                return(null);
            }

            using (Afrodite.CodeDom parseTree = engine.TryAcquireCodeDom()) {
                if (null != parseTree)
                {
                    LoggingService.LogDebug("GetFunction: Looking up symbol at {0}:{1}:{2}", filename, line, column);
                    Afrodite.Symbol symbol = parseTree.GetSymbolForNameAndPath(name, filename, line, column);
                    LoggingService.LogDebug("GetFunction: Got {0}", (null == symbol)? "null": symbol.Name);
                    return(symbol);
                }
                else
                {
                    LoggingService.LogDebug("GetFunction: Unable to acquire codedom");
                }
            }

            return(null);
        }
예제 #7
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
예제 #8
0
 /// <summary>
 /// Release the given CodeDOM (required for continued parsing)
 /// </summary>
 public void ReleaseCodeDom(CodeDom codeDom)
 {
     // Obsolete
 }
예제 #9
0
 public void Dump(CodeDom codeDom, string filterSymbol)
 {
     afrodite_ast_dumper_dump(instance, codeDom.Instance, filterSymbol);
 }