예제 #1
0
        public static void AddContentsFromCalling(ArrayList result, IClass callingClass, IMember callingMember)
        {
            IMethodOrProperty methodOrProperty = callingMember as IMethodOrProperty;

            if (methodOrProperty != null)
            {
                foreach (IParameter p in methodOrProperty.Parameters)
                {
                    result.Add(new DefaultField.ParameterField(p.ReturnType, p.Name, methodOrProperty.Region, callingClass));
                }
                if (callingMember is IMethod)
                {
                    AddTypeParametersForCtrlSpace(result, ((IMethod)callingMember).TypeParameters);
                }
            }

            bool inStatic = false;

            if (callingMember != null)
            {
                inStatic = callingMember.IsStatic;
            }

            if (callingClass != null)
            {
                AddTypeParametersForCtrlSpace(result, callingClass.TypeParameters);

                ArrayList   members = new ArrayList();
                IReturnType t       = callingClass.DefaultReturnType;
                members.AddRange(t.GetMethods());
                members.AddRange(t.GetFields());
                members.AddRange(t.GetEvents());
                members.AddRange(t.GetProperties());
                foreach (IMember m in members)
                {
                    if ((!inStatic || m.IsStatic) && m.IsAccessible(callingClass, true))
                    {
                        result.Add(m);
                    }
                }
                members.Clear();
                IClass c = callingClass.DeclaringType;
                while (c != null)
                {
                    t = c.DefaultReturnType;
                    members.AddRange(t.GetMethods());
                    members.AddRange(t.GetFields());
                    members.AddRange(t.GetEvents());
                    members.AddRange(t.GetProperties());
                    c = c.DeclaringType;
                }
                foreach (IMember m in members)
                {
                    if (m.IsStatic)
                    {
                        result.Add(m);
                    }
                }
            }
        }
예제 #2
0
 ResolveResult ResolveMethod(IReturnType type, string identifier)
 {
     if (type == null)
     {
         return(null);
     }
     foreach (IMethod method in type.GetMethods())
     {
         if (IsSameName(identifier, method.Name))
         {
             return(new MethodResolveResult(callingClass, callingMember, type, identifier));
         }
     }
     if (languageProperties.SupportsExtensionMethods && callingClass != null)
     {
         ArrayList list = new ArrayList();
         ResolveResult.AddExtensions(languageProperties, list, callingClass, type);
         foreach (IMethodOrProperty mp in list)
         {
             if (mp is IMethod && IsSameName(mp.Name, identifier))
             {
                 return(new MethodResolveResult(callingClass, callingMember, type, identifier));
             }
         }
     }
     return(null);
 }
예제 #3
0
		void AddMethodsFromBaseType(List<IMethod> l, IReturnType baseType)
		{
			if (baseType != null) {
				foreach (IMethod m in baseType.GetMethods()) {
					if (m.IsConstructor)
						continue;
					
					bool ok = true;
					if (m.IsOverridable) {
						StringComparer comparer = m.DeclaringType.ProjectContent.Language.NameComparer;
						foreach (IMethod oldMethod in c.Methods) {
							if (comparer.Equals(oldMethod.Name, m.Name)) {
								if (m.IsStatic == oldMethod.IsStatic && object.Equals(m.ReturnType, oldMethod.ReturnType)) {
									if (DiffUtility.Compare(oldMethod.Parameters, m.Parameters) == 0) {
										ok = false;
										break;
									}
								}
							}
						}
					}
					if (ok)
						l.Add(m);
				}
			}
		}
예제 #4
0
        void AddMethodsFromBaseType(List <IMethod> l, IReturnType baseType)
        {
            if (baseType != null)
            {
                foreach (IMethod m in baseType.GetMethods())
                {
                    if (m.IsConstructor)
                    {
                        continue;
                    }

                    /*bool ok = true;
                     * if (m.IsOverridable) {
                     *      StringComparer comparer = m.DeclaringType.ProjectContent.Language.NameComparer;
                     *      foreach (IMethod oldMethod in c.Methods) {
                     *              if (comparer.Equals(oldMethod.Name, m.Name)) {
                     *                      if (m.IsStatic == oldMethod.IsStatic && object.Equals(m.ReturnType, oldMethod.ReturnType)) {
                     *                              if (DiffUtility.Compare(oldMethod.Parameters, m.Parameters) == 0) {
                     *                                      ok = false;
                     *                                      break;
                     *                              }
                     *                      }
                     *              }
                     *      }
                     * }
                     * if (ok)
                     *      l.Add(m);*/
                    l.Add(m);
                }
            }
        }
