当前位置: 首页>>代码示例>>C#>>正文


C# IElement.GetPsiModule方法代码示例

本文整理汇总了C#中IElement.GetPsiModule方法的典型用法代码示例。如果您正苦于以下问题:C# IElement.GetPsiModule方法的具体用法?C# IElement.GetPsiModule怎么用?C# IElement.GetPsiModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IElement的用法示例。


在下文中一共展示了IElement.GetPsiModule方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReplaceReturnValue

        /// <summary>
        /// Actions the specified t.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        private void ReplaceReturnValue(IElement element)
        {
            var returnStatement = element as IReturnStatement;
              if (returnStatement == null)
              {
            return;
              }

              var value = returnStatement.Value;
              if (value == null)
              {
            return;
              }

              var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());
              if (factory == null)
              {
            return;
              }

              ICSharpExpression expression;

              var text = value.GetText();

              if (text == "true")
              {
            expression = factory.CreateExpression("false");
              }
              else if (text == "false")
              {
            expression = factory.CreateExpression("true");
              }
              else if (IsNotExpression(value))
              {
            var unaryOperatorExpression = (IUnaryOperatorExpression)value;

            text = unaryOperatorExpression.Operand.GetText();
            if (text.StartsWith("(") && text.EndsWith(")"))
            {
              text = text.Substring(1, text.Length - 2);
            }

            expression = factory.CreateExpression(text);
              }
              else
              {
            if (text.StartsWith("(") && text.EndsWith(")"))
            {
              text = text.Substring(1, text.Length - 2);
            }

            expression = factory.CreateExpression("!(" + text + ")");
              }

              if (expression == null)
              {
            return;
              }

              value.ReplaceBy(expression);
        }
开发者ID:xerxesb,项目名称:agentjohnsonplugin,代码行数:67,代码来源:InvertReturnValueRefactoring.cs

示例2: CheckAssignment

        /// <summary>
        /// Inserts the assert.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="anchor">
        /// The anchor.
        /// </param>
        /// <param name="name">
        /// The name.
        /// </param>
        private void CheckAssignment(IElement element, IStatement anchor, string name)
        {
            var functionDeclaration = anchor.GetContainingTypeMemberDeclaration() as IMethodDeclaration;
              if (functionDeclaration == null)
              {
            return;
              }

              var body = functionDeclaration.Body;
              if (body == null)
              {
            return;
              }

              var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());

              var csharpElement = element as ICSharpElement;
              if (csharpElement == null)
              {
            return;
              }

              var code = string.Format("if({0} == null) {{ }}", name);

              var statement = factory.CreateStatement(code);

              var result = body.AddStatementAfter(statement, anchor);

              var range = result.GetDocumentRange();
              var codeFormatter = new CodeFormatter();
              codeFormatter.Format(this.Solution, range);
        }
开发者ID:xerxesb,项目名称:agentjohnsonplugin,代码行数:44,代码来源:CheckAssignmentContextAction.cs

示例3: Execute

        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        protected override void Execute(IElement element)
        {
            var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());
              if (factory == null)
              {
            return;
              }

              var parent = element.ToTreeNode().Parent;
              if (parent == null)
              {
            return;
              }

              var classDeclaration = parent.Parent as IClassDeclaration;
              if (classDeclaration == null)
              {
            return;
              }

              classDeclaration.SetAbstract(false);

              var methodDeclarations = classDeclaration.MethodDeclarations;

              foreach (var methodDeclaration in methodDeclarations)
              {
            if (!methodDeclaration.IsAbstract)
            {
              continue;
            }

            methodDeclaration.SetAbstract(false);
            methodDeclaration.SetVirtual(true);

            if (methodDeclaration.Body != null)
            {
              continue;
            }

            var block = factory.CreateEmptyBlock();

            methodDeclaration.SetBody(block);

            CSharpMemberBodyUtil.Instance.SetBodyToDefault(methodDeclaration);
              }

              var propertyDeclarations = classDeclaration.PropertyDeclarations;

              foreach (var propertyDeclaration in propertyDeclarations)
              {
            if (!propertyDeclaration.IsAbstract)
            {
              continue;
            }

            propertyDeclaration.SetAbstract(false);
            propertyDeclaration.SetVirtual(true);

            foreach (var accessorDeclaration in propertyDeclaration.AccessorDeclarations)
            {
              if (accessorDeclaration.Body != null)
              {
            continue;
              }

              var block = factory.CreateEmptyBlock();

              accessorDeclaration.SetBody(block);

              CSharpPropertyBodyUtil.SetDefaultBody(accessorDeclaration);
            }
              }
        }
