示例#1
0
        /// <summary>
        /// Adds extension methods to <paramref name="res"/>.
        /// </summary>
        public static void AddExtensions(LanguageProperties language, ArrayList res, IClass callingClass, IReturnType resolvedType)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }
            if (res == null)
            {
                throw new ArgumentNullException("res");
            }
            if (callingClass == null)
            {
                throw new ArgumentNullException("callingClass");
            }
            if (resolvedType == null)
            {
                throw new ArgumentNullException("resolvedType");
            }

            bool supportsExtensionMethods    = language.SupportsExtensionMethods;
            bool supportsExtensionProperties = language.SupportsExtensionProperties;

            if (supportsExtensionMethods || supportsExtensionProperties)
            {
                ArrayList list        = new ArrayList();
                IMethod   dummyMethod = new DefaultMethod("dummy", VoidReturnType.Instance, ModifierEnum.Static, DomRegion.Empty, DomRegion.Empty, callingClass);
                CtrlSpaceResolveHelper.AddContentsFromCalling(list, callingClass, dummyMethod);
                CtrlSpaceResolveHelper.AddImportedNamespaceContents(list, callingClass.CompilationUnit, callingClass);

                bool searchExtensionsInClasses = language.SearchExtensionsInClasses;
                foreach (object o in list)
                {
                    if (supportsExtensionMethods && o is IMethod || supportsExtensionProperties && o is IProperty)
                    {
                        TryAddExtension(language, res, o as IMethodOrProperty, resolvedType);
                    }
                    else if (searchExtensionsInClasses && o is IClass)
                    {
                        IClass c = o as IClass;
                        if (c.HasExtensionMethods)
                        {
                            if (supportsExtensionProperties)
                            {
                                foreach (IProperty p in c.Properties)
                                {
                                    TryAddExtension(language, res, p, resolvedType);
                                }
                            }
                            if (supportsExtensionMethods)
                            {
                                foreach (IMethod m in c.Methods)
                                {
                                    TryAddExtension(language, res, m, resolvedType);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Gets the namespace dictionary that uses the name comparison rules of <paramref name="language"/>.
        /// </summary>
        protected Dictionary <string, NamespaceStruct> GetNamespaces(LanguageProperties language)
        {
            for (int i = 0; i < namespaces.Count; ++i)
            {
                if (namespaces[i].Comparer == language.NameComparer)
                {
                    return(namespaces[i]);
                }
            }
            Dictionary <string, NamespaceStruct> d;

            if (namespaces.Count > 0)
            {
                Dictionary <string, NamespaceStruct> oldList = namespaces[0];
                d = new Dictionary <string, NamespaceStruct>(oldList.Count, language.NameComparer);
                foreach (KeyValuePair <string, NamespaceStruct> pair in oldList)
                {
                    d.Add(pair.Key, pair.Value);
                }
            }
            else
            {
                d = new Dictionary <string, NamespaceStruct>(language.NameComparer);
            }
            namespaces.Add(d);
            return(d);
        }
示例#3
0
        /// <summary>
        /// Gets the class dictionary that uses the name comparison rules of <paramref name="language"/>.
        /// </summary>
        protected Dictionary <string, IClass> GetClasses(LanguageProperties language)
        {
            for (int i = 0; i < classLists.Count; ++i)
            {
                if (classLists[i].Comparer == language.NameComparer)
                {
                    return(classLists[i]);
                }
            }
            Dictionary <string, IClass> d;

            if (classLists.Count > 0)
            {
                Dictionary <string, IClass> oldList = classLists[0];
                d = new Dictionary <string, IClass>(oldList.Count, language.NameComparer);
                foreach (KeyValuePair <string, IClass> pair in oldList)
                {
                    d.Add(pair.Key, pair.Value);
                }
            }
            else
            {
                d = new Dictionary <string, IClass>(language.NameComparer);
            }
            classLists.Add(d);
            return(d);
        }
示例#4
0
        /// <summary>
        /// Adds the contents of the specified <paramref name="nameSpace"/> to the <paramref name="list"/>.
        /// </summary>
        public void AddNamespaceContents(ArrayList list, string nameSpace, LanguageProperties language, bool lookInReferences)
        {
            if (nameSpace == null)
            {
                return;
            }

            if (lookInReferences)
            {
                lock (_referencedContents)
                {
                    foreach (IProjectContent content in _referencedContents)
                    {
                        if (content != null)
                        {
                            content.AddNamespaceContents(list, nameSpace, language, false);
                        }
                    }
                }
            }

            Dictionary <string, NamespaceStruct> dict = GetNamespaces(language);

            if (dict.ContainsKey(nameSpace))
            {
                NamespaceStruct ns          = dict[nameSpace];
                int             newCapacity = list.Count + ns.Classes.Count + ns.SubNamespaces.Count;
                if (list.Capacity < newCapacity)
                {
                    list.Capacity = Math.Max(list.Count * 2, newCapacity);
                }
                foreach (IClass c in ns.Classes)
                {
                    if (c is GenericClassContainer)
                    {
                        foreach (IClass realClass in ((GenericClassContainer)c).RealClasses)
                        {
                            AddNamespaceContentsClass(list, realClass, language, lookInReferences);
                        }
                    }
                    else
                    {
                        AddNamespaceContentsClass(list, c, language, lookInReferences);
                    }
                }
                foreach (string subns in ns.SubNamespaces)
                {
                    if (!list.Contains(subns))
                    {
                        list.Add(subns);
                    }
                }
            }
        }
示例#5
0
        protected ArrayList GetCompletionData(LanguageProperties language, bool showStatic)
        {
            if (resolvedType == null)
            {
                return(null);
            }
            ArrayList res = new ArrayList();
            bool      isClassInInheritanceTree = false;

            if (callingClass != null)
            {
                isClassInInheritanceTree = callingClass.IsTypeInInheritanceTree(resolvedType.GetUnderlyingClass());
            }
            foreach (IMethod m in resolvedType.GetMethods())
            {
                if (language.ShowMember(m, showStatic) && m.IsAccessible(callingClass, isClassInInheritanceTree))
                {
                    res.Add(m);
                }
            }
            foreach (IEvent e in resolvedType.GetEvents())
            {
                if (language.ShowMember(e, showStatic) && e.IsAccessible(callingClass, isClassInInheritanceTree))
                {
                    res.Add(e);
                }
            }
            foreach (IField f in resolvedType.GetFields())
            {
                if (language.ShowMember(f, showStatic) && f.IsAccessible(callingClass, isClassInInheritanceTree))
                {
                    res.Add(f);
                }
            }
            foreach (IProperty p in resolvedType.GetProperties())
            {
                if (language.ShowMember(p, showStatic) && p.IsAccessible(callingClass, isClassInInheritanceTree))
                {
                    res.Add(p);
                }
            }

            if (!showStatic && callingClass != null)
            {
                AddExtensions(language, res, callingClass, resolvedType);
            }

            return(res);
        }
示例#6
0
 protected IClass GetClassInternal(string typeName, int typeParameterCount, LanguageProperties language)
 {
     lock (namespaces) {
         IClass c;
         if (GetClasses(language).TryGetValue(typeName, out c))
         {
             GenericClassContainer gcc = c as GenericClassContainer;
             if (gcc != null)
             {
                 return(gcc.GetBest(typeParameterCount));
             }
             return(c);
         }
         return(null);
     }
 }
示例#7
0
 static void TryAddExtension(LanguageProperties language, ArrayList res, IMethodOrProperty ext, IReturnType resolvedType)
 {
     // accept only extension methods
     if (!ext.IsExtensionMethod)
     {
         return;
     }
     // don't add extension if method with that name already exists
     // but allow overloading extension methods
     foreach (IMember member in res)
     {
         IMethodOrProperty p = member as IMethodOrProperty;
         if (p != null && p.IsExtensionMethod)
         {
             continue;
         }
         if (language.NameComparer.Equals(member.Name, ext.Name))
         {
             return;
         }
     }
     // now add the extension method if it fits the type
     if (MemberLookupHelper.ConversionExists(resolvedType, ext.Parameters[0].ReturnType))
     {
         IMethod method = ext as IMethod;
         if (method != null && method.TypeParameters.Count > 0)
         {
             IReturnType[] typeArguments = new IReturnType[method.TypeParameters.Count];
             MemberLookupHelper.InferTypeArgument(method.Parameters[0].ReturnType, resolvedType, typeArguments);
             for (int i = 0; i < typeArguments.Length; i++)
             {
                 if (typeArguments[i] != null)
                 {
                     ext            = (IMethod)ext.Clone();
                     ext.ReturnType = ConstructedReturnType.TranslateType(ext.ReturnType, typeArguments, true);
                     for (int j = 0; j < ext.Parameters.Count; ++j)
                     {
                         ext.Parameters[j].ReturnType = ConstructedReturnType.TranslateType(ext.Parameters[j].ReturnType, typeArguments, true);
                     }
                     break;
                 }
             }
         }
         res.Add(ext);
     }
 }
示例#8
0
 void AddNamespaceContentsClass(ArrayList list, IClass c, LanguageProperties language, bool lookInReferences)
 {
     if (c.IsInternal && !lookInReferences)
     {
         // internal class and we are looking at it from another project content
         return;
     }
     if (language.ShowInNamespaceCompletion(c))
     {
         list.Add(c);
     }
     if (language.ImportModules && c.ClassType == ClassType.Module)
     {
         foreach (IMember m in c.Methods)
         {
             if (m.IsAccessible(null, false))
             {
                 list.Add(m);
             }
         }
         foreach (IMember m in c.Events)
         {
             if (m.IsAccessible(null, false))
             {
                 list.Add(m);
             }
         }
         foreach (IMember m in c.Fields)
         {
             if (m.IsAccessible(null, false))
             {
                 list.Add(m);
             }
         }
         foreach (IMember m in c.Properties)
         {
             if (m.IsAccessible(null, false))
             {
                 list.Add(m);
             }
         }
     }
 }
示例#9
0
        public bool NamespaceExists(string name, LanguageProperties language, bool lookInReferences)
        {
            if (name == null)
            {
                return(false);
            }

            if (lookInReferences)
            {
                lock (referencedContents) {
                    foreach (IProjectContent content in referencedContents)
                    {
                        if (content.NamespaceExists(name, language, false))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(GetNamespaces(language).ContainsKey(name));
        }
示例#10
0
        /// <summary>
        /// Searches the member with the specified name. Returns the first member/overload found.
        /// </summary>
        public IMember SearchMember(string memberName, LanguageProperties language)
        {
            if (memberName == null || memberName.Length == 0)
            {
                return(null);
            }
            StringComparer cmp = language.NameComparer;

            foreach (IProperty p in Properties)
            {
                if (cmp.Equals(p.Name, memberName))
                {
                    return(p);
                }
            }
            foreach (IEvent e in Events)
            {
                if (cmp.Equals(e.Name, memberName))
                {
                    return(e);
                }
            }
            foreach (IField f in Fields)
            {
                if (cmp.Equals(f.Name, memberName))
                {
                    return(f);
                }
            }
            foreach (IMethod m in Methods)
            {
                if (cmp.Equals(m.Name, memberName))
                {
                    return(m);
                }
            }
            return(null);
        }
示例#11
0
        public IClass GetClass(string typeName, int typeParameterCount, LanguageProperties language, bool lookInReferences)
        {
            IClass c = GetClassInternal(typeName, typeParameterCount, language);

            if (c != null && c.TypeParameters.Count == typeParameterCount)
            {
                return(c);
            }

            // Search in references:
            if (lookInReferences)
            {
                lock (referencedContents) {
                    foreach (IProjectContent content in referencedContents)
                    {
                        IClass contentClass = content.GetClass(typeName, typeParameterCount, language, false);
                        if (contentClass != null)
                        {
                            if (contentClass.TypeParameters.Count == typeParameterCount)
                            {
                                return(contentClass);
                            }
                            else
                            {
                                c = contentClass;
                            }
                        }
                    }
                }
            }

            if (c != null)
            {
                return(c);
            }

            // not found -> maybe nested type -> trying to find class that contains this one.
            int lastIndex = typeName.LastIndexOf('.');

            if (lastIndex > 0)
            {
                string outerName  = typeName.Substring(0, lastIndex);
                IClass upperClass = GetClassInternal(outerName, typeParameterCount, language);
                if (upperClass != null)
                {
                    foreach (IClass upperBaseClass in upperClass.ClassInheritanceTree)
                    {
                        List <IClass> innerClasses = upperBaseClass.InnerClasses;
                        if (innerClasses != null)
                        {
                            string innerName = typeName.Substring(lastIndex + 1);
                            foreach (IClass innerClass in innerClasses)
                            {
                                if (language.NameComparer.Equals(innerClass.Name, innerName))
                                {
                                    return(innerClass);
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }