Esempio n. 1
0
        private string CalcIndent(FormattingStageContext context)
        {
            CompositeElement parent = context.Parent;

            if (context.LeftChild != context.RightChild)
            {
                ITreeNode rChild = context.RightChild;
                if ((!context.LeftChild.HasLineFeedsTo(rChild)))
                {
                    return(null);
                }

                var psiTreeNode = context.Parent as IPsiTreeNode;

                return(psiTreeNode != null
          ? psiTreeNode.Accept(_indentVisitor, context)
          : _indentVisitor.VisitNode(parent, context));
            }
            else
            {
                var psiTreeNode = context.Parent as IPsiTreeNode;

                return(psiTreeNode != null
          ? psiTreeNode.Accept(_indentVisitor, context)
          : _indentVisitor.VisitNode(parent, context));
            }
        }
 public bool Match(FormattingStageContext context)
 {
     if (myParentType != null)
     {
         if (context.Parent.NodeType != myParentType)
         {
             return(false);
         }
     }
     if (myLeftChildType != null)
     {
         var leftChild = context.LeftChild as TreeElement;
         if (!((leftChild != null) && (leftChild.NodeType == myLeftChildType)))
         {
             return(false);
         }
     }
     if (myRightChildType != null)
     {
         var rightChild = context.RightChild as TreeElement;
         if (!((rightChild != null) && (rightChild.NodeType == myRightChildType)))
         {
             return(false);
         }
     }
     return(true);
 }
        public bool Match(FormattingStageContext context)
        {
            if (myParentType != null)
            {
                if (myParentType != context.Parent.NodeType)
                {
                    return(false);
                }
            }
            if (myLeftChildType != null)
            {
                if (!(myLeftChildType == (context.LeftChild as TreeElement).NodeType))
                {
                    return(false);
                }
            }
            if (myRightChildType != null)
            {
                if (!(myRightChildType == (context.RightChild as TreeElement).NodeType))
                {
                    return(false);
                }
            }


            return(true);
        }
        public IEnumerable <string> Space(FormattingStageContext context, FormattingStageResearchBase stage)
        {
            ITreeNode parent = context.Parent;

            while ((parent as TreeElement) != null && !(mySingleLineParentType == (parent as TreeElement).NodeType))
            {
                parent = parent.Parent;
            }
            if (parent == null)
            {
                return(new[] { "\n" });
            }

            ITreeNode firstToken;
            ITreeNode lastToken;

            FindFisrtAndLastTokenIn(parent, context, out firstToken, out lastToken);
            if (firstToken != null && lastToken != null)
            {
                if (stage.HasLineFeedsTo(firstToken, lastToken))
                {
                    return(new[] { "\n" });
                }
            }
            return(mySpace);
        }
