コード例 #1
0
 public IntroduceMemberPostfixTemplateInfo(
     [NotNull] string text, [NotNull] PostfixExpressionContext expression, IType expressionType, bool isStatic)
     : base(text, expression)
 {
     ExpressionType = expressionType;
     IsStatic       = isStatic;
 }
コード例 #2
0
 public PostfixTemplateInfo(
     [NotNull] string text, [NotNull] PostfixExpressionContext expression,
     PostfixTemplateTarget target = PostfixTemplateTarget.Expression)
 {
     Multiplier         = 0;
     myText             = text.ToLowerInvariant();
     myShortcut         = text;
     myTarget           = target;
     myImages           = new[] { new PostfixExpressionContextImage(expression) };
     myExecutionContext = expression.PostfixContext.ExecutionContext;
 }
コード例 #3
0
        private static string PresentExpression(
            [NotNull] PostfixExpressionContext context, [NotNull] string postfixText, out TextRange range)
        {
            var text = context.Expression.GetText();

            range = context.ExpressionRange.TextRange;

            if (context.Expression.Contains(context.PostfixContext.Reference))
            {
                var originalSize = text.Length;

                // "x > 0.par" => "x > 0"
                if (text.EndsWith(postfixText, StringComparison.OrdinalIgnoreCase))
                {
                    text = text.Substring(0, text.Length - postfixText.Length).TrimEnd();
                }

                var delta = originalSize - text.Length;
                if (delta >= 0)
                {
                    range = range.ExtendRight(-delta);
                }
            }

            text = text.ReplaceNewLines().TrimStart();

            while (true) // "aa\n         && bb" => "aa && bb"
            {
                var reduced = text.Replace("  ", " ");
                if (reduced.Length < text.Length)
                {
                    text = reduced;
                }
                else
                {
                    break;
                }
            }

            const int textLength = 50;

            if (text.Length > textLength)
            {
                text = text.Substring(0, textLength) + "…";
            }

            return(text);
        }
        protected override ITreeNode ExpandPostfix(PostfixExpressionContext context)
        {
            var csharpContext = (CSharpPostfixExpressionContext)context;
            var psiModule     = csharpContext.PostfixContext.PsiModule;
            var psiServices   = psiModule.GetPsiServices();

            var expandedExpression = psiServices.DoTransaction(ExpandCommandName, () =>
            {
                var factory    = CSharpElementFactory.GetInstance(psiModule);
                var expression = csharpContext.Expression;

                // todo: get rid of this xtra behavior?
                var operand = expression.GetOperandThroughParenthesis().NotNull("operand != null");

                var newExpression = CreateExpression(factory, operand);

                return(expression.ReplaceBy(newExpression));

                // todo: DecorateReplacedExpression()?
            });

            return(expandedExpression);
        }
コード例 #5
0
 public override PostfixExpressionContext FixExpression(PostfixExpressionContext context)
 {
     return(FixExpression((CSharpPostfixExpressionContext)context));
 }
コード例 #6
0
 public CheckForNullPostfixTemplateInfo(
     [NotNull] string text, [NotNull] PostfixExpressionContext expression, bool checkNotNull, PostfixTemplateTarget target)
     : base(text, expression, target)
 {
     CheckNotNull = checkNotNull;
 }
コード例 #7
0
 protected abstract ITreeNode ExpandPostfix([NotNull] PostfixExpressionContext context);
コード例 #8
0
ファイル: JSONParser.cs プロジェクト: mpmedia/Excess
	private bool postfixExpression_sempred(PostfixExpressionContext _localctx, int predIndex) {
		switch (predIndex) {
		case 0: return Precpred(Context, 6);
		case 1: return Precpred(Context, 5);
		case 2: return Precpred(Context, 4);
		case 3: return Precpred(Context, 3);
		case 4: return Precpred(Context, 2);
		case 5: return Precpred(Context, 1);
		}
		return true;
	}
