Exemplo n.º 1
0
 static void TryAddExtension(LanguageProperties language, Action <IMethodOrProperty> methodFound, IMethodOrProperty ext, IReturnType resolvedType)
 {
     // now add the extension method if it fits the type
     if (MemberLookupHelper.IsApplicable(resolvedType, ext.Parameters[0].ReturnType, ext as IMethod))
     {
         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.CreateSpecializedMember();
                     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;
                 }
             }
         }
         methodFound(ext);
     }
 }
Exemplo n.º 2
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);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds extension methods to <paramref name="res"/>.
        /// </summary>
        public static void AddExtensions(LanguageProperties language, Action <IMethodOrProperty> methodFound, IClass callingClass, IReturnType resolvedType, bool searchInAllNamespaces = false)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }
            if (methodFound == null)
            {
                throw new ArgumentNullException("methodFound");
            }
            if (resolvedType == null)
            {
                throw new ArgumentNullException("resolvedType");
            }
            if (callingClass == null)
            {
                throw new ArgumentNullException("callingClass");
            }

            // convert resolvedType into direct type to speed up the IsApplicable lookups
            resolvedType = resolvedType.GetDirectReturnType();

            foreach (IMethodOrProperty mp in CtrlSpaceResolveHelper.FindAllExtensions(language, callingClass, searchInAllNamespaces))
            {
                TryAddExtension(language, methodFound, mp, resolvedType);
            }
        }
		public NRefactoryInsightWindowHandler(SupportedLanguage language)
		{
			this.language = language;
			if (language == SupportedLanguage.CSharp) {
				eofToken = CSTokens.EOF;
				commaToken = CSTokens.Comma;
				openParensToken = CSTokens.OpenParenthesis;
				closeParensToken = CSTokens.CloseParenthesis;
				openBracketToken = CSTokens.OpenSquareBracket;
				closeBracketToken = CSTokens.CloseSquareBracket;
				openBracesToken = CSTokens.OpenCurlyBrace;
				closeBracesToken = CSTokens.CloseCurlyBrace;
				statementEndToken = CSTokens.Semicolon;

				languageProperties = LanguageProperties.CSharp;
			} else {
				eofToken = VBTokens.EOF;
				commaToken = VBTokens.Comma;
				openParensToken = VBTokens.OpenParenthesis;
				closeParensToken = VBTokens.CloseParenthesis;
				openBracketToken = -1;
				closeBracketToken = -1;
				openBracesToken = VBTokens.OpenCurlyBrace;
				closeBracesToken = VBTokens.CloseCurlyBrace;
				statementEndToken = VBTokens.EOL;

				languageProperties = LanguageProperties.VBNet;
			}
		}
        public static List <IList <IMember> > LookupMember(
            IReturnType type, string name, IClass callingClass,
            LanguageProperties language, bool isInvocation, bool?isAccessThoughReferenceOfCurrentClass)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }

            if (isAccessThoughReferenceOfCurrentClass == null)
            {
                isAccessThoughReferenceOfCurrentClass = false;
                IClass underlyingClass = type.GetUnderlyingClass();
                if (underlyingClass != null)
                {
                    isAccessThoughReferenceOfCurrentClass = underlyingClass.IsTypeInInheritanceTree(callingClass);
                }
            }

            IEnumerable <IMember> members;

            if (language == LanguageProperties.VBNet && language.NameComparer.Equals(name, "New"))
            {
                members = GetAllMembers(type).OfType <IMethod>().Where(m => m.IsConstructor).Select(m => (IMember)m);
            }
            else
            {
                members = GetAllMembers(type).Where(m => language.NameComparer.Equals(m.Name, name));
            }

            return(LookupMember(members, callingClass, (bool)isAccessThoughReferenceOfCurrentClass, isInvocation));
        }
		protected NRefactoryCodeCompletionBinding(SupportedLanguage language)
		{
			this.language = language;
			if (language == SupportedLanguage.CSharp) {
				eofToken = CSTokens.EOF;
				commaToken = CSTokens.Comma;
				openParensToken = CSTokens.OpenParenthesis;
				closeParensToken = CSTokens.CloseParenthesis;
				openBracketToken = CSTokens.OpenSquareBracket;
				closeBracketToken = CSTokens.CloseSquareBracket;
				openBracesToken = CSTokens.OpenCurlyBrace;
				closeBracesToken = CSTokens.CloseCurlyBrace;
				
				languageProperties = LanguageProperties.CSharp;
			} else {
				eofToken = VBTokens.EOF;
				commaToken = VBTokens.Comma;
				openParensToken = VBTokens.OpenParenthesis;
				closeParensToken = VBTokens.CloseParenthesis;
				openBracketToken = -1;
				closeBracketToken = -1;
				openBracesToken = VBTokens.OpenCurlyBrace;
				closeBracesToken = VBTokens.CloseCurlyBrace;
				
				languageProperties = LanguageProperties.VBNet;
			}
		}