Esempio n. 5
0
        public override IEnumerable <string> VisitSecretFile(INTriplesFile psiFile, FormattingStageContext context)
        {
            if (!this.myIsGenerated)
            {
                return(base.VisitSecretFile(psiFile, context));
            }

            return(base.VisitSecretFile(psiFile, context));
        }
        public override IEnumerable <string> VisitPsiFile(IPsiFile psiFile, FormattingStageContext context)
        {
            if (!myIsGenerated)
            {
                return(base.VisitPsiFile(psiFile, context));
            }

            return(base.VisitPsiFile(psiFile, context));
        }
        private IEnumerable <string> CalcSpaces(FormattingStageContext context)
        {
            var psiTreeNode = context.Parent as INTriplesTreeNode;

            /*if(context.RightChild is IQuantifier)// TODO
             * {
             * return new  List<string> {""};
             * } */
            return(psiTreeNode != null
                       ? psiTreeNode.Accept(this.myFmtVisitor, context)
                       : null);
        }
        private IEnumerable <string> CalcSpaces(FormattingStageContext context)
        {
            var psiTreeNode = context.Parent as IPsiTreeNode;

            if (context.RightChild is IQuantifier)
            {
                return(new  List <string> {
                    ""
                });
            }
            return(psiTreeNode != null?psiTreeNode.Accept(myFmtVisitor, context) : null);
        }
        public bool Match(FormattingStageContext context)
        {
            if (myParentType != null)
            {
                if (context.Parent.NodeType != myParentType)
                {
                    return(false);
                }
            }
            TreeElement rightChild = context.RightChild as TreeElement;

            return(rightChild.NodeType == myType);
        }
        public bool Match(FormattingStageContext context)
        {
            var leftChild = context.LeftChild as TreeElement;

            if (myParentType != null)
            {
                if (myParentType != context.Parent.NodeType)
                {
                    return(false);
                }
            }
            return(leftChild.NodeType == myType);
        }
        private bool IsTokensGlued(FormattingStageContext formattingStageContext)
        {
            if (formattingStageContext.LeftChild.GetText() == "")
            {
                return(false);
            }
            if (formattingStageContext.RightChild.GetText() == "")
            {
                return(false);
            }
            var lexer = GetLexer(formattingStageContext);

            return(lexer.LookaheadToken(1) == null);
        }
 public bool Match(FormattingStageContext context)
 {
     if (myParentType != null)
     {
         if (context.Parent.NodeType != myParentType)
         {
             return(false);
         }
     }
     if (!(context.LeftChild is ITokenNode))
     {
         return(false);
     }
     return(context.LeftChild.GetText() == myTokenText);
 }
 public bool Match(FormattingStageContext context)
 {
     if (myParentType != null)
     {
         if (!(myParentType.IsInstanceOfType(context.Parent)))
         {
             return(false);
         }
     }
     if (!(context.RightChild is ITokenNode))
     {
         return(false);
     }
     return(context.RightChild.GetText() == myTokenText);
 }
        private string CalcIndent(FormattingStageContext context)
        {
            CompositeElement parent = context.Parent;

            ITreeNode rChild = context.RightChild;
            if ((!context.LeftChild.HasLineFeedsTo(rChild)) && (!this.myInTypingAssist))
            {
                return null;
            }

            var psiTreeNode = context.Parent as INTriplesTreeNode;

            return psiTreeNode != null
                       ? psiTreeNode.Accept(ourIndentVisitor, context)
                       : ourIndentVisitor.VisitNode(parent, context);
        }
        private string CalcIndent(FormattingStageContext context)
        {
            CompositeElement parent = context.Parent;

            ITreeNode rChild = context.RightChild;

            if ((!context.LeftChild.HasLineFeedsTo(rChild)) && (!this.myInTypingAssist))
            {
                return(null);
            }

            var psiTreeNode = context.Parent as INTriplesTreeNode;

            return(psiTreeNode != null
                       ? psiTreeNode.Accept(ourIndentVisitor, context)
                       : ourIndentVisitor.VisitNode(parent, context));
        }
        public IEnumerable <string> Space(FormattingStageContext context, FormattingStageResearchBase stage)
        {
            ITreeNode parent = context.Parent;

            while (parent != null && !mySingleLineParentType.IsInstanceOfType(parent))
            {
                parent = parent.Parent;
            }
            if (parent == null)
            {
                return(new[] { "\n" });
            }
            if (stage.HasLineFeedsTo(parent.FirstChild, parent.LastChild))
            {
                return(new[] { "\n" });
            }
            return(mySpace);
        }
        private void FindFisrtAndLastTokenIn(ITreeNode parent, FormattingStageContext context, out ITreeNode firstToken, out ITreeNode lastToken)
        {
            var offset = context.RightChild.GetTreeStartOffset().Offset;
            var child  = parent.FirstChild;

            firstToken = null;
            lastToken  = null;
            while ((child != null) && (child.GetTreeStartOffset().Offset <= offset))
            {
                child = child.NextSibling;
            }

            if (child != null)
            {
                child = child.PrevSibling;
            }

            var leftChild  = child;
            var rightChild = child;

            while (leftChild != null)
            {
                if (leftChild.GetText() == myLeftText)
                {
                    firstToken = leftChild;
                    break;
                }
                leftChild = leftChild.PrevSibling;
            }

            while (rightChild != null)
            {
                if (rightChild.GetText() == myRightText)
                {
                    lastToken = rightChild;
                    break;
                }
                rightChild = rightChild.NextSibling;
            }
        }
        private IEnumerable <string> CalcSpaces(FormattingStageContext formattingStageContext)
        {
            IFormattingRule currentRule = null;

            foreach (var formattingRule in myFormatter.FormattingRules)
            {
                if (formattingRule.Match(formattingStageContext))
                {
                    if (currentRule == null)
                    {
                        if (formattingRule.GetPriority() > 0)
                        {
                            currentRule = formattingRule;
                        }
                    }
                    else
                    {
                        if (formattingRule.GetPriority() > currentRule.GetPriority())
                        {
                            currentRule = formattingRule;
                        }
                    }
                }
            }

            if (currentRule != null)
            {
                return(currentRule.Space(formattingStageContext, this));
            }
            if (IsTokensGlued(formattingStageContext))
            {
                //return new[] {" "};
                return(null);
            }
            else
            {
                return(new[] { "" });
            }
        }