开发者ID:xerxesb,项目名称:agentjohnsonplugin,代码行数:79,代码来源:MakeVirtual.cs

示例4: InsertAssertionCode

        /// <summary>Inserts the assert.</summary>
        /// <param name="assertion">The assertion.</param>
        /// <param name="element">The element.</param>
        private void InsertAssertionCode(string assertion, IElement element)
        {
            IStatement anchor = null;
              string name;

              var assignmentExpression = element as IAssignmentExpression;
              if (assignmentExpression != null)
              {
            anchor = assignmentExpression.GetContainingStatement();

            var referenceExpression = assignmentExpression.Dest as IReferenceExpression;
            if (referenceExpression == null)
            {
              return;
            }

            name = referenceExpression.Reference.GetName();
              }
              else
              {
            var treeNode = element.ToTreeNode();

            while (treeNode != null)
            {
              anchor = treeNode as IStatement;

              if (anchor != null)
              {
            break;
              }

              treeNode = treeNode.Parent;
            }

            var localVariable = element as ILocalVariable;
            if (localVariable == null)
            {
              return;
            }

            name = localVariable.ShortName;
              }

              if (anchor == null)
              {
            return;
              }

              var functionDeclaration = anchor.GetContainingTypeMemberDeclaration() as IMethodDeclaration;
              if (functionDeclaration == null)
              {
            return;
              }

              var body = functionDeclaration.Body;
              if (body == null)
              {
            return;
              }

              var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());

              var csharpElement = element as ICSharpElement;
              if (csharpElement == null)
              {
            return;
              }

              var code = string.Format(assertion, name);

              var statement = factory.CreateStatement(code);
              if (statement == null)
              {
            return;
              }

              var result = body.AddStatementAfter(statement, anchor);

              var range = result.GetDocumentRange();
              var codeFormatter = new CodeFormatter();
              codeFormatter.Format(this.Solution, range);
        }
开发者ID:jamiebriant,项目名称:agentjohnson,代码行数:85,代码来源:AssertAssignmentContextAction.cs

示例5: GetExpressionNullReferenceState

        /// <summary>
        /// Gets the state.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="name">
        /// The variable name.
        /// </param>
        /// <returns>
        /// The null reference state.
        /// </returns>
        private static CSharpControlFlowNullReferenceState GetExpressionNullReferenceState(IElement element, string name)
        {
            const CSharpControlFlowNullReferenceState UNKNOWN = CSharpControlFlowNullReferenceState.UNKNOWN;

              var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());

              var statement = factory.CreateStatement("if(" + name + " == null) { }");
              var anchorSatement = StatementUtil.GetPreviousStatement(element);

              var block = element.GetContainingElement(typeof(IBlock), true) as IBlock;
              if (block == null)
              {
            return UNKNOWN;
              }

              var ifStatement = block.AddStatementAfter(statement, anchorSatement) as IIfStatement;
              if (ifStatement == null)
              {
            return UNKNOWN;
              }

              var equalityExpression = ifStatement.Condition as IEqualityExpression;
              if (equalityExpression == null)
              {
            return UNKNOWN;
              }

              var referenceExpression = equalityExpression.LeftOperand as IReferenceExpression;
              if (referenceExpression == null)
              {
            return UNKNOWN;
              }

              var functionDeclaration = ifStatement.GetContainingElement<ICSharpFunctionDeclaration>(true);
              if (functionDeclaration == null)
              {
            return UNKNOWN;
              }

              var graf = CSharpControlFlowBuilder.Build(functionDeclaration);

              var inspect = graf.Inspect(ValueAnalysisMode.OPTIMISTIC);

              return inspect.GetExpressionNullReferenceState(referenceExpression);
        }