Exemplo n.º 9
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 (resolvedType == null)
            {
                throw new ArgumentNullException("resolvedType");
            }
            if (callingClass == null)
            {
                throw new ArgumentNullException("callingClass");
            }

            // convert resolvedType into direct type to speed up the IsApplicable lookups
            resolvedType = resolvedType.GetDirectReturnType();

            foreach (IMethodOrProperty mp in CtrlSpaceResolveHelper.FindAllExtensions(language, callingClass))
            {
                TryAddExtension(language, res, mp, resolvedType);
            }
        }
Exemplo n.º 10
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;
		}
Exemplo n.º 11
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)
                {
                    // don't use d.Add(), the new name language might treat two names as equal
                    // that were unequal in the old dictionary
                    d[pair.Key] = pair.Value;
                }
            }
            else
            {
                d = new Dictionary <string, IClass>(language.NameComparer);
            }
            classLists.Add(d);
            return(d);
        }
		protected NRefactoryCodeCompletionBinding(SupportedLanguage language)
		{
			this.language = language;
			if (language == SupportedLanguage.CSharp) {
				languageProperties = LanguageProperties.CSharp;
			} else {
				languageProperties = LanguageProperties.VBNet;
			}
			
			insightHandler = new NRefactoryInsightWindowHandler(language);
		}
Exemplo n.º 13
0
		void CheckNamespace(string @namespace, string className, LanguageProperties language)
		{
			ICompilationUnit cu = Prepare(language);
			string ns = cu.ProjectContent.SearchType(new SearchTypeRequest(@namespace, 0, null, cu, 1, 1)).NamespaceResult;
			Assert.IsNotNull(ns, @namespace + " not found");
			foreach (object o in cu.ProjectContent.GetNamespaceContents(ns)) {
				IClass c = o as IClass;
				if (c != null && c.Name == className)
					return;
			}
		}
		protected override string GenerateCode(LanguageProperties language, IClass currentClass)
		{
			StringBuilder builder = new StringBuilder();
			IDocumentLine line = editor.Document.GetLineForOffset(anchor.Offset);
			string indent = DocumentUtilitites.GetWhitespaceAfter(editor.Document, line.Offset);
			bool implementInterface = this.implementInterface.IsChecked == true;
			bool hasOnPropertyChanged = HasOnPropertyChanged(currentClass);
			bool useEventArgs = false;
			
			if (implementInterface && !currentClass.IsStatic) {
				if (!hasOnPropertyChanged) {
					var nodes = new List<AbstractNode>();
					var rt = new GetClassReturnType(currentClass.ProjectContent, "System.ComponentModel.INotifyPropertyChanged", 0);
					if (!currentClass.ClassInheritanceTree.Any(bt => bt.FullyQualifiedName == "System.ComponentModel.INotifyPropertyChanged")) {
						int insertion = editor.Document.PositionToOffset(currentClass.BodyRegion.BeginLine, currentClass.BodyRegion.BeginColumn);
						if (currentClass.BaseTypes.Count > 0)
							editor.Document.Insert(insertion, ", INotifyPropertyChanged");
						else
							editor.Document.Insert(insertion, " : INotifyPropertyChanged");
					}
					language.CodeGenerator.ImplementInterface(nodes, rt, false, currentClass);
					var ev = rt.GetEvents().First(e => e.Name == "PropertyChanged");
					MethodDeclaration onEvent = language.CodeGenerator.CreateOnEventMethod(new DefaultEvent(ev.Name, ev.ReturnType, ev.Modifiers, ev.Region, ev.BodyRegion, currentClass));
					nodes.Add(onEvent);
					onEvent.Parameters[0].TypeReference = new TypeReference("string", true);
					onEvent.Parameters[0].ParameterName = "propertyName";
					((RaiseEventStatement)onEvent.Body.Children[0]).Arguments[1] = new ObjectCreateExpression(new TypeReference("PropertyChangedEventArgs"), new List<Expression> { new IdentifierExpression("propertyName") });
					foreach (var node in nodes)
						builder.AppendLine(language.CodeGenerator.GenerateCode(node, indent));
					useEventArgs = false;
				} else {
					useEventArgs = currentClass.DefaultReturnType.GetMethods().First(m => m.Name == "OnPropertyChanged").Parameters[0].ReturnType.FullyQualifiedName != "System.String";
				}
			}
			
			foreach (FieldWrapper field in listBox.SelectedItems) {
				var prop = language.CodeGenerator.CreateProperty(field.Field, true, field.AddSetter);
				if (!field.Field.IsStatic && !currentClass.IsStatic && field.AddSetter && implementInterface) {
					var invocation = new ExpressionStatement(CreateInvocation(field.PropertyName, useEventArgs));
					var assignment = prop.SetRegion.Block.Children[0];
					prop.SetRegion.Block.Children.Clear();
					prop.SetRegion.Block.AddChild(
						new IfElseStatement(
							new BinaryOperatorExpression(new IdentifierExpression(field.MemberName), BinaryOperatorType.InEquality, new IdentifierExpression("value")),
							new BlockStatement { Children = { assignment, invocation } }
						)
					);
				}
				builder.AppendLine(language.CodeGenerator.GenerateCode(prop, indent));
			}
			
			return builder.ToString().Trim();
		}
