Beispiel #1
0
        ResolveResult GetResults(NCC.CompletionResult results, DefaultCompilationUnit cu, bool completeLocals)
        {
            try
            {
                if (results == null || results.Elems.Count == 0)
                {
                    return(null);
                }

                if (results.Elems [0] is NCC.Elem.Node)
                {
                    List <string>          alreadyAdded = new List <string> ();
                    List <string>          namespaces   = new List <string> ();
                    LanguageItemCollection lang         = new LanguageItemCollection();

                    foreach (NCC.Elem elem in results.Elems)
                    {
                        if (!(elem is NCC.Elem.Node))
                        {
                            continue;
                        }

                        NCC.Elem.Node enode = (NCC.Elem.Node)elem;
                        if (enode.node.Value is NCC.NamespaceTree.TypeInfoCache.NamespaceReference)
                        {
                            namespaces.Add(enode.Name);
                        }
                        else if (enode.node.Value is NCC.NamespaceTree.TypeInfoCache.Cached)
                        {
                            if (!alreadyAdded.Contains(enode.Name))
                            {
                                alreadyAdded.Add(enode.Name);
                                lang.Add(new Class(((NCC.NamespaceTree.TypeInfoCache.Cached)enode.node.Value).tycon, cu, false));
                            }
                        }
                    }
                    return(new ResolveResult(namespaces.ToArray(), lang));
                }
                else
                {
                    Class declaring = GetTheRealType(results.ObjectType, cu);

                    /*if (declaring.FullyQualifiedName == "System.Object")
                     * {
                     *  // Try with any other member
                     *  NCC.TypeInfo found = null;
                     *  foreach (NCC.OverloadPossibility ov in results.Overloads)
                     *  {
                     *      if (ov.Member.DeclaringType.FrameworkTypeName != "System.Object")
                     *      {
                     *          found = ov.Member.DeclaringType;
                     *          break;
                     *      }
                     *  }
                     *  if (found != null)
                     *      declaring = new Class (found, cu, false);
                     * }*/

                    LanguageItemCollection lang = new LanguageItemCollection();

                    foreach (NCC.Elem elem in results.Elems)
                    {
                        if (elem is NCC.Elem.Local)
                        {
                            if (!completeLocals)
                            {
                                continue;
                            }

                            NCC.Elem.Local lvalue = (NCC.Elem.Local)elem;

/*                        lang.Add (new NemerleBinding.Parser.SharpDevelopTree.Local
 *                          (new Class ("LOCALS", cu), lvalue.Value));
 */                     }
                        else if (elem is NCC.Elem.Overloads)
                        {
                            NCC.Elem.Overloads lvalue = (NCC.Elem.Overloads)elem;
                            foreach (NCC.OverloadPossibility ov in lvalue.Values)
                            {
                                AddMember(declaring, lang, ov.Member);
                            }
                        }
                        else if (elem is NCC.Elem.Overload)
                        {
                            NCC.Elem.Overload lvalue = (NCC.Elem.Overload)elem;
                            AddMember(declaring, lang, lvalue.Value.Member);
                        }
                        else if (elem is NCC.Elem.Member)
                        {
                            NCC.Elem.Member lvalue = (NCC.Elem.Member)elem;
                            AddMember(declaring, lang, lvalue.member);
                        }
                    }

                    return(new ResolveResult(declaring, lang));
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.GetType().FullName);
                System.Console.WriteLine(ex.Message);
                System.Console.WriteLine(ex.StackTrace);
                if (ex.InnerException != null)
                {
                    System.Console.WriteLine(ex.InnerException.GetType().FullName);
                    System.Console.WriteLine(ex.InnerException.Message);
                    System.Console.WriteLine(ex.InnerException.StackTrace);
                }
                return(null);
            }
        }