开发者ID:xerxesb,项目名称:agentjohnsonplugin,代码行数:57,代码来源:AssignmentCheck.cs

示例6: Negate

        /// <summary>
        /// Reverses the specified element.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        private static void Negate(IElement element)
        {
            var ifStatement = element.GetContainingElement<IIfStatement>(true);
              if (ifStatement == null)
              {
            return;
              }

              IExpression condition = ifStatement.Condition;
              if (condition == null)
              {
            return;
              }

              var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());
              if (factory == null)
              {
            return;
              }

              var equalityExpression = ifStatement.Condition as IEqualityExpression;
              if (equalityExpression != null)
              {
            NegateEqualityExpression(factory, equalityExpression);
            return;
              }

              var relationalExpression = ifStatement.Condition as IRelationalExpression;
              if (relationalExpression != null)
              {
            NegateRelationalExpression(factory, relationalExpression);
            return;
              }

              var unaryOperatorExpression = ifStatement.Condition as IUnaryOperatorExpression;
              if (unaryOperatorExpression != null)
              {
            NegateUnaryExpression(factory, unaryOperatorExpression);
            return;
              }

              var invocationExpression = ifStatement.Condition as IInvocationExpression;
              if (invocationExpression != null)
              {
            NegateInvocationExpression(factory, invocationExpression);
            return;
              }

              var literalExpression = ifStatement.Condition as ILiteralExpression;
              if (literalExpression != null)
              {
            NegateLiteralExpression(factory, literalExpression);
            return;
              }

              NegateExpression(factory, ifStatement.Condition);
        }
开发者ID:xerxesb,项目名称:agentjohnsonplugin,代码行数:63,代码来源:NegateIfCondition.cs

示例7: Execute

        /// <summary>
        /// Executes the specified element.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <returns>
        /// Returns the text range.
        /// </returns>
        private static global::JetBrains.Util.TextRange Execute(IElement element)
        {
            var typeMemberDeclaration = element.ToTreeNode().Parent as ICSharpTypeMemberDeclaration;
              if (typeMemberDeclaration == null)
              {
            return global::JetBrains.Util.TextRange.InvalidRange;
              }

              var classDeclaration = typeMemberDeclaration.GetContainingTypeDeclaration() as IClassDeclaration;
              if (classDeclaration == null)
              {
            return global::JetBrains.Util.TextRange.InvalidRange;
              }

              var text = typeMemberDeclaration.GetText();

              var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());
              if (factory == null)
              {
            return global::JetBrains.Util.TextRange.InvalidRange;
              }

              var declaration = factory.CreateTypeMemberDeclaration(text) as IClassMemberDeclaration;
              if (declaration == null)
              {
            return global::JetBrains.Util.TextRange.InvalidRange;
              }

              var anchor = typeMemberDeclaration as IClassMemberDeclaration;
              if (anchor == null)
              {
            return global::JetBrains.Util.TextRange.InvalidRange;
              }

              var after = classDeclaration.AddClassMemberDeclarationAfter(declaration, anchor);
              if (after != null)
              {
            var treeTextRange = after.GetNameRange();
            return new global::JetBrains.Util.TextRange(treeTextRange.StartOffset.Offset, treeTextRange.EndOffset.Offset);
              }

              return global::JetBrains.Util.TextRange.InvalidRange;
        }