Exemplo n.º 15
0
		ICompilationUnit Prepare(LanguageProperties language)
		{
			DefaultProjectContent pc = new DefaultProjectContent();
			pc.ReferencedContents.Add(projectContentRegistry.Mscorlib);
			pc.Language = language;
			DefaultCompilationUnit cu = new DefaultCompilationUnit(pc);
			if (language == LanguageProperties.VBNet)
				cu.UsingScope.Usings.Add(CreateUsing(pc, "syStEm"));
			else
				cu.UsingScope.Usings.Add(CreateUsing(pc, "System"));
			return cu;
		}
Exemplo n.º 16
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)
                    {
                        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);
                    }
                }
            }
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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);
     }
 }
		protected override string GenerateCode(LanguageProperties language, IClass currentClass)
		{
			string[] fields = listBox.SelectedItems.OfType<PropertyOrFieldWrapper>().Select(f2 => f2.MemberName).ToArray();
			
			Ast.PrimitiveExpression formatString = new Ast.PrimitiveExpression(GenerateFormatString(currentClass, language.CodeGenerator, fields));
			List<Ast.Expression> param = new List<Ast.Expression>() { formatString };
			
			Ast.ReturnStatement ret = new Ast.ReturnStatement(new Ast.InvocationExpression(
				new Ast.MemberReferenceExpression(new Ast.TypeReferenceExpression(new Ast.TypeReference("System.String", true)), "Format"),
				param.Concat(fields.Select(f => new Ast.IdentifierExpression(f))).ToList()
			));
			
			insertedCode = language.CodeGenerator.GenerateCode(ret, "").Trim();
			
			return insertedCode;
		}
Exemplo n.º 20
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);
     }
 }
Exemplo n.º 21
0
 /// <summary>
 /// Adds the contents of all namespaces in this project to the <paramref name="list"/>.
 /// </summary>
 /// <param name="lookInReferences">If true, contents of referenced projects will be added as well (not recursive - just 1 level deep).</param>
 public void AddAllContents(List <ICompletionEntry> list, LanguageProperties language, bool lookInReferences)
 {
     if (lookInReferences)
     {
         lock (referencedContents) {
             foreach (IProjectContent content in referencedContents)
             {
                 content.AddAllContents(list, language, false);
             }
         }
     }
     lock (namespaces) {
         Dictionary <string, NamespaceStruct> dict = GetNamespaces(language);
         foreach (var namespaceStruct in dict.Values)
         {
             AddNamespaceStructContents(list, namespaceStruct, language, lookInReferences);
         }
     }
 }
Exemplo n.º 22
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);
             }
         }
     }
 }
		/// <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;
		}
Exemplo n.º 24
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));
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
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)
                {
                    NamespaceStruct ns;
                    if (d.TryGetValue(pair.Key, out ns))
                    {
                        // we got a name conflict due to the new NameComparer.
                        // This happens if a C# assembly contains the namespace "a" and "A",
                        // and now we're trying to get a dictionary for use in VB.
                        d[pair.Key] = ns.MergeWith(pair.Value);
                    }
                    else
                    {
                        d.Add(pair.Key, pair.Value);
                    }
                }
            }
            else
            {
                d = new Dictionary <string, NamespaceStruct>(language.NameComparer);
            }
            namespaces.Add(d);
            return(d);
        }
