public string SearchNamespace(string partialNamespaceName)
 {
     if (HasAliases)
     {
         foreach (KeyValuePair <string, IReturnType> entry in aliases)
         {
             if (!entry.Value.IsDefaultReturnType)
             {
                 continue;
             }
             string aliasString = entry.Key;
             string nsName;
             if (projectContent.Language.NameComparer.Equals(partialNamespaceName, aliasString))
             {
                 nsName = entry.Value.FullyQualifiedName;
                 if (projectContent.NamespaceExists(nsName))
                 {
                     return(nsName);
                 }
             }
             if (partialNamespaceName.Length > aliasString.Length)
             {
                 if (projectContent.Language.NameComparer.Equals(partialNamespaceName.Substring(0, aliasString.Length + 1), aliasString + "."))
                 {
                     nsName = String.Concat(entry.Value.FullyQualifiedName, partialNamespaceName.Remove(0, aliasString.Length));
                     if (projectContent.NamespaceExists(nsName))
                     {
                         return(nsName);
                     }
                 }
             }
         }
     }
     if (projectContent.Language.ImportNamespaces)
     {
         foreach (string str in usings)
         {
             string possibleNamespace = String.Concat(str, ".", partialNamespaceName);
             if (projectContent.NamespaceExists(possibleNamespace))
             {
                 return(possibleNamespace);
             }
         }
     }
     return(null);
 }
Exemple #2
0
 public override void OnReferenceExpression(ReferenceExpression node)
 {
     if (pc.GetClass(node.Name, 0) != null)
     {
         _expression = new CodeTypeReferenceExpression(node.Name);
     }
     else if (pc.NamespaceExists(node.Name))
     {
         _expression = new CodeTypeReferenceExpression(node.Name);
     }
     else if (GetLocalVariable(node.Name) != null)
     {
         _expression = new CodeVariableReferenceExpression(node.Name);
     }
     else
     {
         _expression = CreateMemberExpression(new CodeThisReferenceExpression(), node.Name);
     }
 }
        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));
        }
Exemple #4
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));
        }
 public bool NamespaceExistsInProjectReferences(string name)
 {
     return(projectContent.NamespaceExists(name));
 }
Exemple #6
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);
                }
            }
        }
		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);
		}