예제 #1
0
 private void TestParseUnaryExp(Func <string, NativeXUnaryExpression> parser)
 {
     {
         NativeXExpression e = parser("++--&*-!~a++--");
         {
             string[] operators = { "++", "--", "&", "*", "-", "!", "~" };
             foreach (string op in operators)
             {
                 NativeXUnaryExpression unary = (NativeXUnaryExpression)e;
                 Assert.AreEqual(op, unary.Operator);
                 e = unary.Operand;
             }
         }
         {
             string[] operators = { "--", "++" };
             foreach (string op in operators)
             {
                 NativeXPostUnaryExpression unary = (NativeXPostUnaryExpression)e;
                 Assert.AreEqual(op, unary.Operator);
                 e = unary.Operand;
             }
         }
         {
             Assert.AreEqual("a", ((NativeXReferenceExpression)e).ReferencedName);
         }
     }
 }
예제 #2
0
 public Tuple <XDocument, TextPosition> OnGetQuickInfoTooltip()
 {
     if (this.EditingObserverExtension.EditingNode != null &&
         this.EditingObserverExtension.EditingNode.Scope != null
         )
     {
         var          editingNode = this.EditingObserverExtension.EditingNode;
         TextPosition pos         = this.EditingObserverExtension.NodePositionToEditing(this.Callback.TextEditorBox.SelectionCaret);
         NativeXNode  node        = editingNode.FindDeepest <NativeXNode>(pos);
         if (node != null)
         {
             NativeXInvokeExpression invoke = (node as NativeXInvokeExpression) ?? node.FindParent <NativeXInvokeExpression>();
             while (invoke != null && invoke.Function != null)
             {
                 TextPosition start = invoke.Function.End;
                 TextPosition end   = this.EditingObserverExtension.CodePositionToEditing(this.Callback.TextEditorBox.SelectionCaret);
                 if (!this.EditingObserverExtension.IsTemporaryEditingNode)
                 {
                     start = this.EditingObserverExtension.CodePositionToEditing(start);
                 }
                 if (start < end)
                 {
                     string inside     = this.EditingObserverExtension.EditingNodeCode.GetString(start, end);
                     int    openCount  = inside.Where(c => c == '(').Count();
                     int    closeCount = inside.Where(c => c == ')').Count();
                     if (openCount > closeCount)
                     {
                         break;
                     }
                 }
                 invoke = invoke.FindParent <NativeXInvokeExpression>();
             }
             if (invoke != null && invoke.Function != null)
             {
                 NativeXExpression function = invoke.Function;
                 int index = 0;
                 if (invoke.Arguments != null)
                 {
                     for (int i = 0; i < invoke.Arguments.Count; i++)
                     {
                         NativeXNode argument = invoke.Arguments[i];
                         if (argument != null && argument.Start <= pos && pos <= argument.End)
                         {
                             index = i;
                             break;
                         }
                         else
                         {
                             index = Math.Min(index + 1, invoke.Arguments.Count - 1);
                         }
                     }
                 }
                 Tuple <string, string, string> info = function.GetFormattedFunctionQuickInfo(index);
                 if (!string.IsNullOrEmpty(info.Item1 + info.Item2 + info.Item3))
                 {
                     var content = new RichContent.Content(
                         new RichContent.Text(info.Item1),
                         new RichContent.Bold(new RichContent.Text(info.Item2)),
                         new RichContent.Text(info.Item3)
                         );
                     return(Tuple.Create <XDocument, TextPosition>(content, this.EditingObserverExtension.NodePositionToGlobal(invoke.Start)));
                 }
             }
         }
     }
     return(null);
 }