Example #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)
            {
                ITypeArgumentListNode typeArgumentListNode = currentNode as ITypeArgumentListNode;
                if (typeArgumentListNode != null)
                {
                    SwapGenericDeclarationToBuiltInType(typeArgumentListNode);
                }
                else
                {
                    IMethodDeclarationNode methodDeclarationNode = currentNode as IMethodDeclarationNode;
                    if (methodDeclarationNode != null)
                    {
                        SwapReturnTypeToBuiltInType(methodDeclarationNode);
                    }
                    else
                    {
                        IVariableDeclarationNode variableDeclaration = currentNode as IVariableDeclarationNode;
                        if (variableDeclaration != null)
                        {
                            SwapVariableDeclarationToBuiltInType(variableDeclaration);
                        }
                        else
                        {
                            IObjectCreationExpressionNode creationExpressionNode = currentNode as IObjectCreationExpressionNode;
                            if (creationExpressionNode != null)
                            {
                                SwapObjectCreationToBuiltInType(creationExpressionNode);
                            }
                            else
                            {
                                IArrayCreationExpressionNode arrayCreationNode = currentNode as IArrayCreationExpressionNode;
                                if (arrayCreationNode != null)
                                {
                                    SwapArrayCreationToBuiltInType(arrayCreationNode);
                                }
                                else
                                {
                                    IReferenceExpressionNode referenceExpressionNode = currentNode as IReferenceExpressionNode;
                                    if (referenceExpressionNode != null)
                                    {
                                        SwapReferenceExpressionToBuiltInType(referenceExpressionNode);
                                    }
                                }
                            }
                        }
                    }
                }

                if (currentNode != null && currentNode.FirstChild != null)
                {
                    SwapToBuiltInTypeAlias(currentNode.FirstChild);
                }
            }
        }
Example #2
0
        /// <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)
            {
                ITypeArgumentListNode typeArgumentListNode = tokenNode.GetContainingElement <ITypeArgumentListNode>(true);

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

                IObjectCreationExpressionNode objectCreationExpressionNode = tokenNode.GetContainingElement <IObjectCreationExpressionNode>(true);

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

                IArrayCreationExpressionNode arrayCreationExpressionNode = tokenNode.GetContainingElement <IArrayCreationExpressionNode>(true);

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

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

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

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

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

                IMultipleDeclarationNode multipleDeclarationNode = tokenNode.GetContainingElement <IMultipleDeclarationNode>(true);

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

            using (WriteLockCookie.Create(true))
            {
                for (int i = 0; i < typeUsageNodes.Count; i++)
                {
                    if (!types[i].IsUnknown)
                    {
                        ITypeUsageNode 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(ITypeArgumentListNode node)
        {
            IPsiModule project = node.GetPsiModule();
            IList<ITypeUsageNode> typeUsageNodes = node.TypeArgumentNodes;
            IList<IType> types = node.TypeArguments;

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

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