Exemplo n.º 27
0
		// usingMode: 0 = one using-statement for each namespace (correctly cased)
		//            1 = mixture of using statements and default imports (incorrectly cased)
		//            2 = all default imports (incorrectly cased)
		ICompilationUnit Prepare(LanguageProperties language, int usingMode)
		{
			DefaultProjectContent pc = new DefaultProjectContent();
			pc.ReferencedContents.Add(projectContentRegistry.Mscorlib);
			pc.Language = language;
			DefaultCompilationUnit cu = new DefaultCompilationUnit(pc);
			if (usingMode == 1) {
				cu.UsingScope.Usings.Add(CreateUsing(pc, "syStEm.coLLectIons"));
				pc.DefaultImports = new DefaultUsing(pc);
				pc.DefaultImports.Usings.Add("syStEm");
				pc.DefaultImports.Usings.Add("syStEm.coLLEctionS.GeNeRic");
			} else if (usingMode == 2) {
				pc.DefaultImports = new DefaultUsing(pc);
				pc.DefaultImports.Usings.Add("syStEm");
				pc.DefaultImports.Usings.Add("syStEm.coLLEctioNs");
				pc.DefaultImports.Usings.Add("syStEm.coLLEctionS.GeNeRic");
			} else { // usingMode == 0
				cu.UsingScope.Usings.Add(CreateUsing(pc, "System"));
				cu.UsingScope.Usings.Add(CreateUsing(pc, "System.Collections"));
				cu.UsingScope.Usings.Add(CreateUsing(pc, "System.Collections.Generic"));
			}
			return cu;
		}
Exemplo n.º 28
0
 protected IClass GetClassInternal(string typeName, int typeParameterCount, LanguageProperties language)
 {
     CheckNotDisposed();
                 #if DEBUG
     if (System.Text.RegularExpressions.Regex.IsMatch(typeName, "`[0-9]+$"))
     {
         Debug.Assert(false, "how did a Reflection type name get here?");
     }
                 #endif
     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);
     }
 }
Exemplo n.º 29
0
        protected List <ICompletionEntry> GetCompletionData(LanguageProperties language, bool showStatic)
        {
            if (resolvedType == null)
            {
                return(null);
            }
            List <ICompletionEntry> res = new List <ICompletionEntry>();

            foreach (IMember m in MemberLookupHelper.GetAccessibleMembers(resolvedType, callingClass, language))
            {
                if (language.ShowMember(m, showStatic))
                {
                    res.Add(m);
                }
            }

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

            return(res);
        }
Exemplo n.º 30
0
        protected ArrayList GetCompletionData(LanguageProperties language, bool showStatic)
        {
            if (resolvedType == null)
            {
                return(null);
            }
            ArrayList res = new ArrayList();

            foreach (IMember m in MemberLookupHelper.GetAccessibleMembers(resolvedType, callingClass, language))
            {
                if (language.ShowMember(m, showStatic))
                {
                    res.Add(m);
                }
            }

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

            return(res);
        }
Exemplo n.º 31
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;
						}
					}
				}
			}
			
			lock (namespaces) {
				return GetNamespaces(language).ContainsKey(name);
			}
		}
Exemplo n.º 32
0
		void AddNamespaceContentsClass(List<ICompletionEntry> 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);
				}
			}
		}
Exemplo n.º 33
0
		void AddNamespaceStructContents(List<ICompletionEntry> list, NamespaceStruct ns, LanguageProperties language, bool lookInReferences)
		{
			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) {
				NamespaceEntry subnsEntry = new NamespaceEntry(subns);
				if (!list.Contains(subnsEntry))	// PERF
					list.Add(subnsEntry);
			}
		}
Exemplo n.º 34
0
		/// <summary>
		/// Adds the contents of the specified <paramref name="nameSpace"/> to the <paramref name="list"/>.
		/// </summary>
		/// <param name="lookInReferences">If true, contents of referenced projects will be added as well (not recursive - just 1 level deep).</param>
		public void AddNamespaceContents(List<ICompletionEntry> list, string nameSpace, LanguageProperties language, bool lookInReferences)
		{
			if (nameSpace == null) {
				return;
			}
			
			if (lookInReferences) {
				lock (referencedContents) {
					foreach (IProjectContent content in referencedContents) {
						content.AddNamespaceContents(list, nameSpace, language, false);
					}
				}
			}
			
			lock (namespaces) {
				Dictionary<string, NamespaceStruct> dict = GetNamespaces(language);
				if (dict.ContainsKey(nameSpace)) {
					NamespaceStruct ns = dict[nameSpace];
					AddNamespaceStructContents(list, ns, language, lookInReferences);
				}
			}
		}
		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;
			}
		}
