Beispiel #1
0
        /// <summary>
        /// Swap to built in type alias.
        /// </summary>
        /// <param name="node">
        /// The node to process.
        /// </param>
        public static void SwapToBuiltInTypeAlias(ITreeNode node)
        {
            for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling)
            {
                ITypeArgumentList typeArgumentListNode = currentNode as ITypeArgumentList;
                if (typeArgumentListNode != null)
                {
                    SwapGenericDeclarationToBuiltInType(typeArgumentListNode);
                }
                else
                {
                    IMethodDeclaration methodDeclarationNode = currentNode as IMethodDeclaration;
                    if (methodDeclarationNode != null)
                    {
                        SwapReturnTypeToBuiltInType(methodDeclarationNode);
                    }
                    else
                    {
                        IVariableDeclaration variableDeclaration = currentNode as IVariableDeclaration;
                        if (variableDeclaration != null)
                        {
                            SwapVariableDeclarationToBuiltInType(variableDeclaration);
                        }
                        else
                        {
                            IObjectCreationExpression creationExpressionNode = currentNode as IObjectCreationExpression;
                            if (creationExpressionNode != null)
                            {
                                //// No need to call this now and its messing up nested {}
                                //// SwapObjectCreationToBuiltInType(creationExpressionNode);
                            }
                            else
                            {
                                IArrayCreationExpression arrayCreationNode = currentNode as IArrayCreationExpression;
                                if (arrayCreationNode != null)
                                {
                                    SwapArrayCreationToBuiltInType(arrayCreationNode);
                                }
                                else
                                {
                                    IReferenceExpression referenceExpressionNode = currentNode as IReferenceExpression;
                                    if (referenceExpressionNode != null)
                                    {
                                        SwapReferenceExpressionToBuiltInType(referenceExpressionNode);
                                    }
                                }
                            }
                        }
                    }
                }

                if (currentNode != null && currentNode.FirstChild != null)
                {
                    SwapToBuiltInTypeAlias(currentNode.FirstChild);
                }
            }
        }
        /// <summary>
        /// The execute transaction inner.
        /// </summary>
        /// <param name="solution">
        /// The solution.
        /// </param>
        /// <param name="textControl">
        /// The text control.
        /// </param>
        public override void ExecuteTransactionInner(ISolution solution, ITextControl textControl)
        {
            IList <ITokenNode> tokensForLine = Utils.GetTokensForLineFromTextControl(solution, textControl);

            foreach (ITokenNode tokenNode in tokensForLine)
            {
                ITypeArgumentList typeArgumentListNode = tokenNode.GetContainingNode <ITypeArgumentList>(true);

                if (typeArgumentListNode != null)
                {
                    ReadabilityRules.SwapToBuiltInTypeAlias(typeArgumentListNode);
                }

                IObjectCreationExpression objectCreationExpressionNode = tokenNode.GetContainingNode <IObjectCreationExpression>(true);

                if (objectCreationExpressionNode != null)
                {
                    ReadabilityRules.SwapToBuiltInTypeAlias(objectCreationExpressionNode);
                }

                IArrayCreationExpression arrayCreationExpressionNode = tokenNode.GetContainingNode <IArrayCreationExpression>(true);

                if (arrayCreationExpressionNode != null)
                {
                    ReadabilityRules.SwapToBuiltInTypeAlias(arrayCreationExpressionNode);
                }

                IMethodDeclaration methodDeclaration = tokenNode.GetContainingNode <IMethodDeclaration>(true);

                if (methodDeclaration != null)
                {
                    ReadabilityRules.SwapToBuiltInTypeAlias(methodDeclaration);
                }

                IVariableDeclaration variableDeclaration = tokenNode.GetContainingNode <IVariableDeclaration>(true);

                if (variableDeclaration != null)
                {
                    ReadabilityRules.SwapToBuiltInTypeAlias(variableDeclaration);
                }

                IMultipleDeclaration multipleDeclarationNode = tokenNode.GetContainingNode <IMultipleDeclaration>(true);

                if (multipleDeclarationNode != null)
                {
                    ReadabilityRules.SwapToBuiltInTypeAlias(multipleDeclarationNode);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Swap generic declaration to built in type.
        /// </summary>
        /// <param name="node">
        /// The node to process.
        /// </param>
        private static void SwapGenericDeclarationToBuiltInType(ITypeArgumentList node)
        {
            IPsiModule         project        = node.GetPsiModule();
            IList <ITypeUsage> typeUsageNodes = node.TypeArgumentNodes;
            IList <IType>      types          = node.TypeArguments;

            using (WriteLockCookie.Create(true))
            {
                for (int i = 0; i < typeUsageNodes.Count; i++)
                {
                    if (!types[i].IsUnknown)
                    {
                        ITypeUsage newTypeUsageNode = CSharpElementFactory.GetInstance(project).CreateTypeUsageNode(types[i]);

                        using (WriteLockCookie.Create(true))
                        {
                            ModificationUtil.ReplaceChild(typeUsageNodes[i], newTypeUsageNode);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Swap generic declaration to built in type.
        /// </summary>
        /// <param name="node">
        /// The node to process.
        /// </param>
        private static void SwapGenericDeclarationToBuiltInType(ITypeArgumentList node)
        {
            IPsiModule project = node.GetPsiModule();
            IList<ITypeUsage> typeUsageNodes = node.TypeArgumentNodes;
            IList<IType> types = node.TypeArguments;

            using (WriteLockCookie.Create(true))
            {
                for (int i = 0; i < typeUsageNodes.Count; i++)
                {
                    if (!types[i].IsUnknown)
                    {
                        ITypeUsage newTypeUsageNode = CSharpElementFactory.GetInstance(project).CreateTypeUsageNode(types[i]);

                        using (WriteLockCookie.Create(true))
                        {
                            ModificationUtil.ReplaceChild(typeUsageNodes[i], newTypeUsageNode);
                        }
                    }
                }
            }
        }