Ejemplo n.º 1
0
        public override void OnReferenceExpression(ReferenceExpression node)
        {
            string identifier  = node.Name;
            bool   wasResolved = ResolveIdentifier(identifier);

            if (wasResolved && resolveResult is TypeResolveResult)
            {
                return;
            }
            // was not resolved or was resolved as local, member etc.
            ResolveResult oldResult = resolveResult;

            ClearResult();
            // Try to resolve as type:
            IReturnType t = projectContent.SearchType(new SearchTypeRequest(identifier, 0, callingClass, cu, resolver.CaretLine, resolver.CaretColumn)).Result;

            if (t != null)
            {
                MakeTypeResult(t);
            }
            else
            {
                if (callingClass != null)
                {
                    if (resolver.CallingMember is IMethod)
                    {
                        foreach (ITypeParameter typeParameter in (resolver.CallingMember as IMethod).TypeParameters)
                        {
                            if (IsSameName(identifier, typeParameter.Name))
                            {
                                MakeTypeResult(new GenericReturnType(typeParameter));
                                return;
                            }
                        }
                    }
                    foreach (ITypeParameter typeParameter in callingClass.TypeParameters)
                    {
                        if (IsSameName(identifier, typeParameter.Name))
                        {
                            MakeTypeResult(new GenericReturnType(typeParameter));
                            return;
                        }
                    }
                }
            }
            if (!wasResolved)
            {
                return;                 // return type result, if existant
            }
            if (resolveResult == null)
            {
                resolveResult = oldResult;
            }
            else
            {
                // TODO: return type or mixed dependant on context!
                resolveResult = new MixedResolveResult(oldResult, resolveResult);
            }
        }
Ejemplo n.º 2
0
 public IReturnType SearchType(string name)
 {
     return(projectContent.SearchType(new SearchTypeRequest(name, 0, callingClass, cu, caretLine, caretColumn)).Result);
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 4
0
 public IReturnType SearchType(string name, int typeParameterCount)
 {
     return(projectContent.SearchType(new SearchTypeRequest(name, typeParameterCount, callingClass, cu, caretLine, caretColumn)).Result);
 }
Ejemplo n.º 5
0
        public static IReturnType CreateReturnType(TypeReference reference, IClass callingClass,
		                                           IMember callingMember, int caretLine, int caretColumn,
		                                           IProjectContent projectContent,
		                                           ReturnTypeOptions options)
        {
            if (reference == null) return null;
            if (reference.IsNull) return null;
            if (reference is InnerClassTypeReference) {
                reference = ((InnerClassTypeReference)reference).CombineToNormalTypeReference();
            }

            bool useLazyReturnType = (options & ReturnTypeOptions.Lazy) == ReturnTypeOptions.Lazy;
            bool isBaseTypeReference = (options & ReturnTypeOptions.BaseTypeReference) == ReturnTypeOptions.BaseTypeReference;

            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.Type)) {
                        t = new GenericReturnType(tp);
                        break;
                    }
                }
                IMethod callingMethod = callingMember as IMethod;
                if (t == null && callingMethod != null) {
                    foreach (ITypeParameter tp in callingMethod.TypeParameters) {
                        if (languageProperties.NameComparer.Equals(tp.Name, reference.Type)) {
                            t = new GenericReturnType(tp);
                            break;
                        }
                    }
                }
            }
            if (t == null) {
                int typeParameterCount = reference.GenericTypes.Count;
                if (reference.IsKeyword) {
                    // keyword-type like void, int, string etc.
                    IClass c = projectContent.GetClass(reference.Type, typeParameterCount);
                    if (c != null)
                        t = c.DefaultReturnType;
                    else
                        t = new GetClassReturnType(projectContent, reference.Type, typeParameterCount);
                } else {
                    if (useLazyReturnType || isBaseTypeReference) {
                        if (reference.IsGlobal) {
                            t = new GetClassReturnType(projectContent, reference.Type, typeParameterCount);
                        } else if (callingClass != null) {
                            SearchClassReturnType scrt = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn, reference.Type, typeParameterCount);
                            if (isBaseTypeReference)
                                scrt.LookForInnerClassesInDeclaringClass = false;
                            t = scrt;
                        }
                    } else {
                        IClass c;
                        if (reference.IsGlobal) {
                            c = projectContent.GetClass(reference.Type, typeParameterCount);
                            t = (c != null) ? c.DefaultReturnType : null;
                        } else if (callingClass != null) {
                            t = projectContent.SearchType(new SearchTypeRequest(reference.Type, typeParameterCount, callingClass, caretLine, caretColumn)).Result;
                        }
                        if (t == null) {
                            return null;
                        }
                    }
                }
            }
            if (reference.GenericTypes.Count > 0) {
                IReturnType[] para = new IReturnType[reference.GenericTypes.Count];
                for (int i = 0; i < reference.GenericTypes.Count; ++i) {
                    para[i] = CreateReturnType(reference.GenericTypes[i], callingClass, callingMember, caretLine, caretColumn, projectContent, options);
                }
                t = new ConstructedReturnType(t, para);
            }
            for (int i = 0; i < reference.PointerNestingLevel; i++) {
                t = new PointerReturnType(t);
            }
            return WrapArray(projectContent, t, reference);
        }