Exemplo n.º 36
0
        /// <summary>
        /// Adds the contents of the specified <paramref name="nameSpace"/> to the <paramref name="list"/>.
        /// </summary>
        /// <param name="lookInReferences">If true, contents of referenced projects will be added as well (not recursive - just 1 level deep).</param>
        public void AddNamespaceContents(List <ICompletionEntry> list, string nameSpace, LanguageProperties language, bool lookInReferences)
        {
            if (nameSpace == null)
            {
                return;
            }

            if (lookInReferences)
            {
                lock (referencedContents) {
                    foreach (IProjectContent content in referencedContents)
                    {
                        content.AddNamespaceContents(list, nameSpace, language, false);
                    }
                }
            }

            lock (namespaces) {
                Dictionary <string, NamespaceStruct> dict = GetNamespaces(language);
                if (dict.ContainsKey(nameSpace))
                {
                    NamespaceStruct ns = dict[nameSpace];
                    AddNamespaceStructContents(list, ns, language, lookInReferences);
                }
            }
        }
Exemplo n.º 37
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);
        }
Exemplo n.º 38
0
        /// <summary>
        /// Gets all accessible members, including indexers and constructors.
        /// </summary>
        public static List <IMember> GetAccessibleMembers(IReturnType rt, IClass callingClass, LanguageProperties language, bool isAccessThoughReferenceOfCurrentClass)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }

            List <IMember> result = new List <IMember>();

            foreach (var g in GetAllMembers(rt).GroupBy(m => m.Name, language.NameComparer).OrderBy(g2 => g2.Key))
            {
                foreach (var group in LookupMember(g, callingClass, isAccessThoughReferenceOfCurrentClass, false))
                {
                    result.AddRange(group);
                }
            }
            return(result);
        }
		public static IList<IMethodOrProperty> FindAllExtensions(LanguageProperties language, IClass callingClass, bool searchInAllNamespaces = false)
		{
			if (language == null)
				throw new ArgumentNullException("language");
			if (callingClass == null)
				throw new ArgumentNullException("callingClass");
			
			HashSet<IMethodOrProperty> res = new HashSet<IMethodOrProperty>();
			
			bool supportsExtensionMethods = language.SupportsExtensionMethods;
			bool supportsExtensionProperties = language.SupportsExtensionProperties;
			if (supportsExtensionMethods || supportsExtensionProperties) {
				List<ICompletionEntry> list = new List<ICompletionEntry>();
				IMethod dummyMethod = new DefaultMethod("dummy", callingClass.ProjectContent.SystemTypes.Void,
				                                        ModifierEnum.Static, DomRegion.Empty, DomRegion.Empty, callingClass);
				CtrlSpaceResolveHelper.AddContentsFromCalling(list, callingClass, dummyMethod);
				if (searchInAllNamespaces) {
					// search extension methods in all referenced projects, no matter the using section
					CtrlSpaceResolveHelper.AddReferencedProjectsContents(list, callingClass.CompilationUnit, callingClass);
				} else {
					CtrlSpaceResolveHelper.AddImportedNamespaceContents(list, callingClass.CompilationUnit, callingClass);
				}
				
				bool searchExtensionsInClasses = language.SearchExtensionsInClasses;
				foreach (object o in list) {
					IMethodOrProperty mp = o as IMethodOrProperty;
					if (mp != null && mp.IsExtensionMethod &&
					    (supportsExtensionMethods && o is IMethod || supportsExtensionProperties && o is IProperty))
					{
						res.Add(mp);
					} else if (searchExtensionsInClasses && o is IClass) {
						IClass c = o as IClass;
						if (c.HasExtensionMethods) {
							if (supportsExtensionProperties) {
								foreach (IProperty p in c.Properties) {
									if (p.IsExtensionMethod)
										res.Add(p);
								}
							}
							if (supportsExtensionMethods) {
								foreach (IMethod m in c.Methods) {
									if (m.IsExtensionMethod)
										res.Add(m);
								}
							}
						}
					}
				}
			}
			return res.ToList();
		} // FindAllExtensions
		/// <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) {
						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);
				}
			}
		}