开发者ID:xerxesb,项目名称:agentjohnsonplugin,代码行数:52,代码来源:DuplicateMethod.cs

示例8: Execute

        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        protected override void Execute(IElement element)
        {
            var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());
              if (factory == null)
              {
            return;
              }

              var statement = element.ToTreeNode().Parent as IForStatement;
              if (statement == null)
              {
            return;
              }

              var localVariableDeclarations = statement.InitializerDeclarations;
              if (localVariableDeclarations.Count != 1)
              {
            return;
              }

              var localVariableDeclaration = localVariableDeclarations[0];
              if (localVariableDeclaration == null)
              {
            return;
              }

              var expressionInitializer = localVariableDeclaration.Initial as IExpressionInitializer;
              if (expressionInitializer == null)
              {
            return;
              }

              var from = expressionInitializer.Value;

              var relationalExpression = statement.Condition as IRelationalExpression;
              if (relationalExpression == null)
              {
            return;
              }

              var to = relationalExpression.RightOperand;

              var iterators = statement.IteratorExpressions;
              if (iterators == null)
              {
            return;
              }

              if (iterators.Count != 1)
              {
            return;
              }

              var postfixOperatorExpression = iterators[0] as IPostfixOperatorExpression;
              if (postfixOperatorExpression == null)
              {
            return;
              }

              if (postfixOperatorExpression.PostfixOperatorType == PostfixOperatorType.INVALID)
              {
            return;
              }

              if (postfixOperatorExpression.PostfixOperatorType == PostfixOperatorType.PLUSPLUS)
              {
            var expression = AddToExpression(factory, to, '-');

            expressionInitializer.SetValue(expression);

            var condition = GetCondition(factory, relationalExpression.LeftOperand, relationalExpression.OperatorSign.GetText(), from);

            relationalExpression.ReplaceBy(condition);

            var dec = factory.CreateExpression(string.Format("{0}--", postfixOperatorExpression.Operand.GetText()));

            postfixOperatorExpression.ReplaceBy(dec);
              }
              else
              {
            var expression = AddToExpression(factory, from, '+');

            expressionInitializer.SetValue(to);

            var condition = GetCondition(factory, relationalExpression.LeftOperand, relationalExpression.OperatorSign.GetText(), expression);

            relationalExpression.ReplaceBy(condition);

            var inc = factory.CreateExpression(string.Format("{0}++", postfixOperatorExpression.Operand.GetText()));

            postfixOperatorExpression.ReplaceBy(inc);
              }
        }
开发者ID:xerxesb,项目名称:agentjohnsonplugin,代码行数:99,代码来源:ReverseForDirectionContextAction.cs

示例9: CreateDocCommentBlockNode

        /// <summary>
        /// Creates a DocCommentBlockNode with the text provided.
        /// </summary>
        /// <param name="element">
        /// The element to create for.
        /// </param>
        /// <param name="text">
        /// The text to use to create the doc.
        /// </param>
        /// <returns>
        /// An IDocCommentBlockNode that has been created.
        /// </returns>
        public static IDocCommentBlockNode CreateDocCommentBlockNode(IElement element, string text)
        {
            // Fix up the xml terminators to remove the extra space.
            text = text.Replace(" />", "/>");

            StringBuilder builder = new StringBuilder();
            foreach (string line in text.Split('\n'))
            {
                string outputLine = line;
                if (line.StartsWith(" "))
                {
                    outputLine = line.Substring(1);
                }

                builder.Append("/// " + outputLine + Environment.NewLine);
            }

            builder.Append("void fec();");
            IDocCommentBlockOwnerNode declaration =
                (IDocCommentBlockOwnerNode)CSharpElementFactory.GetInstance(element.GetPsiModule()).CreateTypeMemberDeclaration(builder.ToString());

            return declaration.GetDocCommentBlockNode();
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-FIRST-stylecop,代码行数:35,代码来源:Utils.cs


注:本文中的IElement.GetPsiModule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。