Exemplo n.º 1
0
        public ArrayList GetCompletionItems(string subNamespace)
        {
            ArrayList items = projectContent.GetNamespaceContents(subNamespace);

            if (String.IsNullOrEmpty(subNamespace))
            {
                AddStandardPythonModules(items);
            }
            return(items);
        }
Exemplo n.º 2
0
        public static void AddUsing(ArrayList result, IUsing u, IProjectContent projectContent)
        {
            if (u == null)
            {
                return;
            }
            bool importNamespaces = projectContent.Language.ImportNamespaces;
            bool importClasses    = projectContent.Language.CanImportClasses;

            foreach (string name in u.Usings)
            {
                if (importClasses)
                {
                    IClass c = projectContent.GetClass(name, 0);
                    if (c != null)
                    {
                        ArrayList   members = new ArrayList();
                        IReturnType t       = c.DefaultReturnType;
                        members.AddRange(t.GetMethods());
                        members.AddRange(t.GetFields());
                        members.AddRange(t.GetEvents());
                        members.AddRange(t.GetProperties());
                        foreach (IMember m in members)
                        {
                            if (m.IsStatic && m.IsPublic)
                            {
                                result.Add(m);
                            }
                        }
                        continue;
                    }
                }
                if (importNamespaces)
                {
                    string newName = null;
                    if (projectContent.DefaultImports != null)
                    {
                        newName = projectContent.DefaultImports.SearchNamespace(name);
                    }
                    projectContent.AddNamespaceContents(result, newName ?? name, projectContent.Language, true);
                }
                else
                {
                    foreach (object o in projectContent.GetNamespaceContents(name))
                    {
                        if (!(o is string))
                        {
                            result.Add(o);
                        }
                    }
                }
            }
            if (u.HasAliases)
            {
                foreach (string alias in u.Aliases.Keys)
                {
                    result.Add(alias);
                }
            }
        }
Exemplo n.º 3
0
 public static ArrayList GetNamespaceMembers(IProjectContent pc, string xmlNamespace)
 {
     if (pc == null)
     {
         throw new ArgumentNullException("pc");
     }
     if (xmlNamespace == null)
     {
         return(null);
     }
     if (xmlNamespace.StartsWith("clr-namespace:"))
     {
         return(pc.GetNamespaceContents(GetNamespaceNameFromClrNamespace(xmlNamespace)));
     }
     else
     {
         ArrayList list = new ArrayList();
         AddNamespaceMembersInAssembly(pc, xmlNamespace, list);
         foreach (IProjectContent p in pc.ReferencedContents)
         {
             AddNamespaceMembersInAssembly(p, xmlNamespace, list);
         }
         return(list);
     }
 }
Exemplo n.º 4
0
        public static IEnumerable <IClass> GetNamespaceMembers(IProjectContent pc, string xmlNamespace)
        {
            if (pc == null)
            {
                throw new ArgumentNullException("pc");
            }

            if (!string.IsNullOrEmpty(xmlNamespace))
            {
                if (xmlNamespace.StartsWith("clr-namespace:", StringComparison.OrdinalIgnoreCase))
                {
                    return(pc.GetNamespaceContents(GetNamespaceNameFromClrNamespace(xmlNamespace)).OfType <IClass>());
                }
                else
                {
                    var list = new List <ICompletionEntry>();
                    AddNamespaceMembersInAssembly(pc, xmlNamespace, list);
                    foreach (IProjectContent p in pc.ThreadSafeGetReferencedContents())
                    {
                        AddNamespaceMembersInAssembly(p, xmlNamespace, list);
                    }
                    return(list.OfType <IClass>());
                }
            }

            return(Enumerable.Empty <IClass>());
        }
Exemplo n.º 5
0
        static void AddContentsFromCallingClass(List <ICompletionEntry> result, IProjectContent projectContent, IClass callingClass)
        {
            if (callingClass == null)
            {
                return;
            }
            // use HashSet so that Contains lookups are possible in O(1).
            HashSet <ICompletionEntry> existingResults = new HashSet <ICompletionEntry>(result);

            string[] namespaceParts = callingClass.Namespace.Split('.');
            for (int i = 1; i <= namespaceParts.Length; i++)
            {
                foreach (ICompletionEntry member in projectContent.GetNamespaceContents(string.Join(".", namespaceParts, 0, i)))
                {
                    if (!existingResults.Contains(member))
                    {
                        result.Add(member);
                    }
                }
            }
            IClass currentClass = callingClass;

            do
            {
                foreach (IClass innerClass in currentClass.GetCompoundClass().GetAccessibleTypes(currentClass))
                {
                    if (!existingResults.Contains(innerClass))
                    {
                        result.Add(innerClass);
                    }
                }
                currentClass = currentClass.DeclaringType;
            } while (currentClass != null);
        }
 void GetCodeElements()
 {
     foreach (ICompletionEntry entry in projectContent.GetNamespaceContents(namespaceName.QualifiedName))
     {
         AddCodeElement(entry);
     }
 }