コード例 #9
0
ファイル: JSONParser.cs プロジェクト: mpmedia/Excess
	private PostfixExpressionContext postfixExpression(int _p) {
		ParserRuleContext _parentctx = Context;
		int _parentState = State;
		PostfixExpressionContext _localctx = new PostfixExpressionContext(Context, _parentState);
		PostfixExpressionContext _prevctx = _localctx;
		int _startState = 14;
		EnterRecursionRule(_localctx, 14, RULE_postfixExpression, _p);
		int _la;
		try {
			int _alt;
			EnterOuterAlt(_localctx, 1);
			{
			{
			_localctx = new SimpleExpressionContext(_localctx);
			Context = _localctx;
			_prevctx = _localctx;

			State = 115; primaryExpression();
			}
			Context.Stop = TokenStream.Lt(-1);
			State = 140;
			ErrorHandler.Sync(this);
			_alt = Interpreter.AdaptivePredict(TokenStream,10,Context);
			while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber ) {
				if ( _alt==1 ) {
					if ( ParseListeners!=null )
						TriggerExitRuleEvent();
					_prevctx = _localctx;
					{
					State = 138;
					switch ( Interpreter.AdaptivePredict(TokenStream,9,Context) ) {
					case 1:
						{
						_localctx = new IndexContext(new PostfixExpressionContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_postfixExpression);
						State = 117;
						if (!(Precpred(Context, 6))) throw new FailedPredicateException(this, "Precpred(Context, 6)");
						State = 118; Match(LeftBracket);
						State = 119; argumentExpressionList(0);
						State = 120; Match(RightBracket);
						}
						break;
					case 2:
						{
						_localctx = new CallContext(new PostfixExpressionContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_postfixExpression);
						State = 122;
						if (!(Precpred(Context, 5))) throw new FailedPredicateException(this, "Precpred(Context, 5)");
						State = 123; Match(LeftParen);
						State = 125;
						_la = TokenStream.La(1);
						if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << LeftParen) | (1L << Plus) | (1L << PlusPlus) | (1L << Minus) | (1L << MinusMinus) | (1L << Star) | (1L << And) | (1L << Not) | (1L << Tilde) | (1L << Identifier) | (1L << Constant) | (1L << StringLiteral))) != 0)) {
							{
							State = 124; argumentExpressionList(0);
							}
						}

						State = 127; Match(RightParen);
						}
						break;
					case 3:
						{
						_localctx = new MemberAccessContext(new PostfixExpressionContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_postfixExpression);
						State = 128;
						if (!(Precpred(Context, 4))) throw new FailedPredicateException(this, "Precpred(Context, 4)");
						State = 129; Match(Dot);
						State = 130; Match(Identifier);
						}
						break;
					case 4:
						{
						_localctx = new MemberPointerAccessContext(new PostfixExpressionContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_postfixExpression);
						State = 131;
						if (!(Precpred(Context, 3))) throw new FailedPredicateException(this, "Precpred(Context, 3)");
						State = 132; Match(Arrow);
						State = 133; Match(Identifier);
						}
						break;
					case 5:
						{
						_localctx = new PostfixIncrementContext(new PostfixExpressionContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_postfixExpression);
						State = 134;
						if (!(Precpred(Context, 2))) throw new FailedPredicateException(this, "Precpred(Context, 2)");
						State = 135; Match(PlusPlus);
						}
						break;
					case 6:
						{
						_localctx = new PostfixDecrementContext(new PostfixExpressionContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_postfixExpression);
						State = 136;
						if (!(Precpred(Context, 1))) throw new FailedPredicateException(this, "Precpred(Context, 1)");
						State = 137; Match(MinusMinus);
						}
						break;
					}
					} 
				}
				State = 142;
				ErrorHandler.Sync(this);
				_alt = Interpreter.AdaptivePredict(TokenStream,10,Context);
			}
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			UnrollRecursionContexts(_parentctx);
		}
		return _localctx;
	}
コード例 #10
0
ファイル: JSONParser.cs プロジェクト: mpmedia/Excess
		public PostfixIncrementContext(PostfixExpressionContext context) { CopyFrom(context); }
コード例 #11
0
ファイル: JSONParser.cs プロジェクト: mpmedia/Excess
		public CallContext(PostfixExpressionContext context) { CopyFrom(context); }