Exemplo n.º 41
0
		protected override string GenerateCode(LanguageProperties language, IClass currentClass)
		{
			IDocumentLine line = editor.Document.GetLineForOffset(anchor.Offset);
			
			string indent = DocumentUtilitites.GetWhitespaceAfter(editor.Document, line.Offset);
			
			List<PropertyOrFieldWrapper> filtered = parameterList
				.Where(p => p.IsSelected)
				.OrderBy(p => p.Index)
				.ToList();
			
			BlockStatement block = new BlockStatement();
			
			foreach (PropertyOrFieldWrapper w in filtered) {
				if (w.AddCheckForNull) {
					// true = reference, null = generic or unknown
					if (w.Type.IsReferenceType != false)
						block.AddChild(
							new IfElseStatement(
								new BinaryOperatorExpression(new IdentifierExpression(w.ParameterName), BinaryOperatorType.Equality, new PrimitiveExpression(null)),
								new ThrowStatement(new ObjectCreateExpression(new TypeReference("ArgumentNullException"), new List<Expression>() { new PrimitiveExpression(w.ParameterName, '"' + w.ParameterName + '"') }))
							)
						);
					else
						block.AddChild(
							new IfElseStatement(
								new UnaryOperatorExpression(new MemberReferenceExpression(new IdentifierExpression(w.MemberName), "HasValue"), UnaryOperatorType.Not),
								new ThrowStatement(new ObjectCreateExpression(new TypeReference("ArgumentNullException"), new List<Expression>() { new PrimitiveExpression(w.ParameterName, '"' + w.ParameterName + '"') }))
							)
						);
				}
				if (w.AddRangeCheck) {
					block.AddChild(
						new IfElseStatement(
							new BinaryOperatorExpression(
								new BinaryOperatorExpression(new IdentifierExpression(w.ParameterName), BinaryOperatorType.LessThan, new IdentifierExpression("lower")),
								BinaryOperatorType.LogicalOr,
								new BinaryOperatorExpression(new IdentifierExpression(w.ParameterName), BinaryOperatorType.GreaterThan, new IdentifierExpression("upper"))
							),
							new ThrowStatement(
								new ObjectCreateExpression(
									new TypeReference("ArgumentOutOfRangeException"),
									new List<Expression>() { new PrimitiveExpression(w.ParameterName, '"' + w.ParameterName + '"'), new IdentifierExpression(w.ParameterName), new BinaryOperatorExpression(new PrimitiveExpression("Value must be between "), BinaryOperatorType.Concat, new BinaryOperatorExpression(new IdentifierExpression("lower"), BinaryOperatorType.Concat, new BinaryOperatorExpression(new PrimitiveExpression(" and "), BinaryOperatorType.Concat, new IdentifierExpression("upper")))) }
								)
							)
						)
					);
				}
			}
			
			foreach (PropertyOrFieldWrapper w in filtered)
				block.AddChild(new ExpressionStatement(new AssignmentExpression(new MemberReferenceExpression(new ThisReferenceExpression(), w.MemberName), AssignmentOperatorType.Assign, new IdentifierExpression(w.ParameterName))));
			
			AnchorElement parameterListElement = context.ActiveElements
				.OfType<AnchorElement>()
				.FirstOrDefault(item => item.Name.Equals("parameterList", StringComparison.OrdinalIgnoreCase));
			
			if (parameterListElement != null) {
				StringBuilder pList = new StringBuilder();
				
				var parameters = filtered
					.Select(p => new ParameterDeclarationExpression(ConvertType(p.Type), p.ParameterName))
					.ToList();
				
				for (int i = 0; i < parameters.Count; i++) {
					if (i > 0)
						pList.Append(", ");
					pList.Append(language.CodeGenerator.GenerateCode(parameters[i], ""));
				}
				
				parameterListElement.Text = pList.ToString();
			}
			
			StringBuilder builder = new StringBuilder();
			
			foreach (var element in block.Children.OfType<AbstractNode>()) {
				builder.Append(language.CodeGenerator.GenerateCode(element, indent));
			}
			
			return builder.ToString().Trim();
		}
Exemplo n.º 42
0
        /// <summary>
        /// Gets all accessible members, including indexers and constructors.
        /// </summary>
        public static List <IMember> GetAccessibleMembers(IReturnType rt, IClass callingClass, LanguageProperties language)
        {
            bool   isAccessThoughReferenceOfCurrentClass = false;
            IClass underlyingClass = rt.GetUnderlyingClass();

            if (underlyingClass != null)
            {
                isAccessThoughReferenceOfCurrentClass = underlyingClass.IsTypeInInheritanceTree(callingClass);
            }
            return(GetAccessibleMembers(rt, callingClass, language, isAccessThoughReferenceOfCurrentClass));
        }
Exemplo n.º 43
0
		public void AddAllContents(List<ICompletionEntry> list, LanguageProperties language, bool lookInReferences)
		{
			throw new NotImplementedException();
		}
Exemplo n.º 44
0
		public void AddNamespaceContents(List<ICompletionEntry> list, string subNameSpace, LanguageProperties language, bool lookInReferences)
		{
			throw new NotImplementedException();
		}
Exemplo n.º 45
0
		public bool NamespaceExists(string name, LanguageProperties language, bool lookInReferences)
		{
			throw new NotImplementedException();
		}
