예제 #1
0
 bool MatchesRequest(ref SearchTypeRequest request, ref SearchTypeResult result)
 {
     if (result.NamespaceResult != null)
     {
         return(request.TypeParameterCount == 0);
     }
     else
     {
         IReturnType rt = result.Result;
         if (rt == null)
         {
             return(false);
         }
         if (rt.TypeArgumentCount != request.TypeParameterCount)
         {
             return(false);
         }
         IClass c = rt.GetUnderlyingClass();
         if (c != null)
         {
             return(IsAccessibleClass(c));
         }
         else
         {
             return(true);
         }
     }
 }
예제 #2
0
        bool SearchTypeInUsing(IUsing u, SearchTypeRequest request, ref SearchTypeResult result)
        {
            foreach (IReturnType r in u.SearchType(request.Name, request.TypeParameterCount))
            {
                result = new SearchTypeResult(r, u);
                if (MatchesRequest(request, ref result))
                {
                    return(true);
                }
            }
            string nsResult = u.SearchNamespace(request.Name);

            if (nsResult != null)
            {
                result = new SearchTypeResult(nsResult, null);
                if (MatchesRequest(request, ref result))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #3
0
        public SearchTypeResult SearchType(SearchTypeRequest request)
        {
            string name = request.Name;

            if (string.IsNullOrEmpty(name))
            {
                return(SearchTypeResult.Empty);
            }

            // 'result' holds the fall-back result if no result with the right type parameter count is found.
            SearchTypeResult result = SearchTypeResult.Empty;

            if (name.IndexOf('.') < 0)
            {
                for (IClass outerClass = request.CurrentType; outerClass != null; outerClass = outerClass.DeclaringType)
                {
                    // Try inner classes (in full inheritance tree)
                    // Don't use loop with cur = cur.BaseType because of inheritance cycles
                    foreach (IClass baseClass in outerClass.ClassInheritanceTree)
                    {
                        if (baseClass.ClassType == ClassType.Class || baseClass.ClassType == ClassType.Struct || baseClass.ClassType == ClassType.Module)
                        {
                            foreach (IClass innerClass in baseClass.InnerClasses)
                            {
                                if (language.NameComparer.Equals(innerClass.Name, name))
                                {
                                    result = new SearchTypeResult(innerClass);
                                    if (MatchesRequest(ref request, ref result))
                                    {
                                        return(result);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            for (IUsingScope usingScope = request.CurrentUsingScope; usingScope != null; usingScope = usingScope.Parent)
            {
                string fullname;
                if (string.IsNullOrEmpty(usingScope.NamespaceName))
                {
                    // Try if name is already the full type name
                    fullname = name;
                }
                else
                {
                    fullname = usingScope.NamespaceName + "." + name;
                }
                IClass c = GetClass(fullname, request.TypeParameterCount);
                if (c != null)
                {
                    result = new SearchTypeResult(c);
                    if (MatchesRequest(ref request, ref result))
                    {
                        return(result);
                    }
                }
                if (NamespaceExists(fullname))
                {
                    result = new SearchTypeResult(fullname, null);
                    if (MatchesRequest(ref request, ref result))
                    {
                        return(result);
                    }
                }

                foreach (IUsing u in usingScope.Usings)
                {
                    foreach (IReturnType r in u.SearchType(name, request.TypeParameterCount))
                    {
                        result = new SearchTypeResult(r, u);
                        if (MatchesRequest(ref request, ref result))
                        {
                            return(result);
                        }
                    }
                    string nsResult = u.SearchNamespace(name);
                    if (nsResult != null)
                    {
                        result = new SearchTypeResult(nsResult, null);
                        if (MatchesRequest(ref request, ref result))
                        {
                            return(result);
                        }
                    }
                }
            }

            if (defaultImports != null)
            {
                foreach (IReturnType r in defaultImports.SearchType(name, request.TypeParameterCount))
                {
                    result = new SearchTypeResult(r, defaultImports);
                    if (MatchesRequest(ref request, ref result))
                    {
                        return(result);
                    }
                }
                string nsResult = defaultImports.SearchNamespace(name);
                if (nsResult != null)
                {
                    result = new SearchTypeResult(nsResult, null);
                    if (MatchesRequest(ref request, ref result))
                    {
                        return(result);
                    }
                }
            }
            return(result);
        }
예제 #4
0
		bool SearchTypeInUsing(IUsing u, SearchTypeRequest request, ref SearchTypeResult result)
		{
			foreach (IReturnType r in u.SearchType(request.Name, request.TypeParameterCount)) {
				result = new SearchTypeResult(r, u);
				if (MatchesRequest(request, ref result)) {
					return true;
				}
			}
			string nsResult = u.SearchNamespace(request.Name);
			if (nsResult != null) {
				result = new SearchTypeResult(nsResult, null);
				if (MatchesRequest(request, ref result)) {
					return true;
				}
			}
			return false;
		}
예제 #5
0
		public SearchTypeResult SearchType(SearchTypeRequest request)
		{
			string name = request.Name;
			if (string.IsNullOrEmpty(name)) {
				return SearchTypeResult.Empty;
			}
			
			// 'result' holds the fall-back result if no result with the right type parameter count is found.
			SearchTypeResult result = SearchTypeResult.Empty;
			
			if (name.IndexOf('.') < 0) {
				for (IClass outerClass = request.CurrentType; outerClass != null; outerClass = outerClass.DeclaringType) {
					// Try inner classes (in full inheritance tree)
					// Don't use loop with cur = cur.BaseType because of inheritance cycles
					foreach (IClass baseClass in outerClass.ClassInheritanceTree) {
						if (baseClass.ClassType == ClassType.Class || baseClass.ClassType == ClassType.Struct || baseClass.ClassType == ClassType.Module) {
							foreach (IClass innerClass in baseClass.InnerClasses) {
								if (language.NameComparer.Equals(innerClass.Name, name)) {
									result = new SearchTypeResult(innerClass);
									if (MatchesRequest(request, ref result)) {
										return result;
									}
								}
							}
						}
					}
				}
			}
			
			for (IUsingScope usingScope = request.CurrentUsingScope; usingScope != null; usingScope = usingScope.Parent) {
				string fullname;
				if (string.IsNullOrEmpty(usingScope.NamespaceName)) {
					// Try if name is already the full type name
					fullname = name;
				} else {
					fullname = usingScope.NamespaceName + "." + name;
				}
				IClass c = GetClass(fullname, request.TypeParameterCount);
				if (c != null) {
					result = new SearchTypeResult(c);
					if (MatchesRequest(request, ref result)) {
						return result;
					}
				}
				if (NamespaceExists(fullname)) {
					result = new SearchTypeResult(fullname, null);
					if (MatchesRequest(request, ref result)) {
						return result;
					}
				}
				
				// prefer aliases over imported types
				foreach (IUsing u in usingScope.Usings) {
					if (u.HasAliases) {
						if (SearchTypeInUsing(u, request, ref result))
							return result;
					}
				}
				foreach (IUsing u in usingScope.Usings) {
					if (!u.HasAliases) {
						if (SearchTypeInUsing(u, request, ref result))
							return result;
					}
				}
			}
			
			if (defaultImports != null) {
				if (SearchTypeInUsing(defaultImports, request, ref result))
					return result;
			}
			return result;
		}
예제 #6
0
		bool MatchesRequest(SearchTypeRequest request, ref SearchTypeResult result)
		{
			if (result.NamespaceResult != null)
				return request.TypeParameterCount == 0;
			else {
				IReturnType rt = result.Result;
				if (rt == null)
					return false;
				if (rt.TypeArgumentCount != request.TypeParameterCount)
					return false;
				IClass c = rt.GetUnderlyingClass();
				if (c != null)
					return IsAccessibleClass(c);
				else
					return true;
			}
		}
		public SearchTypeResult SearchType(SearchTypeRequest request)
		{
			string name = request.Name;
			if (string.IsNullOrEmpty(name)) {
				return SearchTypeResult.Empty;
			}
			
			// 'result' holds the fall-back result if no result with the right type parameter count is found.
			SearchTypeResult result = SearchTypeResult.Empty;
			
			if (name.IndexOf('.') < 0) {
				for (IClass outerClass = request.CurrentType; outerClass != null; outerClass = outerClass.DeclaringType) {
					// Try inner classes (in full inheritance tree)
					// Don't use loop with cur = cur.BaseType because of inheritance cycles
					foreach (IClass baseClass in outerClass.ClassInheritanceTree) {
						if (baseClass.ClassType == ClassType.Class) {
							foreach (IClass innerClass in baseClass.InnerClasses) {
								if (language.NameComparer.Equals(innerClass.Name, name)) {
									result = new SearchTypeResult(innerClass);
									if (MatchesRequest(ref request, ref result)) {
										return result;
									}
								}
							}
						}
					}
				}
			}

            var maxLoop = 50;           //DC: see details below (hack to try to prevent an infinit loop here);

			for (IUsingScope usingScope = request.CurrentUsingScope; usingScope != null; usingScope = usingScope.Parent) {
				string fullname;
				if (string.IsNullOrEmpty(usingScope.NamespaceName)) {
					// Try if name is already the full type name
					fullname = name;
				} else {
					fullname = usingScope.NamespaceName + "." + name;
				}
				IClass c = GetClass(fullname, request.TypeParameterCount);
				if (c != null) {
					result = new SearchTypeResult(c);
					if (MatchesRequest(ref request, ref result)) {
						return result;
					}
				}
				if (NamespaceExists(fullname)) {
					result = new SearchTypeResult(fullname, null);
					if (MatchesRequest(ref request, ref result)) {
						return result;
					}
				}
				
				foreach (IUsing u in usingScope.Usings) {
					foreach (IReturnType r in u.SearchType(name, request.TypeParameterCount)) {
						result = new SearchTypeResult(r, u);
						if (MatchesRequest(ref request, ref result)) {
							return result;
						}
					}
					string nsResult = u.SearchNamespace(name);
					if (nsResult != null) {
						result = new SearchTypeResult(nsResult, null);
						if (MatchesRequest(ref request, ref result)) {
							return result;
						}
					}
				}

                if (usingScope == usingScope.Parent)  //DC: 7/13/2012 - there seemed to be an infinit loop here on Method Stream creation
                {
                    if (maxLoop-- < 1)
                        break;
                }
                else
                { 
                }
			}
			
			if (defaultImports != null) {
				foreach (IReturnType r in defaultImports.SearchType(name, request.TypeParameterCount)) {
					result = new SearchTypeResult(r, defaultImports);
					if (MatchesRequest(ref request, ref result)) {
						return result;
					}
				}
				string nsResult = defaultImports.SearchNamespace(name);
				if (nsResult != null) {
					result = new SearchTypeResult(nsResult, null);
					if (MatchesRequest(ref request, ref result)) {
						return result;
					}
				}
			}
			return result;
		}
예제 #8
0
		public SearchTypeResult SearchType(SearchTypeRequest request)
		{
			throw new NotImplementedException();
		}
예제 #9
0
        public SearchTypeResult SearchType(SearchTypeRequest request)
        {
            string name = request.Name;

            if (name == null || name.Length == 0)
            {
                return(SearchTypeResult.Empty);
            }

            // Try if name is already the full type name
            IClass c = GetClass(name, request.TypeParameterCount);

            if (c != null)
            {
                return(new SearchTypeResult(c.DefaultReturnType));
            }
            // fallback-class if the one with the right type parameter count is not found.
            SearchTypeResult fallbackResult = SearchTypeResult.Empty;

            if (request.CurrentType != null)
            {
                // Try parent namespaces of the current class
                string        fullname     = request.CurrentType.FullyQualifiedName;
                string[]      namespaces   = fullname.Split('.');
                StringBuilder curnamespace = new StringBuilder();
                for (int i = 0; i < namespaces.Length; ++i)
                {
                    curnamespace.Append(namespaces[i]);
                    curnamespace.Append('.');

                    curnamespace.Append(name);
                    c = GetClass(curnamespace.ToString(), request.TypeParameterCount);
                    if (c != null)
                    {
                        if (c.TypeParameters.Count == request.TypeParameterCount)
                        {
                            return(new SearchTypeResult(c.DefaultReturnType));
                        }
                        else
                        {
                            fallbackResult = new SearchTypeResult(c.DefaultReturnType);
                        }
                    }
                    // remove class name again to try next namespace
                    curnamespace.Length -= name.Length;
                }

                if (name.IndexOf('.') < 0)
                {
                    // Try inner classes (in full inheritance tree)
                    // Don't use loop with cur = cur.BaseType because of inheritance cycles
                    foreach (IClass baseClass in request.CurrentType.ClassInheritanceTree)
                    {
                        if (baseClass.ClassType == ClassType.Class)
                        {
                            foreach (IClass innerClass in baseClass.InnerClasses)
                            {
                                if (language.NameComparer.Equals(innerClass.Name, name))
                                {
                                    return(new SearchTypeResult(innerClass.DefaultReturnType));
                                }
                            }
                        }
                    }
                }
            }
            if (request.CurrentCompilationUnit != null)
            {
                // Combine name with usings
                foreach (IUsing u in request.CurrentCompilationUnit.Usings)
                {
                    if (u != null)
                    {
                        foreach (IReturnType r in u.SearchType(name, request.TypeParameterCount))
                        {
                            if (r.TypeParameterCount == request.TypeParameterCount)
                            {
                                return(new SearchTypeResult(r, u));
                            }
                            else
                            {
                                fallbackResult = new SearchTypeResult(r, u);
                            }
                        }
                    }
                }
            }
            if (defaultImports != null)
            {
                foreach (IReturnType r in defaultImports.SearchType(name, request.TypeParameterCount))
                {
                    if (r.TypeParameterCount == request.TypeParameterCount)
                    {
                        return(new SearchTypeResult(r, defaultImports));
                    }
                    else
                    {
                        fallbackResult = new SearchTypeResult(r, defaultImports);
                    }
                }
            }
            return(fallbackResult);
        }
예제 #10
0
		public SearchTypeResult SearchType(SearchTypeRequest request)
		{
			searchTypeCalled = true;
			searchTypeRequest = request;
			return searchTypeResult;
		}
		public SearchTypeResult SearchType(SearchTypeRequest request)
		{
			string name = request.Name;
			if (name == null || name.Length == 0) {
				return SearchTypeResult.Empty;
			}
			
			// Try if name is already the full type name
			IClass c = GetClass(name, request.TypeParameterCount);
			if (c != null) {
				return new SearchTypeResult(c.DefaultReturnType);
			}
			// fallback-class if the one with the right type parameter count is not found.
			SearchTypeResult fallbackResult = SearchTypeResult.Empty;
			if (request.CurrentType != null) {
				// Try parent namespaces of the current class
				string fullname = request.CurrentType.FullyQualifiedName;
				string[] namespaces = fullname.Split('.');
				StringBuilder curnamespace = new StringBuilder();
				for (int i = 0; i < namespaces.Length; ++i) {
					curnamespace.Append(namespaces[i]);
					curnamespace.Append('.');
					
					curnamespace.Append(name);
					c = GetClass(curnamespace.ToString(), request.TypeParameterCount);
					if (c != null) {
						if (c.TypeParameters.Count == request.TypeParameterCount)
							return new SearchTypeResult(c.DefaultReturnType);
						else
							fallbackResult = new SearchTypeResult(c.DefaultReturnType);
					}
					// remove class name again to try next namespace
					curnamespace.Length -= name.Length;
				}
				
				if (name.IndexOf('.') < 0) {
					// Try inner classes (in full inheritance tree)
					// Don't use loop with cur = cur.BaseType because of inheritance cycles
					foreach (IClass baseClass in request.CurrentType.ClassInheritanceTree) {
						if (baseClass.ClassType == ClassType.Class) {
							foreach (IClass innerClass in baseClass.InnerClasses) {
								if (language.NameComparer.Equals(innerClass.Name, name))
									return new SearchTypeResult(innerClass.DefaultReturnType);
							}
						}
					}
				}
			}
			if (request.CurrentCompilationUnit != null) {
				// Combine name with usings
				foreach (IUsing u in request.CurrentCompilationUnit.Usings) {
					if (u != null) {
						foreach (IReturnType r in u.SearchType(name, request.TypeParameterCount)) {
							if (r.TypeParameterCount == request.TypeParameterCount) {
								return new SearchTypeResult(r, u);
							} else {
								fallbackResult = new SearchTypeResult(r, u);
							}
						}
					}
				}
			}
			if (defaultImports != null) {
				foreach (IReturnType r in defaultImports.SearchType(name, request.TypeParameterCount)) {
					if (r.TypeParameterCount == request.TypeParameterCount) {
						return new SearchTypeResult(r, defaultImports);
					} else {
						fallbackResult = new SearchTypeResult(r, defaultImports);
					}
				}
			}
			return fallbackResult;
		}