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); } } }
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); }
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); }