示例#1
0
        public static IReturnType CreateReturnType(TypeReference reference, IClass callingClass,
                                                   IMember callingMember, int caretLine, int caretColumn,
                                                   IProjectContent projectContent,
                                                   bool useLazyReturnType)
        {
            if (reference == null)
            {
                return(null);
            }
            if (reference.IsNull)
            {
                return(null);
            }
            if (reference is InnerClassTypeReference)
            {
                reference = ((InnerClassTypeReference)reference).CombineToNormalTypeReference();
            }
            LanguageProperties languageProperties = projectContent.Language;
            IReturnType        t = null;

            if (callingClass != null && !reference.IsGlobal)
            {
                foreach (ITypeParameter tp in callingClass.TypeParameters)
                {
                    if (languageProperties.NameComparer.Equals(tp.Name, reference.SystemType))
                    {
                        t = new GenericReturnType(tp);
                        break;
                    }
                }
                if (t == null && callingMember is IMethod && (callingMember as IMethod).TypeParameters != null)
                {
                    foreach (ITypeParameter tp in (callingMember as IMethod).TypeParameters)
                    {
                        if (languageProperties.NameComparer.Equals(tp.Name, reference.SystemType))
                        {
                            t = new GenericReturnType(tp);
                            break;
                        }
                    }
                }
            }
            if (t == null)
            {
                if (reference.Type != reference.SystemType)
                {
                    // keyword-type like void, int, string etc.
                    IClass c = projectContent.GetClass(reference.SystemType);
                    if (c != null)
                    {
                        t = c.DefaultReturnType;
                    }
                    else
                    {
                        t = new GetClassReturnType(projectContent, reference.SystemType, 0);
                    }
                }
                else
                {
                    int typeParameterCount = reference.GenericTypes.Count;
                    if (useLazyReturnType)
                    {
                        if (reference.IsGlobal)
                        {
                            t = new GetClassReturnType(projectContent, reference.SystemType, typeParameterCount);
                        }
                        else if (callingClass != null)
                        {
                            t = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn, reference.SystemType, typeParameterCount);
                        }
                    }
                    else
                    {
                        IClass c;
                        if (reference.IsGlobal)
                        {
                            c = projectContent.GetClass(reference.SystemType, typeParameterCount);
                            t = (c != null) ? c.DefaultReturnType : null;
                        }
                        else if (callingClass != null)
                        {
                            t = projectContent.SearchType(new SearchTypeRequest(reference.SystemType, typeParameterCount, callingClass, caretLine, caretColumn)).Result;
                        }
                        if (t == null)
                        {
                            if (reference.GenericTypes.Count == 0 && !reference.IsArrayType)
                            {
                                // reference to namespace is possible
                                if (reference.IsGlobal)
                                {
                                    if (projectContent.NamespaceExists(reference.Type))
                                    {
                                        return(new NamespaceReturnType(reference.Type));
                                    }
                                }
                                else
                                {
                                    string name = projectContent.SearchNamespace(reference.Type, callingClass, (callingClass == null) ? null : callingClass.CompilationUnit, caretLine, caretColumn);
                                    if (name != null)
                                    {
                                        return(new NamespaceReturnType(name));
                                    }
                                }
                            }
                            return(null);
                        }
                    }
                }
            }
            if (reference.GenericTypes.Count > 0)
            {
                List <IReturnType> para = new List <IReturnType>(reference.GenericTypes.Count);
                for (int i = 0; i < reference.GenericTypes.Count; ++i)
                {
                    para.Add(CreateReturnType(reference.GenericTypes[i], callingClass, callingMember, caretLine, caretColumn, projectContent, useLazyReturnType));
                }
                t = new ConstructedReturnType(t, para);
            }
            return(WrapArray(projectContent, t, reference));
        }
示例#2
0
 /// <remarks>
 /// use the usings to find the correct name of a namespace
 /// </remarks>
 public string SearchNamespace(string name)
 {
     return(projectContent.SearchNamespace(name, callingClass, cu, caretLine, caretColumn));
 }
示例#3
0
		public static IReturnType CreateReturnType(TypeReference reference, IClass callingClass,
		                                           IMember callingMember, int caretLine, int caretColumn,
		                                           IProjectContent projectContent,
		                                           bool useLazyReturnType)
		{
			if (reference == null) return null;
			if (reference.IsNull) return null;
			if (reference is InnerClassTypeReference) {
				reference = ((InnerClassTypeReference)reference).CombineToNormalTypeReference();
			}
			LanguageProperties languageProperties = projectContent.Language;
			IReturnType t = null;
			if (callingClass != null && !reference.IsGlobal) {
				foreach (ITypeParameter tp in callingClass.TypeParameters) {
					if (languageProperties.NameComparer.Equals(tp.Name, reference.SystemType)) {
						t = new GenericReturnType(tp);
						break;
					}
				}
				if (t == null && callingMember is IMethod && (callingMember as IMethod).TypeParameters != null) {
					foreach (ITypeParameter tp in (callingMember as IMethod).TypeParameters) {
						if (languageProperties.NameComparer.Equals(tp.Name, reference.SystemType)) {
							t = new GenericReturnType(tp);
							break;
						}
					}
				}
			}
			if (t == null) {
				if (reference.Type != reference.SystemType) {
					// keyword-type like void, int, string etc.
					IClass c = projectContent.GetClass(reference.SystemType);
					if (c != null)
						t = c.DefaultReturnType;
					else
						t = new GetClassReturnType(projectContent, reference.SystemType, 0);
				} else {
					int typeParameterCount = reference.GenericTypes.Count;
					if (useLazyReturnType) {
						if (reference.IsGlobal)
							t = new GetClassReturnType(projectContent, reference.SystemType, typeParameterCount);
						else if (callingClass != null)
							t = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn, reference.SystemType, typeParameterCount);
					} else {
						IClass c;
						if (reference.IsGlobal) {
							c = projectContent.GetClass(reference.SystemType, typeParameterCount);
							t = (c != null) ? c.DefaultReturnType : null;
						} else if (callingClass != null) {
							t = projectContent.SearchType(new SearchTypeRequest(reference.SystemType, typeParameterCount, callingClass, caretLine, caretColumn)).Result;
						}
						if (t == null) {
							if (reference.GenericTypes.Count == 0 && !reference.IsArrayType) {
								// reference to namespace is possible
								if (reference.IsGlobal) {
									if (projectContent.NamespaceExists(reference.Type))
										return new NamespaceReturnType(reference.Type);
								} else {
									string name = projectContent.SearchNamespace(reference.Type, callingClass, (callingClass == null) ? null : callingClass.CompilationUnit, caretLine, caretColumn);
									if (name != null)
										return new NamespaceReturnType(name);
								}
							}
							return null;
						}
					}
				}
			}
			if (reference.GenericTypes.Count > 0) {
				List<IReturnType> para = new List<IReturnType>(reference.GenericTypes.Count);
				for (int i = 0; i < reference.GenericTypes.Count; ++i) {
					para.Add(CreateReturnType(reference.GenericTypes[i], callingClass, callingMember, caretLine, caretColumn, projectContent, useLazyReturnType));
				}
				t = new ConstructedReturnType(t, para);
			}
			return WrapArray(projectContent, t, reference);
		}