예제 #5
0
        MemberResolveResult ResolveProperty(string xmlNamespace, string className, string propertyName, bool allowAttached)
        {
            IProjectContent pc           = parseInfo.BestCompilationUnit.ProjectContent;
            IReturnType     resolvedType = XamlCompilationUnit.FindType(pc, xmlNamespace, className);

            if (resolvedType != null && resolvedType.GetUnderlyingClass() != null)
            {
                IMember member = resolvedType.GetProperties().Find(delegate(IProperty p) { return(p.Name == propertyName); });
                if (member == null)
                {
                    member = resolvedType.GetEvents().Find(delegate(IEvent p) { return(p.Name == propertyName); });
                }
                if (member == null && allowAttached)
                {
                    member = resolvedType.GetMethods().Find(
                        delegate(IMethod p) {
                        return(p.IsStatic && p.Parameters.Count == 1 && p.Name == "Get" + propertyName);
                    });
                }
                if (member != null)
                {
                    return(new MemberResolveResult(callingClass, null, member));
                }
            }
            return(null);
        }
예제 #6
0
        public static void AddUsing(ArrayList result, IUsing u, IProjectContent projectContent)
        {
            if (u == null)
            {
                return;
            }
            bool importNamespaces = projectContent.Language.ImportNamespaces;
            bool importClasses    = projectContent.Language.CanImportClasses;

            foreach (string name in u.Usings)
            {
                if (importClasses)
                {
                    IClass c = projectContent.GetClass(name, 0);
                    if (c != null)
                    {
                        ArrayList   members = new ArrayList();
                        IReturnType t       = c.DefaultReturnType;
                        members.AddRange(t.GetMethods());
                        members.AddRange(t.GetFields());
                        members.AddRange(t.GetEvents());
                        members.AddRange(t.GetProperties());
                        foreach (IMember m in members)
                        {
                            if (m.IsStatic && m.IsPublic)
                            {
                                result.Add(m);
                            }
                        }
                        continue;
                    }
                }
                if (importNamespaces)
                {
                    string newName = null;
                    if (projectContent.DefaultImports != null)
                    {
                        newName = projectContent.DefaultImports.SearchNamespace(name);
                    }
                    projectContent.AddNamespaceContents(result, newName ?? name, projectContent.Language, true);
                }
                else
                {
                    foreach (object o in projectContent.GetNamespaceContents(name))
                    {
                        if (!(o is string))
                        {
                            result.Add(o);
                        }
                    }
                }
            }
            if (u.HasAliases)
            {
                foreach (string alias in u.Aliases.Keys)
                {
                    result.Add(alias);
                }
            }
        }
예제 #7
0
        void ResolveMethodInType(IReturnType containingType, string methodName, ExpressionCollection arguments)
        {
            List <IMethod> methods = new List <IMethod>();
            bool           isClassInInheritanceTree = false;

            if (callingClass != null)
            {
                isClassInInheritanceTree = callingClass.IsTypeInInheritanceTree(containingType.GetUnderlyingClass());
            }

            foreach (IMethod m in containingType.GetMethods())
            {
                if (IsSameName(m.Name, methodName) &&
                    m.IsAccessible(callingClass, isClassInInheritanceTree)
                    )
                {
                    methods.Add(m);
                }
            }
            if (methods.Count == 0)
            {
                ArrayList list = new ArrayList();
                ResolveResult.AddExtensions(callingClass.ProjectContent.Language, list, callingClass, containingType);
                foreach (IMethodOrProperty mp in list)
                {
                    if (IsSameName(mp.Name, methodName) && mp is IMethod)
                    {
                        IMethod m = (IMethod)mp.CreateSpecializedMember();
                        m.Parameters.RemoveAt(0);
                        methods.Add(m);
                    }
                }
            }
            ResolveInvocation(methods, arguments);
        }