Beispiel #2
0
        public ResolveResult real_resolve(IParserContext parserContext, int caretLineNumber, int caretColumn, string fileName, string fileContent, bool completeLocals)
        {
            try
            {
                DefaultCompilationUnit comp = (DefaultCompilationUnit)parserContext.GetParseInformation(fileName).MostRecentCompilationUnit;
                Class the_class             = null;
                foreach (DefaultClass cl in comp.Classes)
                {
                    if (cl.BodyRegion.BeginLine <= caretLineNumber &&
                        cl.BodyRegion.EndLine >= caretLineNumber)
                    {
                        the_class = (Class)cl;
                    }
                    foreach (DefaultClass nc in cl.InnerClasses)
                    {
                        if (nc.BodyRegion.BeginLine <= caretLineNumber &&
                            nc.BodyRegion.EndLine >= caretLineNumber)
                        {
                            the_class = (Class)nc;
                        }
                    }
                    if (the_class != null)
                    {
                        break;
                    }
                }

                if (the_class == null)
                {
                    return(null);
                }
                else
                {
                    INemerleMethod the_method = null;
                    int            line = 0, column = 0, end_line = 0, end_column = 0;
                    foreach (DefaultMethod m in the_class.Methods)
                    {
                        if (m.BodyRegion.BeginLine <= caretLineNumber &&
                            m.BodyRegion.EndLine >= caretLineNumber &&
                            m.BodyRegion.BeginLine != the_class.BodyRegion.BeginLine)
                        {
                            the_method = (INemerleMethod)m;
                            line       = m.BodyRegion.BeginLine;
                            column     = m.BodyRegion.BeginColumn;
                            end_line   = m.BodyRegion.EndLine;
                            end_column = m.BodyRegion.EndColumn;
                            break;
                        }
                    }

                    if (the_method == null)
                    {
                        // Try with properties
                        foreach (Property p in the_class.Properties)
                        {
                            if (p.GetterRegion != null)
                            {
                                if (p.GetterRegion.BeginLine <= caretLineNumber &&
                                    p.GetterRegion.EndLine >= caretLineNumber)
                                {
                                    the_method = (INemerleMethod)p.Getter;
                                    line       = p.GetterRegion.BeginLine;
                                    column     = p.GetterRegion.BeginColumn;
                                    end_line   = p.BodyRegion.EndLine;
                                    end_column = p.BodyRegion.EndColumn;
                                    break;
                                }
                            }

                            if (p.SetterRegion != null)
                            {
                                if (p.SetterRegion.BeginLine <= caretLineNumber &&
                                    p.SetterRegion.EndLine >= caretLineNumber)
                                {
                                    the_method = (INemerleMethod)p.Setter;
                                    line       = p.SetterRegion.BeginLine;
                                    column     = p.SetterRegion.BeginColumn;
                                    end_line   = p.BodyRegion.EndLine;
                                    end_column = p.BodyRegion.EndColumn;
                                    break;
                                }
                            }
                        }

                        foreach (Indexer p in the_class.Indexer)
                        {
                            if (p.GetterRegion != null)
                            {
                                if (p.GetterRegion.BeginLine <= caretLineNumber &&
                                    p.GetterRegion.EndLine >= caretLineNumber)
                                {
                                    the_method = (INemerleMethod)p.Getter;
                                    line       = p.GetterRegion.BeginLine;
                                    column     = p.GetterRegion.BeginColumn;
                                    end_line   = p.BodyRegion.EndLine;
                                    end_column = p.BodyRegion.EndColumn;
                                    break;
                                }
                            }

                            if (p.SetterRegion != null)
                            {
                                if (p.SetterRegion.BeginLine <= caretLineNumber &&
                                    p.SetterRegion.EndLine >= caretLineNumber)
                                {
                                    the_method = (INemerleMethod)p.Setter;
                                    line       = p.SetterRegion.BeginLine;
                                    column     = p.SetterRegion.BeginColumn;
                                    end_line   = p.BodyRegion.EndLine;
                                    end_column = p.BodyRegion.EndColumn;
                                    break;
                                }
                            }
                        }
                    }

                    if (the_method == null)
                    {
                        return(null);
                    }
                    else
                    {
                        // Recover the text from the start of the method to cursor
                        string method_start = Crop(fileContent, line, column, caretLineNumber, caretColumn);
                        string method_end   = Crop(fileContent, caretLineNumber, caretColumn, end_line, end_column) + "}";
                        // System.Console.WriteLine (method_start + method_end);
                        NCC.CompletionResult infox = engine.RunCompletionEngine((NCC.MethodBuilder)the_method.Member,
                                                                                method_start + method_end, method_start.Length);

                        return(GetResults(infox, comp, completeLocals));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(null);
            }
        }