Ejemplo n.º 1
0
        public LanguageItemCollection CtrlSpace(IParserContext parserService, int caretLine, int caretColumn, string fileName)
        {
            LanguageItemCollection result = new LanguageItemCollection();

            this.parserService = parserService;
            IParseInformation parseInfo = parserService.GetParseInformation(fileName);

            JRefactory.Parser.AST.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as JRefactory.Parser.AST.CompilationUnit;
            if (fileCompilationUnit == null)
            {
                return(null);
            }
            lookupTableVisitor = new LookupTableVisitor();
            lookupTableVisitor.Visit(fileCompilationUnit, null);
            JavaVisitor cSharpVisitor = new JavaVisitor();

            cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
            if (cu != null)
            {
                callingClass = GetInnermostClass();
//				Console.WriteLine("CallingClass is " + callingClass == null ? "null" : callingClass.Name);
            }
            foreach (string name in lookupTableVisitor.variables.Keys)
            {
                ArrayList variables = (ArrayList)lookupTableVisitor.variables[name];
                if (variables != null && variables.Count > 0)
                {
                    foreach (LocalLookupVariable v in variables)
                    {
                        if (IsInside(new Point(caretColumn, caretLine), v.StartPos, v.EndPos))
                        {
                            result.Add(v);
                            break;
                        }
                    }
                }
            }
            if (callingClass != null)
            {
                result = ListMembers(result, callingClass);
            }
            string n = "";

            result.AddRange(parserService.GetNamespaceContents(n));
            foreach (IUsing u in cu.Usings)
            {
                if (u != null && (u.Region == null || u.Region.IsInside(caretLine, caretColumn)))
                {
                    foreach (string name in u.Usings)
                    {
                        result.AddRange(parserService.GetNamespaceContents(name));
                    }
                    foreach (string alias in u.Aliases.Keys)
                    {
                        result.Add(alias);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        private void AddMember(Class declaring, LanguageItemCollection lang, NCC.IMember member)
        {
            // Do not add property getters and setters, not events adders and removers,
            // nor overloaded operators, nor enum value__, not Nemerle internal methods
            if (member.Name.StartsWith("_N") || member.Name.StartsWith("get_") ||
                member.Name.StartsWith("set_") || member.Name == "value__" ||
                member.Name.StartsWith("op_") || member.Name.StartsWith("add_") ||
                member.Name.StartsWith("remove_"))
            {
                return;
            }

            try
            {
                if (member is NCC.IField)
                {
                    lang.Add(new NemerleBinding.Parser.SharpDevelopTree.Field(declaring, (NCC.IField)member));
                }
                else if (member is NCC.IMethod)
                {
                    lang.Add(new Method(declaring, (NCC.IMethod)member));
                }
                else if (member is NCC.IProperty)
                {
                    NCC.IProperty prop = (NCC.IProperty)member;
                    if (prop.IsIndexer)
                    {
                        lang.Add(new Indexer(declaring, prop));
                    }
                    else
                    {
                        lang.Add(new Property(declaring, prop));
                    }
                }
                else if (member is NCC.IEvent)
                {
                    lang.Add(new Event(declaring, (NCC.IEvent)member));
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
		public LanguageItemCollection CtrlSpace(IParserContext parserService, int caretLine, int caretColumn, string fileName)
		{
			LanguageItemCollection result = new LanguageItemCollection();
			this.parserService = parserService;
			IParseInformation parseInfo = parserService.GetParseInformation(fileName);
			JRefactory.Parser.AST.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as JRefactory.Parser.AST.CompilationUnit;
			if (fileCompilationUnit == null) {
				return null;
			}
			lookupTableVisitor = new LookupTableVisitor();
			lookupTableVisitor.Visit(fileCompilationUnit, null);
			JavaVisitor cSharpVisitor = new JavaVisitor ();
			cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
			if (cu != null) {
				callingClass = GetInnermostClass();
//				Console.WriteLine("CallingClass is " + callingClass == null ? "null" : callingClass.Name);
			}
			foreach (string name in lookupTableVisitor.variables.Keys) {
				ArrayList variables = (ArrayList)lookupTableVisitor.variables[name];
				if (variables != null && variables.Count > 0) {
					foreach (LocalLookupVariable v in variables) {
						if (IsInside(new Point(caretColumn, caretLine), v.StartPos, v.EndPos)) {
							result.Add(v);
							break;
						}
					}
				}
			}
			if (callingClass != null) {
				result = ListMembers(result, callingClass);
			}
			string n = "";
			result.AddRange(parserService.GetNamespaceContents(n));
			foreach (IUsing u in cu.Usings) {
				if (u != null && (u.Region == null || u.Region.IsInside(caretLine, caretColumn))) {
					foreach (string name in u.Usings) {
						result.AddRange(parserService.GetNamespaceContents(name));
					}
					foreach (string alias in u.Aliases.Keys) {
						result.Add(alias);
					}
				}
			}
			return result;
		}
Ejemplo n.º 5
0
 private void AddMember (Class declaring, LanguageItemCollection lang, NCC.IMember member)
 {
     // Do not add property getters and setters, not events adders and removers,
     // nor overloaded operators, nor enum value__, not Nemerle internal methods
     if (member.Name.StartsWith("_N") || member.Name.StartsWith("get_") ||
         member.Name.StartsWith("set_") || member.Name == "value__" ||
         member.Name.StartsWith("op_") || member.Name.StartsWith("add_") ||
         member.Name.StartsWith("remove_"))
         return;
           
     try
     {
         if (member is NCC.IField)
             lang.Add (new NemerleBinding.Parser.SharpDevelopTree.Field (declaring, (NCC.IField)member));
         else if (member is NCC.IMethod)
             lang.Add (new Method (declaring, (NCC.IMethod)member));
         else if (member is NCC.IProperty)
         {
             NCC.IProperty prop = (NCC.IProperty)member;
             if (prop.IsIndexer)
                 lang.Add (new Indexer (declaring, prop));
             else
                 lang.Add (new Property (declaring, prop));
         }
         else if (member is NCC.IEvent)
             lang.Add (new Event (declaring, (NCC.IEvent)member));
     }
     catch (Exception e)
     {
         System.Console.WriteLine (e.Message);
     }
 }
Ejemplo n.º 6
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;
            }
        }