예제 #8
0
        internal ResolveResult ResolveConstructorOverload(IReturnType rt, List <Expression> arguments)
        {
            if (rt == null)
            {
                return(null);
            }

            List <IMethod> methods = rt.GetMethods().Where(m => m.IsConstructor && !m.IsStatic).ToList();

            IReturnType[] argumentTypes = arguments.Select <Expression, IReturnType>(ResolveType).ToArray();
            bool          resultIsAcceptable;
            IMethod       result = MemberLookupHelper.FindOverload(methods, argumentTypes, out resultIsAcceptable);

            if (result == null)
            {
                IClass c = rt.GetUnderlyingClass();
                if (c != null)
                {
                    result = Constructor.CreateDefault(c);
                }
            }
            ResolveResult rr = CreateMemberResolveResult(result);

            if (rr != null)
            {
                rr.ResolvedType = rt;
            }
            return(rr);
        }
예제 #9
0
        public virtual List <IMethod> GetMethods()
        {
            IReturnType    baseType = BaseType;
            List <IMethod> tmp      = (baseType != null && TryEnter()) ? baseType.GetMethods() : new List <IMethod>();

            _busy = false;
            return(tmp);
        }
예제 #10
0
        public virtual List <IMethod> GetMethods()
        {
            IReturnType baseType = BaseType;

            using (var l = busyManager.Enter(this)) {
                return((l.Success && baseType != null) ? baseType.GetMethods() : new List <IMethod>());
            }
        }
예제 #11
0
 bool IsCollectionType(IReturnType rt)
 {
     if (rt == null)
     {
         return(false);
     }
     return(rt.GetMethods().Any(m => m.Name == "Add" && m.IsPublic));
 }
예제 #12
0
        public static IEnumerable <IMember> GetMembers(this IReturnType typeReference)
        {
            var properties = typeReference.GetProperties().Cast <IMember>();
            var methods    = typeReference.GetMethods().Cast <IMember>();
            var fields     = typeReference.GetFields().Cast <IMember>();
            var events     = typeReference.GetEvents().Cast <IMember>();

            return(properties.Concat(methods).Concat(fields).Concat(events));
        }
        public static List <IMember> GetAllMembers(IReturnType rt)
        {
            List <IMember> members = new List <IMember>();

            if (rt != null)
            {
                rt.GetMethods().ForEach(members.Add);
                rt.GetProperties().ForEach(members.Add);
                rt.GetFields().ForEach(members.Add);
                rt.GetEvents().ForEach(members.Add);
            }
            return(members);
        }
 IEnumerable <IMethod> GetConstructors(IReturnType rt)
 {
     // no need to add default constructor here:
     // default constructors should already be present in rt.GetMethods()
     if (rt == null)
     {
         return(Enumerable.Empty <IMethod>());
     }
     else
     {
         return(rt.GetMethods().Where(m => m.IsConstructor && !m.IsStatic));
     }
 }