Esempio n. 19
0
        private string CalcIndent(FormattingStageContext formattingStageContext, IList <IndentRange> indentRanges, bool indent)
        {
            ITreeNode rChild = formattingStageContext.RightChild;

            if ((!HasLineFeedsTo(formattingStageContext.LeftChild, rChild)))
            {
                return(null);
            }
            var offset = formattingStageContext.RightChild.GetTreeStartOffset();

            var range = GetCurrentRangeForInsert(offset, indentRanges);

            if (range == null)
            {
                var parent = formattingStageContext.LeftChild.FindCommonParent(formattingStageContext.RightChild);
                return(GetIndent(parent));
            }
            else
            {
                return(range.Indent);
            }
        }
        protected ILexer GetLexer(FormattingStageContext formattingStageContext)
        {
            string s = "";

            if (formattingStageContext.LeftChild.FirstChild == null)
            {
                s = formattingStageContext.LeftChild.GetText();
            }
            else
            {
                s = formattingStageContext.LeftChild.GetLastTokenIn().GetText();
            }
            if (formattingStageContext.RightChild.FirstChild == null)
            {
                s += formattingStageContext.RightChild.GetText();
            }
            else
            {
                s += formattingStageContext.RightChild.GetFirstTokenIn().GetText();
            }
            return(GetLexer(s));
        }
 public IEnumerable <string> Space(FormattingStageContext context, FormattingStageResearchBase stage)
 {
     return(mySpace);
 }
 public override IEnumerable <string> VisitRuleBody(IRuleBody ruleBodyParam, FormattingStageContext context)
 {
     return(new[] { " " });
 }
        public override IEnumerable <string> VisitRuleDeclaration(IRuleDeclaration ruleDeclarationParam, FormattingStageContext context)
        {
            if (context.LeftChild is IModifier)
            {
                return(new[] { " " });
            }
            if (context.RightChild is IRoleGetterParameter)
            {
                return(new[] { " " });
            }
            if (context.RightChild is IRuleBracketTypedParameters)
            {
                return(new[] { " " });
            }

            return(new[] { "\r\n" });
        }
 public override IEnumerable <string> VisitExtraDefinition(IExtraDefinition extraDefinitionParam, FormattingStageContext context)
 {
     return(new[] { " " });
 }
 public override IEnumerable <string> VisitSequence(ISequence sequenceParam, FormattingStageContext context)
 {
     return(new[] { "\r\n" });
 }
 public override IEnumerable <string> VisitOptionsDefinition(IOptionsDefinition optionsDefinitionParam, FormattingStageContext context)
 {
     return(new[] { "\r\n" });
 }
 public override IEnumerable <string> VisitPsiExpression(IPsiExpression psiExpressionParam, FormattingStageContext context)
 {
     if (context.RightChild is IChoiceTail)
     {
         return(new[] { "\r\n" });
     }
     return(new[] { " " });
 }
 public override IEnumerable <string> VisitParenExpression(IParenExpression parenExpressionParam, FormattingStageContext context)
 {
     if ((context.LeftChild is IPsiExpression) || (context.RightChild is IPsiExpression))
     {
         return(new[] { "\r\n" });
     }
     return(new[] { " " });
 }
 public override IEnumerable <string> VisitChoiceTail(IChoiceTail choiceTailParam, FormattingStageContext context)
 {
     if (context.LeftChild is ICommentNode)
     {
         return(new[] { "\r\n" });
     }
     return(new[] { " " });
 }
   private IEnumerable<string> CalcSpaces(FormattingStageContext context)
   {
       var psiTreeNode = context.Parent as INTriplesTreeNode;
       /*if(context.RightChild is IQuantifier)// TODO
 {
   return new  List<string> {""};
 } */
       return psiTreeNode != null
                  ? psiTreeNode.Accept(this.myFmtVisitor, context)
                  : null;
   }