Exemplo n.º 46
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) {
					// don't use d.Add(), the new name language might treat two names as equal
					// that were unequal in the old dictionary
					d[pair.Key] = pair.Value;
				}
			} else {
				d = new Dictionary<string, IClass>(language.NameComparer);
			}
			classLists.Add(d);
			return d;
		}
		void SetProjectCodeDomProvider(LanguageProperties languageProperties)
		{
			fakeProject.Stub(p => p.LanguageProperties).Return(languageProperties);
		}
Exemplo n.º 48
0
        public IClass GetClass(string typeName, int typeParameterCount, LanguageProperties language, GetClassOptions options)
        {
            IClass c = GetClassInternal(typeName, typeParameterCount, language);

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

            // Search in references:
            if ((options & GetClassOptions.LookInReferences) != 0)
            {
                lock (referencedContents) {
                    foreach (IProjectContent content in referencedContents)
                    {
                        // Look for the class in the referenced content.
                        // Don't do a inner-class search in the recursive call - one search
                        // done by this GetClass call is sufficient.
                        IClass contentClass = content.GetClass(
                            typeName, typeParameterCount, language,
                            options & ~(GetClassOptions.LookInReferences | GetClassOptions.LookForInnerClass));
                        if (contentClass != null)
                        {
                            if (contentClass.TypeParameters.Count == typeParameterCount &&
                                IsAccessibleClass(contentClass))
                            {
                                return(contentClass);
                            }
                            else
                            {
                                c = contentClass;
                            }
                        }
                    }
                }
            }

            if ((options & GetClassOptions.LookForInnerClass) != 0)
            {
                // 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 = GetClass(outerName, typeParameterCount, language, options);
                    if (upperClass != null)
                    {
                        foreach (IClass upperBaseClass in upperClass.ClassInheritanceTree)
                        {
                            IList <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))
                                    {
                                        if (innerClass.TypeParameters.Count == typeParameterCount)
                                        {
                                            return(innerClass);
                                        }
                                        else
                                        {
                                            // store match
                                            c = innerClass;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if ((options & GetClassOptions.ExactMatch) == GetClassOptions.ExactMatch)
            {
                return(null);
            }
            else
            {
                // no matching class found - we'll return a class with different type paramter count
                return(c);
            }
        }
Exemplo n.º 49
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) {
					NamespaceStruct ns;
					if (d.TryGetValue(pair.Key, out ns)) {
						// we got a name conflict due to the new NameComparer.
						// This happens if a C# assembly contains the namespace "a" and "A",
						// and now we're trying to get a dictionary for use in VB.
						d[pair.Key] = ns.MergeWith(pair.Value);
					} else {
						d.Add(pair.Key, pair.Value);
					}
				}
			} else {
				d = new Dictionary<string, NamespaceStruct>(language.NameComparer);
			}
			namespaces.Add(d);
			return d;
		}
Exemplo n.º 50
0
        void AddNamespaceStructContents(List <ICompletionEntry> list, NamespaceStruct ns, LanguageProperties language, bool lookInReferences)
        {
            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)
            {
                NamespaceEntry subnsEntry = new NamespaceEntry(subns);
                if (!list.Contains(subnsEntry))                 // PERF
                {
                    list.Add(subnsEntry);
                }
            }
        }
Exemplo n.º 51
0
		protected IClass GetClassInternal(string typeName, int typeParameterCount, LanguageProperties language)
		{
			CheckNotDisposed();
			#if DEBUG
			if (System.Text.RegularExpressions.Regex.IsMatch (typeName, "`[0-9]+$"))
				Debug.Assert(false, "how did a Reflection type name get here?");
			#endif
			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;
			}
		}