Ejemplo n.º 6
0
        public static IReturnType CreateReturnType(TypeReference reference, IClass callingClass,
                                                   IMember callingMember, int caretLine, int caretColumn,
                                                   IProjectContent projectContent,
                                                   ReturnTypeOptions options)
        {
            if (reference == null)
            {
                return(null);
            }
            if (reference.IsNull)
            {
                return(null);
            }
            if (reference is InnerClassTypeReference)
            {
                reference = ((InnerClassTypeReference)reference).CombineToNormalTypeReference();
            }

            bool useLazyReturnType   = (options & ReturnTypeOptions.Lazy) == ReturnTypeOptions.Lazy;
            bool isBaseTypeReference = (options & ReturnTypeOptions.BaseTypeReference) == ReturnTypeOptions.BaseTypeReference;

            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.Type))
                    {
                        t = new GenericReturnType(tp);
                        break;
                    }
                }
                IMethod callingMethod = callingMember as IMethod;
                if (t == null && callingMethod != null)
                {
                    foreach (ITypeParameter tp in callingMethod.TypeParameters)
                    {
                        if (languageProperties.NameComparer.Equals(tp.Name, reference.Type))
                        {
                            t = new GenericReturnType(tp);
                            break;
                        }
                    }
                }
            }
            if (t == null && reference.Type == "dynamic")
            {
                t = new DynamicReturnType(projectContent);
            }
            if (t == null)
            {
                int typeParameterCount = reference.GenericTypes.Count;
                if (reference.IsKeyword)
                {
                    // keyword-type like void, int, string etc.
                    IClass c = projectContent.GetClass(reference.Type, typeParameterCount);
                    if (c != null)
                    {
                        t = c.DefaultReturnType;
                    }
                    else
                    {
                        t = new GetClassReturnType(projectContent, reference.Type, typeParameterCount);
                    }
                }
                else
                {
                    if (useLazyReturnType || isBaseTypeReference)
                    {
                        if (reference.IsGlobal)
                        {
                            t = new GetClassReturnType(projectContent, reference.Type, typeParameterCount);
                        }
                        else if (callingClass != null)
                        {
                            SearchClassReturnType scrt = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn, reference.Type, typeParameterCount);
                            if (isBaseTypeReference)
                            {
                                scrt.LookForInnerClassesInDeclaringClass = false;
                            }
                            t = scrt;
                        }
                    }
                    else
                    {
                        IClass c;
                        if (reference.IsGlobal)
                        {
                            c = projectContent.GetClass(reference.Type, typeParameterCount);
                            t = (c != null) ? c.DefaultReturnType : null;
                        }
                        else if (callingClass != null)
                        {
                            t = projectContent.SearchType(new SearchTypeRequest(reference.Type, typeParameterCount, callingClass, caretLine, caretColumn)).Result;
                        }
                        if (t == null)
                        {
                            return(null);
                        }
                    }
                }
            }
            if (reference.GenericTypes.Count > 0)
            {
                IReturnType[] para = new IReturnType[reference.GenericTypes.Count];
                for (int i = 0; i < reference.GenericTypes.Count; ++i)
                {
                    para[i] = CreateReturnType(reference.GenericTypes[i], callingClass, callingMember, caretLine, caretColumn, projectContent, options);
                }
                t = new ConstructedReturnType(t, para);
            }
            for (int i = 0; i < reference.PointerNestingLevel; i++)
            {
                t = new PointerReturnType(t);
            }
            return(WrapArray(projectContent, t, reference));
        }
Ejemplo n.º 7
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);
		}