Пример #1
0
        /// <summary>
        /// Swap base to this unless local implementation.
        /// </summary>
        /// <param name="invocationExpression">
        /// The invocation expression.
        /// </param>
        public static void SwapBaseToThisUnlessLocalImplementation(IInvocationExpression invocationExpression)
        {
            bool isOverride = false;

            bool isNew = false;

            IPrimaryExpression invokedExpression = invocationExpression.InvokedExpression;

            if (invokedExpression != null)
            {
                IReferenceExpression referenceExpressionNode = invokedExpression as IReferenceExpression;

                if (referenceExpressionNode != null)
                {
                    IReferenceExpression referenceExpression = invokedExpression as IReferenceExpression;
                    if (referenceExpression != null)
                    {
                        ICSharpExpression qualifierExpression = referenceExpression.QualifierExpression;
                        if (qualifierExpression is IBaseExpression)
                        {
                            string methodName = referenceExpressionNode.NameIdentifier.Name;

                            ICSharpTypeDeclaration typeDeclaration = invocationExpression.GetContainingNode <ICSharpTypeDeclaration>(true);

                            if (typeDeclaration != null)
                            {
                                foreach (ICSharpTypeMemberDeclaration memberDeclaration in typeDeclaration.MemberDeclarations)
                                {
                                    if (memberDeclaration.DeclaredName == methodName)
                                    {
                                        IMethodDeclaration methodDeclaration = memberDeclaration as IMethodDeclaration;
                                        if (methodDeclaration != null)
                                        {
                                            isOverride = methodDeclaration.IsOverride;
                                            isNew      = methodDeclaration.IsNew();
                                            break;
                                        }
                                    }
                                }

                                if (isOverride || isNew)
                                {
                                    return;
                                }

                                using (WriteLockCookie.Create(true))
                                {
                                    // swap the base to this
                                    ICSharpExpression expression = CSharpElementFactory.GetInstance(invocationExpression.GetPsiModule()).CreateExpression("this");

                                    referenceExpression.SetQualifierExpression(expression);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Swap reference expression to built in type.
        /// </summary>
        /// <param name="referenceExpression">
        /// The reference expression.
        /// </param>
        private static void SwapReferenceExpressionToBuiltInType(IReferenceExpression referenceExpression)
        {
            IPsiModule        project             = referenceExpression.GetPsiModule();
            ICSharpExpression qualifierExpression = referenceExpression.QualifierExpression;

            if (qualifierExpression != null)
            {
                using (WriteLockCookie.Create(true))
                {
                    foreach (string[] builtInType in BuiltInTypes)
                    {
                        string text = qualifierExpression.GetText();
                        if (text == builtInType[0] || text == builtInType[1])
                        {
                            ICSharpExpression expression = CSharpElementFactory.GetInstance(project).CreateExpression(builtInType[2], new object[0]);
                            referenceExpression.SetQualifierExpression(expression);
                            break;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Swap reference expression to built in type.
        /// </summary>
        /// <param name="referenceExpression">
        /// The reference expression.
        /// </param>
        private static void SwapReferenceExpressionToBuiltInType(IReferenceExpression referenceExpression)
        {
            IPsiModule project = referenceExpression.GetPsiModule();
            ICSharpExpression qualifierExpression = referenceExpression.QualifierExpression;

            if (qualifierExpression != null)
            {
                using (WriteLockCookie.Create(true))
                {
                    foreach (string[] builtInType in BuiltInTypes)
                    {
                        string text = qualifierExpression.GetText();
                        if (text == builtInType[0] || text == builtInType[1])
                        {
                            ICSharpExpression expression = CSharpElementFactory.GetInstance(project).CreateExpression(builtInType[2], new object[0]);
                            referenceExpression.SetQualifierExpression(expression);
                            break;
                        }
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Swap base to this unless local implementation.
        /// </summary>
        /// <param name="invocationExpression">
        /// The invocation expression.
        /// </param>
        public static void SwapBaseToThisUnlessLocalImplementation(IInvocationExpression invocationExpression)
        {
            bool isOverride = false;

            bool isNew = false;

            IPrimaryExpression invokedExpression = invocationExpression.InvokedExpression;

            if (invokedExpression == null)
            {
                return;
            }

            IReferenceExpression referenceExpression = invokedExpression as IReferenceExpression;

            if (referenceExpression == null)
            {
                return;
            }

            ICSharpExpression qualifierExpression = referenceExpression.QualifierExpression;

            if (!(qualifierExpression is IBaseExpression))
            {
                return;
            }

            ICSharpTypeDeclaration typeDeclaration = invocationExpression.GetContainingNode <ICSharpTypeDeclaration>(true);

            if (typeDeclaration == null)
            {
                return;
            }

            ITypeElement typeDeclaredElement = typeDeclaration.DeclaredElement;

            if (typeDeclaredElement == null)
            {
                return;
            }

            IDeclaredElement referenceDeclaredElement = referenceExpression.Reference.Resolve().DeclaredElement;

            if (referenceDeclaredElement == null)
            {
                return;
            }

            foreach (var member in typeDeclaredElement.GetAllClassMembers(referenceDeclaredElement.ShortName))
            {
                if (!member.Equals(referenceDeclaredElement))
                {
                    continue;
                }

                using (WriteLockCookie.Create(true))
                {
                    // swap the base to this
                    ICSharpExpression expression = CSharpElementFactory.GetInstance(invocationExpression.GetPsiModule()).CreateExpression("this");

                    referenceExpression.SetQualifierExpression(expression);
                }
            }
        }