Exemplo n.º 7
0
        public static void AddImportedNamespaceContents(ArrayList result, ICompilationUnit cu, IClass callingClass)
        {
            IProjectContent projectContent = cu.ProjectContent;

            projectContent.AddNamespaceContents(result, "", projectContent.Language, true);
            foreach (IUsing u in cu.Usings)
            {
                AddUsing(result, u, projectContent);
            }
            AddUsing(result, projectContent.DefaultImports, projectContent);

            if (callingClass != null)
            {
                string[] namespaceParts = callingClass.Namespace.Split('.');
                for (int i = 1; i <= namespaceParts.Length; i++)
                {
                    foreach (object member in projectContent.GetNamespaceContents(string.Join(".", namespaceParts, 0, i)))
                    {
                        if (!result.Contains(member))
                        {
                            result.Add(member);
                        }
                    }
                }
                IClass currentClass = callingClass;
                do
                {
                    foreach (IClass innerClass in currentClass.GetAccessibleTypes(currentClass))
                    {
                        if (!result.Contains(innerClass))
                        {
                            result.Add(innerClass);
                        }
                    }
                    currentClass = currentClass.DeclaringType;
                } while (currentClass != null);
            }
        }
Exemplo n.º 8
0
        ResolveResult ResolveMemberReferenceExpression(IReturnType type, FieldReferenceExpression fieldReferenceExpression)
        {
            IClass  c;
            IMember member;

            if (type is TypeVisitor.NamespaceReturnType)
            {
                string combinedName;
                if (type.FullyQualifiedName == "")
                {
                    combinedName = fieldReferenceExpression.FieldName;
                }
                else
                {
                    combinedName = type.FullyQualifiedName + "." + fieldReferenceExpression.FieldName;
                }
                if (projectContent.NamespaceExists(combinedName))
                {
                    return(new NamespaceResolveResult(callingClass, callingMember, combinedName));
                }
                c = GetClass(combinedName);
                if (c != null)
                {
                    return(new TypeResolveResult(callingClass, callingMember, c));
                }
                if (languageProperties.ImportModules)
                {
                    // go through the members of the modules
                    foreach (object o in projectContent.GetNamespaceContents(type.FullyQualifiedName))
                    {
                        member = o as IMember;
                        if (member != null && IsSameName(member.Name, fieldReferenceExpression.FieldName))
                        {
                            return(CreateMemberResolveResult(member));
                        }
                    }
                }
                return(null);
            }
            member = GetMember(type, fieldReferenceExpression.FieldName);
            if (member != null)
            {
                return(CreateMemberResolveResult(member));
            }
            c = type.GetUnderlyingClass();
            if (c != null)
            {
                foreach (IClass baseClass in c.ClassInheritanceTree)
                {
                    List <IClass> innerClasses = baseClass.InnerClasses;
                    if (innerClasses != null)
                    {
                        foreach (IClass innerClass in innerClasses)
                        {
                            if (IsSameName(innerClass.Name, fieldReferenceExpression.FieldName))
                            {
                                return(new TypeResolveResult(callingClass, callingMember, innerClass));
                            }
                        }
                    }
                }
            }
            return(ResolveMethod(type, fieldReferenceExpression.FieldName));
        }
		public static void AddUsing(List<ICompletionEntry> result, IUsing u, IProjectContent projectContent)
		{
			if (u == null) {
				return;
			}
			bool importNamespaces = projectContent.Language.ImportNamespaces;
			bool importClasses = projectContent.Language.CanImportClasses;
			foreach (string name in u.Usings) {
				if (importClasses) {
					IClass c = projectContent.GetClass(name, 0);
					if (c != null) {
						ArrayList members = new ArrayList();
						IReturnType t = c.DefaultReturnType;
						members.AddRange(t.GetMethods());
						members.AddRange(t.GetFields());
						members.AddRange(t.GetEvents());
						members.AddRange(t.GetProperties());
						foreach (IMember m in members) {
							if (m.IsStatic && m.IsPublic) {
								result.Add(m);
							}
						}
						continue;
					}
				}
				if (importNamespaces) {
					string newName = null;
					if (projectContent.DefaultImports != null) {
						newName = projectContent.DefaultImports.SearchNamespace(name);
					}
					projectContent.AddNamespaceContents(result, newName ?? name, projectContent.Language, true);
				} else {
					foreach (ICompletionEntry o in projectContent.GetNamespaceContents(name)) {
						if (!(o is NamespaceEntry))
							result.Add(o);
					}
				}
			}
			if (u.HasAliases) {
				foreach (string alias in u.Aliases.Keys) {
					result.Add(new AliasEntry(alias));
				}
			}
		}
		static void AddContentsFromCallingClass(List<ICompletionEntry> result, IProjectContent projectContent, IClass callingClass)
		{
			if (callingClass == null) {
				return;
			}
			// use HashSet so that Contains lookups are possible in O(1).
			HashSet<ICompletionEntry> existingResults = new HashSet<ICompletionEntry>(result);
			string[] namespaceParts = callingClass.Namespace.Split('.');
			for (int i = 1; i <= namespaceParts.Length; i++) {
				foreach (ICompletionEntry member in projectContent.GetNamespaceContents(string.Join(".", namespaceParts, 0, i))) {
					if (!existingResults.Contains(member))
						result.Add(member);
				}
			}
			IClass currentClass = callingClass;
			do {
				foreach (IClass innerClass in currentClass.GetCompoundClass().GetAccessibleTypes(currentClass)) {
					if (!existingResults.Contains(innerClass))
						result.Add(innerClass);
				}
				currentClass = currentClass.DeclaringType;
			} while (currentClass != null);
		}