Exemplo n.º 52
0
        public static IList <IMethodOrProperty> FindAllExtensions(LanguageProperties language, IClass callingClass)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }
            if (callingClass == null)
            {
                throw new ArgumentNullException("callingClass");
            }

            HashSet <IMethodOrProperty> res = new HashSet <IMethodOrProperty>();

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

            if (supportsExtensionMethods || supportsExtensionProperties)
            {
                ArrayList list        = new ArrayList();
                IMethod   dummyMethod = new DefaultMethod("dummy", callingClass.ProjectContent.SystemTypes.Void,
                                                          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)
                {
                    IMethodOrProperty mp = o as IMethodOrProperty;
                    if (mp != null && mp.IsExtensionMethod &&
                        (supportsExtensionMethods && o is IMethod || supportsExtensionProperties && o is IProperty))
                    {
                        res.Add(mp);
                    }
                    else if (searchExtensionsInClasses && o is IClass)
                    {
                        IClass c = o as IClass;
                        if (c.HasExtensionMethods)
                        {
                            if (supportsExtensionProperties)
                            {
                                foreach (IProperty p in c.Properties)
                                {
                                    if (p.IsExtensionMethod)
                                    {
                                        res.Add(p);
                                    }
                                }
                            }
                            if (supportsExtensionMethods)
                            {
                                foreach (IMethod m in c.Methods)
                                {
                                    if (m.IsExtensionMethod)
                                    {
                                        res.Add(m);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(res.ToList());
        }
Exemplo n.º 53
0
		public IClass GetClass(string typeName, int typeParameterCount, LanguageProperties language, GetClassOptions options)
		{
			IClass c = GetClassInternal(typeName, typeParameterCount, language);
			if (c != null && c.TypeParameters.Count == typeParameterCount) {
				return c;
			}
			
			// Search in references:
			if ((options & GetClassOptions.LookInReferences) != 0) {
				lock (referencedContents) {
					foreach (IProjectContent content in referencedContents) {
						// Look for the class in the referenced content.
						// Don't do a inner-class search in the recursive call - one search
						// done by this GetClass call is sufficient.
						IClass contentClass = content.GetClass(
							typeName, typeParameterCount, language,
							options & ~(GetClassOptions.LookInReferences | GetClassOptions.LookForInnerClass));
						if (contentClass != null) {
							if (contentClass.TypeParameters.Count == typeParameterCount
							    && IsAccessibleClass(contentClass))
							{
								return contentClass;
							} else {
								c = contentClass;
							}
						}
					}
				}
			}
			
			if ((options & GetClassOptions.LookForInnerClass) != 0) {
				// 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 = GetClass(outerName, typeParameterCount, language, options);
					if (upperClass != null) {
						foreach (IClass upperBaseClass in upperClass.ClassInheritanceTree) {
							IList<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)) {
										if (innerClass.TypeParameters.Count == typeParameterCount) {
											return innerClass;
										} else {
											// store match
											c = innerClass;
										}
									}
								}
							}
						}
					}
				}
			}
			if ((options & GetClassOptions.ExactMatch) == GetClassOptions.ExactMatch) {
				return null;
			} else {
				// no matching class found - we'll return a class with different type paramter count
				return c;
			}
		}
		public IClass GetClass(string typeName, int typeParameterCount, LanguageProperties language, GetClassOptions options)
		{
			IClass c = GetClassInternal(typeName, typeParameterCount, language);
			if (c != null && c.TypeParameters.Count == typeParameterCount) {
				return c;
			}
			
			// Search in references:
			if ((options & GetClassOptions.LookInReferences) != 0) {
				lock (referencedContents) {
					foreach (IProjectContent content in referencedContents) {
						IClass contentClass = content.GetClass(typeName, typeParameterCount, language, GetClassOptions.None);
						if (contentClass != null) {
							if (contentClass.TypeParameters.Count == typeParameterCount
							    && IsAccessibleClass(contentClass))
							{
								return contentClass;
							} else {
								c = contentClass;
							}
						}
					}
				}
			}
			
			if (c != null) {
				return c;
			}
			
			if ((options & GetClassOptions.LookForInnerClass) != 0) {
				// 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 = GetClass(outerName, typeParameterCount, language, options);
					if (upperClass != null) {
						foreach (IClass upperBaseClass in upperClass.ClassInheritanceTree) {
							IList<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;
		}
Exemplo n.º 55
0
		/// <summary>
		/// Adds the contents of all namespaces in this project to the <paramref name="list"/>.
		/// </summary>
		/// <param name="lookInReferences">If true, contents of referenced projects will be added as well (not recursive - just 1 level deep).</param>
		public void AddAllContents(List<ICompletionEntry> list, LanguageProperties language, bool lookInReferences)
		{
			if (lookInReferences) {
				lock (referencedContents) {
					foreach (IProjectContent content in referencedContents) {
						content.AddAllContents(list, language, false);
					}
				}
			}
			lock (namespaces) {
				Dictionary<string, NamespaceStruct> dict = GetNamespaces(language);
				foreach (var namespaceStruct in dict.Values) {
					AddNamespaceStructContents(list, namespaceStruct, language, lookInReferences);
				}
			}
		}
Exemplo n.º 56
0
		static void SearchAllClassesWithName(List<IClass> searchResults, IProjectContent pc, string name, LanguageProperties language)
		{
			foreach (string ns in pc.NamespaceNames) {
				IClass c = pc.GetClass(ns + "." + name, 0, language, GetClassOptions.None);
				if (c != null)
					searchResults.Add(c);
			}
		}
Exemplo n.º 57
0
		public IClass GetClass(string typeName, int typeParameterCount, LanguageProperties language, GetClassOptions options)
		{
			throw new NotImplementedException();
		}