コード例 #12
0
ファイル: JSONParser.cs プロジェクト: mpmedia/Excess
		public SimpleExpressionContext(PostfixExpressionContext context) { CopyFrom(context); }
コード例 #13
0
ファイル: JSONParser.cs プロジェクト: mpmedia/Excess
		public MemberPointerAccessContext(PostfixExpressionContext context) { CopyFrom(context); }
コード例 #14
0
ファイル: JSONParser.cs プロジェクト: mpmedia/Excess
		public IndexContext(PostfixExpressionContext context) { CopyFrom(context); }
コード例 #15
0
ファイル: JSONParser.cs プロジェクト: mpmedia/Excess
		public virtual void CopyFrom(PostfixExpressionContext context) {
			base.CopyFrom(context);
		}
        protected override ITreeNode ExpandPostfix(PostfixExpressionContext context)
        {
            var csharpContext = (CSharpPostfixExpressionContext)context;
            var psiModule     = csharpContext.PostfixContext.PsiModule;
            var psiServices   = psiModule.GetPsiServices();
            var factory       = CSharpElementFactory.GetInstance(psiModule);

            var targetStatement = csharpContext.GetContainingStatement();
            var expressionRange = csharpContext.Expression.GetDocumentRange();

            // Razor issue - hard to convert expression to statement
            if (!targetStatement.GetDocumentRange().IsValid())
            {
                var newStatement = psiServices.DoTransaction(ExpandCommandName, () =>
                {
                    // todo: pass original context?
                    var expression = csharpContext.Expression.GetOperandThroughParenthesis().NotNull();
                    return(CreateStatement(factory, expression));
                });

                var razorStatement = RazorUtil.FixExpressionToStatement(expressionRange, psiServices);
                if (razorStatement != null)
                {
                    return(psiServices.DoTransaction(ExpandCommandName, () =>
                    {
                        var statement = razorStatement.ReplaceBy(newStatement);

                        // force Razor's bracing style
                        var languageService = statement.Language.LanguageService().NotNull();
                        var formatter = languageService.CodeFormatter.NotNull();
                        formatter.Format(statement, CodeFormatProfile.SOFT, NullProgressIndicator.Instance);

                        return statement;
                    }));
                }

                Logger.Fail("Failed to resolve target statement to replace");
                return(null);
            }

            return(psiServices.DoTransaction(ExpandCommandName, () =>
            {
                var expression = csharpContext.Expression.GetOperandThroughParenthesis().NotNull();
                var newStatement = CreateStatement(factory, expression);

                Assertion.AssertNotNull(targetStatement, "targetStatement != null");
                Assertion.Assert(targetStatement.IsPhysical(), "targetStatement.IsPhysical()");

                // Sometimes statements produced by templates are unfinished (for example, because of
                // parentheses insertion mode in R#), so the created statements has error element at and,
                // prefixed with single-characted whitespace. We remove this whitespace here:
                var errorElement = newStatement.LastChild as IErrorElement;
                if (errorElement != null)
                {
                    var whitespaceNode = errorElement.PrevSibling as IWhitespaceNode;
                    if (whitespaceNode != null && !whitespaceNode.IsNewLine && whitespaceNode.GetText() == " ")
                    {
                        using (WriteLockCookie.Create(newStatement.IsPhysical()))
                        {
                            LowLevelModificationUtil.DeleteChild(whitespaceNode);
                        }
                    }
                }

                return targetStatement.ReplaceBy(newStatement);
            }));
        }
コード例 #17
0
 public PostfixUsingTemplateInfo([NotNull] string text, [NotNull] PostfixExpressionContext expression, bool shouldCreateVariable)
     : base(text, expression)
 {
     ShouldCreateVariable = shouldCreateVariable;
 }
コード例 #18
0
 public ForLoopPostfixTemplateInfo(
     [NotNull] string text, [NotNull] PostfixExpressionContext expression, [CanBeNull] string lengthPropertyName)
     : base(text, expression)
 {
     LengthPropertyName = lengthPropertyName;
 }