Exemplo n.º 11
0
 public override ArrayList GetCompletionData(IProjectContent projectContent)
 {
     return(projectContent.GetNamespaceContents(name));
 }
Exemplo n.º 12
0
		public static IEnumerable<IClass> GetNamespaceMembers(IProjectContent pc, string xmlNamespace)
		{
			if (pc == null)
				throw new ArgumentNullException("pc");
			
			if (!string.IsNullOrEmpty(xmlNamespace)) {
				if (xmlNamespace.StartsWith("clr-namespace:", StringComparison.OrdinalIgnoreCase))
					return pc.GetNamespaceContents(GetNamespaceNameFromClrNamespace(xmlNamespace)).OfType<IClass>();
				else {
					var list = new List<ICompletionEntry>();
					AddNamespaceMembersInAssembly(pc, xmlNamespace, list);
					foreach (IProjectContent p in pc.ThreadSafeGetReferencedContents()) {
						AddNamespaceMembersInAssembly(p, xmlNamespace, list);
					}
					return list.OfType<IClass>();
				}
			}
			
			return Enumerable.Empty<IClass>();
		}
Exemplo n.º 13
0
 public override List <ICompletionEntry> GetCompletionData(IProjectContent projectContent)
 {
     return(projectContent.GetNamespaceContents(name));
 }
Exemplo n.º 14
0
        public override void OnMemberReferenceExpression(MemberReferenceExpression node)
        {
            ClearResult();
            node.Target.Accept(this);
            if (resolveResult is NamespaceResolveResult)
            {
                string namespaceName = (resolveResult as NamespaceResolveResult).Name;
                string combinedName;
                if (namespaceName.Length == 0)
                {
                    combinedName = node.Name;
                }
                else
                {
                    combinedName = namespaceName + "." + node.Name;
                }
                if (projectContent.NamespaceExists(combinedName))
                {
                    MakeNamespaceResult(combinedName);
                    return;
                }
                IClass c = projectContent.GetClass(combinedName, 0);
                if (c != null)
                {
                    MakeTypeResult(c);
                    return;
                }

                ClearResult();
                // go through the members of the modules in that namespace
                foreach (object o in projectContent.GetNamespaceContents(namespaceName))
                {
                    IMember member = o as IMember;
                    if (member != null && IsSameName(member.Name, node.Name))
                    {
                        if (member is IMethod)
                        {
                            MakeMethodResult(member.DeclaringType.DefaultReturnType, member.Name);
                        }
                        else
                        {
                            MakeResult(member);
                        }
                        break;
                    }
                }
            }
            else
            {
                if (resolveResult != null)
                {
                    if (resolveResult is TypeResolveResult)
                    {
                        IClass rClass = (resolveResult as TypeResolveResult).ResolvedClass;
                        if (rClass != null)
                        {
                            foreach (IClass baseClass in rClass.ClassInheritanceTree)
                            {
                                foreach (IClass innerClass in baseClass.InnerClasses)
                                {
                                    if (IsSameName(innerClass.Name, node.Name))
                                    {
                                        MakeTypeResult(innerClass);
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    ResolveMember(resolveResult.ResolvedType, node.Name);
                }
            }
        }
Exemplo n.º 15
0
		public override ArrayList GetCompletionData(IProjectContent projectContent)
		{
			return projectContent.GetNamespaceContents(name);
		}