예제 #15
0
        protected override void FixGeneratedCode(IClass formClass, CodeMemberMethod code)
        {
            base.FixGeneratedCode(formClass, code);
            Dictionary <string, IReturnType> variables = new Dictionary <string, IReturnType>();

            foreach (IField f in formClass.DefaultReturnType.GetFields())
            {
                variables[f.Name] = f.ReturnType;
            }
            variables[""] = formClass.DefaultReturnType;
            foreach (CodeStatement statement in code.Statements)
            {
                CodeExpressionStatement ces = statement as CodeExpressionStatement;
                if (ces != null)
                {
                    CodeMethodInvokeExpression cmie = ces.Expression as CodeMethodInvokeExpression;
                    if (cmie != null && cmie.Parameters.Count == 1)
                    {
                        CodeArrayCreateExpression cace = cmie.Parameters[0] as CodeArrayCreateExpression;
                        if (cace != null)
                        {
                            IReturnType rt = ResolveType(cmie.Method.TargetObject, variables);
                            if (rt != null)
                            {
                                foreach (IMethod m in rt.GetMethods())
                                {
                                    if (m.Name == cmie.Method.MethodName &&
                                        m.Parameters.Count == 1 &&
                                        m.Parameters[0].IsParams &&
                                        m.Parameters[0].ReturnType.IsArrayReturnType)
                                    {
                                        ArrayReturnType paramArt = m.Parameters[0].ReturnType.CastToArrayReturnType();
                                        if (paramArt.ArrayDimensions == 1 &&
                                            paramArt.FullyQualifiedName == cace.CreateType.BaseType)
                                        {
                                            cace.UserData["Explode"] = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                CodeVariableDeclarationStatement cvds = statement as CodeVariableDeclarationStatement;
                if (cvds != null)
                {
                    variables[cvds.Name] = new SearchClassReturnType(formClass.ProjectContent, formClass, formClass.Region.BeginLine + 1, 0, cvds.Type.BaseType, cvds.Type.TypeArguments.Count);
                }
            }
        }
예제 #16
0
        public IMethod GetMethodIfSingleOverload()
        {
            List <IMethod> methods = containingType.GetMethods();

            methods = methods.FindAll(delegate(IMethod m) { return(m.Name == this.Name); });
            if (methods.Count == 1)
            {
                return(methods[0]);
            }
            else
            {
                return(null);
            }
        }
예제 #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);
        }
예제 #18
0
 internal static IMethod GetDelegateOrExpressionTreeSignature(IReturnType rt, bool allowExpressionTree)
 {
     if (rt == null)
         return null;
     IClass c = rt.GetUnderlyingClass();
     if (allowExpressionTree && c != null && c.FullyQualifiedName == "System.Linq.Expressions.Expression") {
         ConstructedReturnType crt = rt.CastToConstructedReturnType();
         if (crt != null && crt.TypeArguments.Count == 1) {
             // get delegate type from expression type
             rt = crt.TypeArguments[0];
             c = rt != null ? rt.GetUnderlyingClass() : null;
         }
     }
     if (c != null && c.ClassType == ClassType.Delegate) {
         return rt.GetMethods().FirstOrDefault((IMethod m) => m.Name == "Invoke");
     }
     return null;
 }
예제 #19
0
        /// <summary>
        /// Gets the list of methods on the return type that have the specified name.
        /// </summary>
        public List <IMethod> SearchMethod(IReturnType type, string memberName)
        {
            List <IMethod> methods = new List <IMethod>();

            if (type == null)
            {
                return(methods);
            }

            bool isClassInInheritanceTree = false;

            if (callingClass != null)
            {
                isClassInInheritanceTree = callingClass.IsTypeInInheritanceTree(type.GetUnderlyingClass());
            }

            foreach (IMethod m in type.GetMethods())
            {
                if (IsSameName(m.Name, memberName) &&
                    m.IsAccessible(callingClass, isClassInInheritanceTree)
                    )
                {
                    methods.Add(m);
                }
            }
            if (methods.Count == 0)
            {
                if (languageProperties.SupportsExtensionMethods && callingClass != null)
                {
                    ArrayList list = new ArrayList();
                    ResolveResult.AddExtensions(languageProperties, list, callingClass, type);
                    foreach (IMethodOrProperty mp in list)
                    {
                        if (mp is IMethod && IsSameName(mp.Name, memberName))
                        {
                            methods.Add((IMethod)mp);
                        }
                    }
                }
            }

            return(methods);
        }
예제 #20
0
        public override List <IMethod> GetMethods()
        {
            List <IMethod> l = baseType.GetMethods();

            for (int i = 0; i < l.Count; ++i)
            {
                if (CheckReturnType(l[i].ReturnType) || CheckParameters(l[i].Parameters))
                {
                    l[i] = (IMethod)l[i].CreateSpecializedMember();
                    if (l[i].DeclaringType == baseType.GetUnderlyingClass())
                    {
                        l[i].DeclaringTypeReference = this;
                    }
                    l[i].ReturnType = TranslateType(l[i].ReturnType);
                    for (int j = 0; j < l[i].Parameters.Count; ++j)
                    {
                        l[i].Parameters[j].ReturnType = TranslateType(l[i].Parameters[j].ReturnType);
                    }
                }
            }
            return(l);
        }
예제 #21
0
        internal static IMethod GetDelegateOrExpressionTreeSignature(IReturnType rt, bool allowExpressionTree)
        {
            if (rt == null)
            {
                return(null);
            }
            IClass c = rt.GetUnderlyingClass();

            if (allowExpressionTree && c != null && c.FullyQualifiedName == "System.Linq.Expressions.Expression")
            {
                ConstructedReturnType crt = rt.CastToConstructedReturnType();
                if (crt != null && crt.TypeArguments.Count == 1)
                {
                    // get delegate type from expression type
                    rt = crt.TypeArguments[0];
                    c  = rt != null?rt.GetUnderlyingClass() : null;
                }
            }
            if (c != null && c.ClassType == ClassType.Delegate)
            {
                return(rt.GetMethods().FirstOrDefault((IMethod m) => m.Name == "Invoke"));
            }
            return(null);
        }
예제 #22
0
		/// <remarks>returns true if elements from named args completion should be added afterwards.</remarks>
		static bool DoPositionalArgsCompletion(XamlCompletionItemList list, XamlCompletionContext context, MarkupExtensionInfo markup, IReturnType type)
		{
			switch (type.FullyQualifiedName) {
				case "System.Windows.Markup.ArrayExtension":
				case "System.Windows.Markup.NullExtension":
					// x:Null/x:Array does not need completion, ignore it
					break;
				case "System.Windows.Markup.StaticExtension":
					if (context.AttributeValue.ExtensionValue.PositionalArguments.Count <= 1)
						return DoStaticExtensionCompletion(list, context);
					break;
				case "System.Windows.Markup.TypeExtension":
					if (context.AttributeValue.ExtensionValue.PositionalArguments.Count <= 1) {
						list.Items.AddRange(GetClassesFromContext(context).FlattenToList());
						AttributeValue selItem = Utils.GetMarkupExtensionAtPosition(context.AttributeValue.ExtensionValue, context.ValueStartOffset)
							.PositionalArguments.LastOrDefault();
						string word = context.Editor.GetWordBeforeCaret().TrimEnd();
						if (selItem != null && selItem.IsString && word == selItem.StringValue) {
							list.PreselectionLength = selItem.StringValue.Length;
						}
					}
					break;
				default:
					var ctors = type.GetMethods()
						.Where(m => m.IsPublic && m.IsConstructor && m.Parameters.Count >= markup.PositionalArguments.Count + 1);
					if (context.Forced)
						return true;
					if (ctors.Any() || markup.PositionalArguments.Count == 0)
						return false;
					break;
			}
			
			return true;
		}
예제 #23
0
		MemberResolveResult ResolvePropertyName(IReturnType resolvedType, string propertyName, bool allowAttached)
		{
			IMember member = resolvedType.GetProperties().Find(delegate(IProperty p) { return p.Name == propertyName; });
			if (member == null) {
				member = resolvedType.GetEvents().Find(delegate(IEvent p) { return p.Name == propertyName; });
			}
			if (member == null && allowAttached) {
				IMethod method = resolvedType.GetMethods().Find(
					delegate(IMethod p) {
						return p.IsStatic && p.Parameters.Count == 1 && p.Name == "Get" + propertyName;
					});
				member = method;
				if (member != null) {
					member = new DefaultProperty(resolvedType.GetUnderlyingClass(), propertyName) { ReturnType = method.ReturnType };
				} else {
					IMethod m = resolvedType.GetMethods().Find(
						delegate(IMethod p) {
							return p.IsPublic && p.IsStatic && p.Parameters.Count == 2 && (p.Name == "Add" + propertyName + "Handler" || p.Name == "Remove" + propertyName + "Handler");
						});
					member = m;
					if (member != null)
						member = new DefaultEvent(resolvedType.GetUnderlyingClass(), propertyName) { ReturnType = m.Parameters[1].ReturnType };
				}
			}
			if (member != null)
				return new MemberResolveResult(callingClass, null, member);
			return null;
		}
예제 #24
0
        public void MethodGroupContainingTypeHasTwoExitMethods()
        {
            IReturnType    returnType = MethodResolveResult.ContainingType;
            List <IMethod> methods    = PythonCompletionItemsHelper.FindAllMethodsFromCollection("exit", returnType.GetMethods());

            Assert.AreEqual(2, methods.Count);
        }
예제 #25
0
        MemberResolveResult ResolvePropertyName(IReturnType resolvedType, string propertyName, bool allowAttached)
        {
            IMember member = resolvedType.GetProperties().Find(delegate(IProperty p) { return(p.Name == propertyName); });

            if (member == null)
            {
                member = resolvedType.GetEvents().Find(delegate(IEvent p) { return(p.Name == propertyName); });
            }
            if (member == null && allowAttached)
            {
                IMethod method = resolvedType.GetMethods().Find(
                    delegate(IMethod p) {
                    return(p.IsStatic && p.Parameters.Count == 1 && p.Name == "Get" + propertyName);
                });
                member = method;
                if (member != null)
                {
                    member = new DefaultProperty(resolvedType.GetUnderlyingClass(), propertyName)
                    {
                        ReturnType = method.ReturnType
                    };
                }
                else
                {
                    IMethod m = resolvedType.GetMethods().Find(
                        delegate(IMethod p) {
                        return(p.IsPublic && p.IsStatic && p.Parameters.Count == 2 && (p.Name == "Add" + propertyName + "Handler" || p.Name == "Remove" + propertyName + "Handler"));
                    });
                    member = m;
                    if (member != null)
                    {
                        member = new DefaultEvent(resolvedType.GetUnderlyingClass(), propertyName)
                        {
                            ReturnType = m.Parameters[1].ReturnType
                        }
                    }
                    ;
                }
            }
            if (member != null)
            {
                return(new MemberResolveResult(callingClass, null, member));
            }
            return(null);
        }

        MemberResolveResult ResolveAttribute(string attributeName)
        {
            if (context.ActiveElement == null)
            {
                return(null);
            }
            string attributeXmlNamespace;

            if (attributeName.Contains(":"))
            {
                string prefix = attributeName.Substring(0, attributeName.IndexOf(':'));
                if (!context.XmlnsDefinitions.TryGetValue(prefix, out attributeXmlNamespace))
                {
                    attributeXmlNamespace = null;
                }
                attributeName = attributeName.Substring(attributeName.IndexOf(':') + 1);
            }
            else
            {
                if (!context.XmlnsDefinitions.TryGetValue("", out attributeXmlNamespace))
                {
                    attributeXmlNamespace = null;
                }
            }
            if (attributeName.Contains("."))
            {
                string className = attributeName.Substring(0, attributeName.IndexOf('.'));
                attributeName = attributeName.Substring(attributeName.IndexOf('.') + 1);
                return(ResolveProperty(attributeXmlNamespace, className, attributeName, true));
            }
            else
            {
                var lastElement = context.ActiveElement;
                return(ResolveProperty(lastElement.Namespace, lastElement.LocalName, attributeName, false));
            }
        }

        ResolveResult ResolveAttributeValue(IMember propertyOrEvent, string expression)
        {
            if (propertyOrEvent == null)
            {
                return(null);
            }
            if (propertyOrEvent is IEvent && callingClass != null)
            {
                return(new MethodGroupResolveResult(callingClass, null, callingClass.DefaultReturnType, expression));
            }
            else if (propertyOrEvent is IProperty && callingClass != null)
            {
                if (propertyOrEvent.Name == "Name")
                {
                    foreach (IField f in callingClass.Fields)
                    {
                        if (f.Name == expression)
                        {
                            return(new MemberResolveResult(callingClass, null, f));
                        }
                    }
                }
                return(ResolveElementName(expression));
            }

            IReturnType type = propertyOrEvent.ReturnType;

            if (type == null)
            {
                return(null);
            }
            IClass c = type.GetUnderlyingClass();

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

            if (c.ClassType == ClassType.Enum)
            {
                foreach (IField f in c.Fields)
                {
                    if (f.Name == expression)
                    {
                        return(new MemberResolveResult(callingClass, null, f));
                    }
                }
            }
            return(null);
        }
예제 #26
0
		bool ResolveMember(IReturnType type, string memberName)
		{
			ClearResult();
			if (type == null)
				return false;
			bool isClassInInheritanceTree = false;
			if (callingClass != null)
				isClassInInheritanceTree = callingClass.IsTypeInInheritanceTree(type.GetUnderlyingClass());
			foreach (IProperty p in type.GetProperties()) {
				if (IsSameName(p.Name, memberName)) {
					MakeResult(p);
					return true;
				}
			}
			foreach (IField f in type.GetFields()) {
				if (IsSameName(f.Name, memberName)) {
					MakeResult(f);
					return true;
				}
			}
			foreach (IEvent e in type.GetEvents()) {
				if (IsSameName(e.Name, memberName)) {
					MakeResult(e);
					return true;
				}
			}
			foreach (IMethod m in type.GetMethods()) {
				if (IsSameName(m.Name, memberName)) {
					MakeMethodResult(type, memberName);
					return true;
				}
			}
			if (callingClass != null) {
				List<IMethodOrProperty> list = new List<IMethodOrProperty>();
				ResolveResult.AddExtensions(callingClass.ProjectContent.Language, list.Add, callingClass, type);
				foreach (IMethodOrProperty mp in list) {
					if (IsSameName(mp.Name, memberName)) {
						if (mp is IMethod)
							MakeMethodResult(type, memberName);
						else
							MakeResult(mp);
						return true;
					}
				}
			}
			return false;
		}
예제 #27
0
		internal ResolveResult ResolveConstructorOverload(IReturnType rt, List<Expression> arguments)
		{
			if (rt == null)
				return null;
			
			List<IMethod> methods = rt.GetMethods().Where(m => m.IsConstructor && !m.IsStatic).ToList();
			IReturnType[] argumentTypes = arguments.Select<Expression, IReturnType>(ResolveType).ToArray();
			bool resultIsAcceptable;
			IMethod result = MemberLookupHelper.FindOverload(methods, argumentTypes, out resultIsAcceptable);
			
			ResolveResult rr = CreateMemberResolveResult(result);
			if (rr != null)
				rr.ResolvedType = rt;
			return rr;
		}
예제 #28
0
        bool ResolveMember(IReturnType type, string memberName)
        {
            ClearResult();
            if (type == null)
            {
                return(false);
            }
            bool isClassInInheritanceTree = false;

            if (callingClass != null)
            {
                isClassInInheritanceTree = callingClass.IsTypeInInheritanceTree(type.GetUnderlyingClass());
            }
            foreach (IProperty p in type.GetProperties())
            {
                if (IsSameName(p.Name, memberName))
                {
                    MakeResult(p);
                    return(true);
                }
            }
            foreach (IField f in type.GetFields())
            {
                if (IsSameName(f.Name, memberName))
                {
                    MakeResult(f);
                    return(true);
                }
            }
            foreach (IEvent e in type.GetEvents())
            {
                if (IsSameName(e.Name, memberName))
                {
                    MakeResult(e);
                    return(true);
                }
            }
            foreach (IMethod m in type.GetMethods())
            {
                if (IsSameName(m.Name, memberName))
                {
                    MakeMethodResult(type, memberName);
                    return(true);
                }
            }
            if (callingClass != null)
            {
                ArrayList list = new ArrayList();
                ResolveResult.AddExtensions(callingClass.ProjectContent.Language, list, callingClass, type);
                foreach (IMethodOrProperty mp in list)
                {
                    if (IsSameName(mp.Name, memberName))
                    {
                        if (mp is IMethod)
                        {
                            MakeMethodResult(type, memberName);
                        }
                        else
                        {
                            MakeResult(mp);
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #29
0
		IEnumerable<IMethod> GetConstructors(IReturnType rt)
		{
			// no need to add default constructor here:
			// default constructors should already be present in rt.GetMethods()
			if (rt == null)
				return Enumerable.Empty<IMethod>();
			else
				return rt.GetMethods().Where(m => m.IsConstructor && !m.IsStatic);
		}
        /// <summary>
        /// Adds the methods implementing the <paramref name="interf"/> to the list
        /// <paramref name="nodes"/>.
        /// </summary>
        public virtual void ImplementInterface(IList <AbstractNode> nodes, IReturnType interf, bool explicitImpl, IClass targetClass)
        {
            ClassFinder   context = new ClassFinder(targetClass, targetClass.Region.BeginLine + 1, 0);
            Modifiers     implicitImplModifier = ConvertModifier(ModifierEnum.Public, context);
            Modifiers     explicitImplModifier = ConvertModifier(context.Language.ExplicitInterfaceImplementationIsPrivateScope ? ModifierEnum.None : ModifierEnum.Public, context);
            List <IEvent> targetClassEvents    = targetClass.DefaultReturnType.GetEvents();
            bool          requireAlternativeImplementation;

            foreach (IEvent e in interf.GetEvents())
            {
                if (!InterfaceMemberAlreadyImplemented(targetClassEvents, e, out requireAlternativeImplementation))
                {
                    EventDeclaration ed = ConvertMember(e, context);
                    ed.Attributes.Clear();
                    if (explicitImpl || requireAlternativeImplementation)
                    {
                        ed.InterfaceImplementations.Add(CreateInterfaceImplementation(e, context));

                        if (context.Language.RequiresAddRemoveRegionInExplicitInterfaceImplementation)
                        {
                            ed.AddRegion          = new EventAddRegion(null);
                            ed.AddRegion.Block    = CreateNotImplementedBlock();
                            ed.RemoveRegion       = new EventRemoveRegion(null);
                            ed.RemoveRegion.Block = CreateNotImplementedBlock();
                        }

                        targetClassEvents.Add(CloneAndAddExplicitImpl(e, targetClass));
                        ed.Modifier = explicitImplModifier;
                    }
                    else
                    {
                        targetClassEvents.Add(e);
                        ed.Modifier = implicitImplModifier;
                    }
                    nodes.Add(ed);
                }
            }
            List <IProperty> targetClassProperties = targetClass.DefaultReturnType.GetProperties();

            foreach (IProperty p in interf.GetProperties())
            {
                if (!InterfaceMemberAlreadyImplemented(targetClassProperties, p, out requireAlternativeImplementation))
                {
                    AttributedNode pd = ConvertMember(p, context);
                    pd.Attributes.Clear();
                    if (explicitImpl || requireAlternativeImplementation)
                    {
                        InterfaceImplementation impl = CreateInterfaceImplementation(p, context);
                        if (pd is IndexerDeclaration)
                        {
                            ((IndexerDeclaration)pd).InterfaceImplementations.Add(impl);
                        }
                        else
                        {
                            ((PropertyDeclaration)pd).InterfaceImplementations.Add(impl);
                        }
                        targetClassProperties.Add(CloneAndAddExplicitImpl(p, targetClass));
                        pd.Modifier = explicitImplModifier;
                    }
                    else
                    {
                        targetClassProperties.Add(p);
                        pd.Modifier = implicitImplModifier;
                    }
                    nodes.Add(pd);
                }
            }
            List <IMethod> targetClassMethods = targetClass.DefaultReturnType.GetMethods();

            foreach (IMethod m in interf.GetMethods())
            {
                if (!InterfaceMemberAlreadyImplemented(targetClassMethods, m, out requireAlternativeImplementation))
                {
                    MethodDeclaration md = ConvertMember(m, context) as MethodDeclaration;
                    md.Attributes.Clear();
                    if (md != null)
                    {
                        if (explicitImpl || requireAlternativeImplementation)
                        {
                            md.InterfaceImplementations.Add(CreateInterfaceImplementation(m, context));
                            targetClassMethods.Add(CloneAndAddExplicitImpl(m, targetClass));
                            md.Modifier = explicitImplModifier;
                        }
                        else
                        {
                            targetClassMethods.Add(m);
                            md.Modifier = implicitImplModifier;
                        }
                        nodes.Add(md);
                    }
                }
            }
        }
예제 #31
0
		void ResolveMethodInType(IReturnType containingType, string methodName, ExpressionCollection arguments)
		{
			List<IMethod> methods = new List<IMethod>();
			bool isClassInInheritanceTree = false;
			if (callingClass != null)
				isClassInInheritanceTree = callingClass.IsTypeInInheritanceTree(containingType.GetUnderlyingClass());
			
			foreach (IMethod m in containingType.GetMethods()) {
				if (IsSameName(m.Name, methodName)
				    && m.IsAccessible(callingClass, isClassInInheritanceTree)
				   ) {
					methods.Add(m);
				}
			}
			if (methods.Count == 0) {
				List<IMethodOrProperty> list = new List<IMethodOrProperty>();
				ResolveResult.AddExtensions(callingClass.ProjectContent.Language, list.Add, callingClass, containingType);
				foreach (IMethodOrProperty mp in list) {
					if (IsSameName(mp.Name, methodName) && mp is IMethod) {
						IMethod m = (IMethod)mp.CreateSpecializedMember();
						m.Parameters.RemoveAt(0);
						methods.Add(m);
					}
				}
			}
			ResolveInvocation(methods, arguments);
		}