Пример #1
0
		public ObjectLiteralElement(Expression Name, Expression Value, TextPoint ColonLocation, TextPoint CommaLocation)
		{
			this.Name = Name;
			this.Value = Value;
			this.ColonLocation = ColonLocation;
			this.CommaLocation = CommaLocation;
		}
Пример #2
0
		public LabelStatement(Identifier Label, Statement Labeled, TextSpan Location, TextPoint Colon)
			:base(Operation.Label,Location)
		{
			this.Label = Label;
			this.Labeled = Labeled;
			this.Colon = Colon;
		}
Пример #3
0
		public DoStatement(Statement Body, Expression Condition, TextSpan Location, TextSpan HeaderLocation, TextPoint While, TextPoint LeftParen, TextPoint RightParen)
			:base(Operation.Do, Body, Location, LeftParen, RightParen)
		{
			this.While = While;
			this.Condition = Condition;
			this.HeaderLocation = HeaderLocation;
		}
Пример #4
0
		public ForInStatement(Statement.Operation Opcode, Expression Collection, Statement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint In, TextPoint LeftParen, TextPoint RightParen)
			:base(Opcode, Body, Location, LeftParen, RightParen)
		{
			this.Collection = Collection;
			this.HeaderLocation = HeaderLocation;
			this.In = In;
		}
Пример #5
0
		public SubscriptExpression(Expression Base, Expression Subscript, TextSpan Location, TextPoint LeftBracketLocation)
			: base(Operation.Subscript, Location)
		{
			this.Base = Base;
			this.Subscript = Subscript;
			this.LeftBracketLocation = LeftBracketLocation;
		}
Пример #6
0
        /// <summary>
        /// 执行命令
        /// </summary>
        /// <param name="para">自定义参数</param>
        /// <result></result>
        public override CommandResult Process(object para)
        {
            CommandResult result = new CommandResult();
            result.ErrCode = CommandExecStatus.Succeed;
            result.ErrMsg = para.ToString();
            if (vsWindowType.vsWindowTypeDocument == DteHelper.Dte2.ActiveWindow.Type)
            {
                _currentCodePoint = DteHelper.GetCurrentActivePoint();
                _currentCodeDocument = DteHelper.Dte2.ActiveDocument;
                List<CodeDomCodeElement<CodeElement>> listElement = DteHelper.FetchCodeElementByPoint(_currentCodeDocument.ProjectItem.FileCodeModel, _currentCodePoint);
                this.CurrentCodeElement = DteHelper.FindPointElement(listElement, _currentCodePoint);
            }
            else if (vsWindowType.vsWindowTypeSolutionExplorer == DteHelper.Dte2.ActiveWindow.Type && CurrentCodeElement != null)
            {
                //取得所有选中文件
                IList<ProjectItem> listItem = DteHelper.GetSelectedItem(Constant.CSharpFileExtension);

                List<CodeDomCodeElement<CodeElement>> listElement = DteHelper.FetchCodeElementByPoint(_currentCodeDocument.ProjectItem.FileCodeModel, _currentCodePoint);
                CodeDomCodeElement<CodeElement> codeElement = DteHelper.FindPointElement(listElement, _currentCodePoint);

                foreach (var projectItem in listItem)
                {
                    foreach (var codeClass in DteHelper.GetClassFromFile(projectItem.FileCodeModel))
                    {//重构元素
                        DteHelper.RefactorElement(this.CurrentCodeElement, codeElement, codeClass);
                    }
                }
            }
            return result;
        }
Пример #7
0
		public CaseClause(DList<Statement, CaseClause> Children, TextSpan Location, TextSpan HeaderLocation, TextPoint Colon)
		{
			this.colon = Colon;
			this.location = Location;
			this.Children = Children;
			this.HeaderLocation = HeaderLocation;
		}
		public BinaryOperatorExpression(Expression Left, Expression Right, Expression.Operation Opcode, TextSpan Location, TextPoint OperatorLocation)
			: base(Opcode,Location)
		{
			this.Left = Left;
			this.Right = Right;
			this.operatorLocation = OperatorLocation;
		}
Пример #9
0
		public LoopStatement(Statement.Operation Opcode, Statement Body, TextSpan Location, TextPoint LeftParen, TextPoint RightParen)
			:base(Opcode,Location)
		{
			this.Body = Body;
			this.LeftParen = LeftParen;
			this.RightParen = RightParen;
		}
        private CodeElement GetCodeElementAtTextPoint(vsCMElement eRequestedCodeElementKind,
            CodeElements colCodeElements, TextPoint objTextPoint)
        {

            //  CodeElement objCodeElement = default(CodeElement);
            CodeElement objResultCodeElement = default(CodeElement);
            CodeElements colCodeElementMembers = default(CodeElements);
            CodeElement objMemberCodeElement = default(CodeElement);


            if ((colCodeElements != null))
            {

                foreach (CodeElement objCodeElement in colCodeElements)
                {

                    if (objCodeElement.StartPoint.GreaterThan(objTextPoint))
                    {
                        // The code element starts beyond the point


                    }
                    else if (objCodeElement.EndPoint.LessThan(objTextPoint))
                    {
                        // The code element ends before the point

                        // The code element contains the point
                    }
                    else
                    {

                        if (objCodeElement.Kind == eRequestedCodeElementKind)
                        {
                            // Found
                            objResultCodeElement = objCodeElement;
                        }

                        // We enter in recursion, just in case there is an inner code element that also 
                        // satisfies the conditions, for example, if we are searching a namespace or a class
                        colCodeElementMembers = GetCodeElementMembers(objCodeElement);

                        objMemberCodeElement = GetCodeElementAtTextPoint(eRequestedCodeElementKind, colCodeElementMembers, objTextPoint);

                        if ((objMemberCodeElement != null))
                        {
                            // A nested code element also satisfies the conditions
                            objResultCodeElement = objMemberCodeElement;
                        }

                        break; // TODO: might not be correct. Was : Exit For

                    }

                }

            }

            return objResultCodeElement;

        }
		public DeclarationForInStatement(VariableDeclaration Item, Expression Collection, Statement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint In, TextPoint LeftParen, TextPoint RightParen)
			:base(Operation.DeclarationForIn,Collection,Body,Location,HeaderLocation,In,LeftParen,RightParen)
		{
			this.Item = Item;
			this.In = In;
			this.LeftParen = LeftParen;
			this.RightParen = RightParen;
		}
Пример #12
0
		//=========================================================================================
		public Token(string typeName, string text, TextPoint start, TextPoint end, TextStyle style)
		{
			this.TokenTypeName = typeName;
			this.Text = text;
			this.Start = start;
			this.End = end;
			this.Style = style;
		}
Пример #13
0
		public QualifiedExpression(Expression Base, Identifier Qualifier, TextSpan Location, TextPoint DotLocation, TextPoint QualifierLocation)
			:base(Operation.Qualified, Location)
		{
			this.Base = Base;
			this.Qualifier = Qualifier;
			this.DotLocation = DotLocation;
			this.QualifierLocation = QualifierLocation;
		}
Пример #14
0
		public CatchClause(Identifier Name, BlockStatement Handler, TextSpan Location, TextSpan NameLocation, TextPoint LeftParen, TextPoint RightParen)
		{
			this.Name = Name;
			this.Handler = Handler;
			this.Location = Location;
			this.NameLocation = NameLocation;
			this.leftParen = LeftParen;
			this.rightParen = RightParen;
		}
Пример #15
0
		public ForStatement(Statement.Operation Opcode, Expression Condition, Expression Increment, Statement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint FirstSemicolon, TextPoint SecondSemicolon, TextPoint LeftParen, TextPoint RightParen)
			:base(Opcode,Body,Location,LeftParen,RightParen)
		{
			this.Condition = Condition;
			this.Increment = Increment;
			this.HeaderLocation = HeaderLocation;
			this.FirstSemicolon= FirstSemicolon;
			this.SecondSemicolon = SecondSemicolon;
		}
		public TernaryOperatorExpression(Expression First, Expression Second, Expression Third, Expression.Operation opcode, TextSpan Location, TextPoint FirstOperatorLocation, TextPoint SecondOperatorLocation)
			:base(opcode,Location)
		{
			this.First = First;
			this.Second = Second;
			this.Third = Third;
			this.FirstOperatorLocation = FirstOperatorLocation;
			this.SecondOperatorLocation = SecondOperatorLocation;
		}
Пример #17
0
 //������Ɖ����t���O
 //private bool _disabledTemporary;
 public TextSelection(CharacterDocumentViewer owner)
 {
     _owner = owner;
     _forwardPivot = new TextPoint();
     _backwardPivot = new TextPoint();
     _forwardDestination = new TextPoint();
     _backwardDestination = new TextPoint();
     _listeners = new List<ISelectionListener>();
 }
Пример #18
0
		public WithStatement(Expression Scope, Statement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint LeftParen, TextPoint RightParen)
			:base(Operation.With,Location)
		{
			this.LeftParen = LeftParen;
			this.RightParen = RightParen;
			this.Body = Body;
			this.HeaderLocation = HeaderLocation;
			this.Scope = Scope;
		}
Пример #19
0
		public SwitchStatement(Expression Value, DList<CaseClause, SwitchStatement> Cases, TextSpan Location, TextSpan HeaderLocation, TextPoint LeftParen, TextPoint RightParen, TextPoint LeftBrace)
			:base(Operation.Switch,Location)
		{
			this.Value = Value;
			this.Cases = Cases;
			this.HeaderLocation = HeaderLocation;
			this.LeftParen = LeftParen;
			this.RightParen = RightParen;
			this.LeftBrace = LeftBrace;
		}
			// [jt] This handler checks for things like paste operations. In theory we should be able to remove the handler above, but
			// I can't get this one to fire reliably... Wonder how much these handlers will slow down the IDE?
			private void OnLineChanged(TextPoint StartPoint, TextPoint EndPoint, int Hint)
			{
				if((Hint & (int)vsTextChanged.vsTextChangedNewline) == 0 &&
					(Hint & (int)vsTextChanged.vsTextChangedMultiLine) == 0 &&
					(Hint & (int)vsTextChanged.vsTextChangedNewline) == 0 &&
					(Hint != 0))
					return;
				if(mPlugin.App.ActiveDocument.ReadOnly && !mPlugin.App.ActiveDocument.Saved)
					P4Operations.EditFile(mPlugin.OutputPane, mPlugin.App.ActiveDocument.FullName);
			}
Пример #21
0
		public FunctionDefinition(Identifier Name, List<Parameter> Parameters, BlockStatement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint NameLocation, TextPoint LeftParenLocation, TextPoint RightParenLocation)
		{
			this.Name = Name;
			this.Parameters = Parameters;
			this.Body = Body;
			this.Location = Location;
			this.HeaderLocation = HeaderLocation;
			this.NameLocation = NameLocation;
			this.LeftParenLocation = LeftParenLocation;
			this.RightParenLocation = RightParenLocation;
		}
Пример #22
0
		public IfStatement (Expression Condition, Statement IfBody, Statement ElseBody, TextSpan Location,
				    TextSpan HeaderLocation, TextPoint LeftParen, TextPoint RightParen, TextPoint Else)
			: base (Operation.If, Location)
		{
			this.Condition = Condition;
			this.IfBody = IfBody;
			this.ElseBody = ElseBody;
			this.HeaderLocation = HeaderLocation;
			this.LeftParen = LeftParen;
			this.RightParen = RightParen;
			this.Else = Else;
		}
Пример #23
0
        internal static string GetTextToFirstMatch(TextPoint startPoint, string matchString)
        {
            var startEditPoint = startPoint.CreateEditPoint();
            var endEditPoint = startEditPoint.CreateEditPoint();
            TextRanges subGroupMatches = null;

            if (endEditPoint.FindPattern(matchString, StandardFindOptions, ref endEditPoint, ref subGroupMatches))
            {
                return startEditPoint.GetText(endEditPoint);
            }

            return null;
        }
Пример #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CodeComment" /> class.
        /// </summary>
        public CodeComment(TextPoint point)
        {
            if (point == null)
            {
                throw new ArgumentNullException("point");
            }

            _document = point.Parent;

            _commentLineRegex = CodeCommentHelper.GetCommentRegex(_document.Language, true);

            Expand(point);
        }
Пример #25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CodeComment" /> class.
        /// </summary>
        public CodeComment(TextPoint point, int tabSize)
        {
            if (point == null)
            {
                throw new ArgumentNullException(nameof(point));
            }

            _document = point.Parent;
            _commentLineRegex = CodeCommentHelper.GetCommentRegex(_document.GetCodeLanguage());
            _tabSize = tabSize;

            Expand(point);
        }
Пример #26
0
 /// <summary>
 /// Returns function declaration line from source code.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="document">The document.</param>
 /// <param name="startPoint">The start point.</param>
 /// <returns></returns>
 public static TextPoint GetFunctionDeclarationFromSource(string name, TextDocument document, TextPoint startPoint)
 {
     TextPoint endPoint = null;
     var functionLineText = GetCodeLineText(document, startPoint.Line);
     if (!string.IsNullOrEmpty(functionLineText))
     {
         int startIndex = functionLineText.ToLower().IndexOf("function", StringComparison.CurrentCultureIgnoreCase);
         if (startIndex > -1)
         {
             int nameIndex = functionLineText.IndexOf(name);
             endPoint = new LuaTextPoint(document, nameIndex + name.Length + 2, startPoint.Line);
         }
     }
     return endPoint;
 }
Пример #27
0
      static public CodeElement FindInnerMostCodeElement(CodeElements elements, TextPoint p)
      {
         foreach (CodeElement ce in elements)
         {
            if (CodeElementContainsPoint(ce, p))
            {
               CodeElement ce2 = FindInnerMostCodeElement(ce.Children, p);

               if (ce2 == null) return ce;
               else return ce2;
            }
         }

         return null;
      }
Пример #28
0
        /// <summary>
        /// An event handler for a line being changed.
        /// </summary>
        /// <param name="startPoint">The starting point of the change.</param>
        /// <param name="endPoint">The ending point of the change.</param>
        /// <param name="hint">A hint as to the type of change that has occurred.</param>
        private void TextEditorEvents_LineChanged(TextPoint startPoint, TextPoint endPoint, int hint)
        {
            var textDocument = startPoint?.Parent;
            if (textDocument == null) return;

            var document = startPoint.Parent.Parent;

            var onLineChanged = OnLineChanged;
            if (onLineChanged != null && document != null)
            {
                OutputWindowHelper.DiagnosticWriteLine($"TextEditorEventListener.OnLineChanged raised for '{document.FullName}'");

                onLineChanged(document);
            }
        }
Пример #29
0
		//=========================================================================================
		public List<Token> Parse(List<string> lines)
		{
			List<Token> tokens = new List<Token>();

			this.Lines = lines;
			this.CurPos = new TextPoint();
			//string sWord = string.Empty;
			int iWordLen = 0;

			while (true)
			{
				if (!this.SkipWhiteSpaces())
					break;
				iWordLen = this.GetNextWordLength();
				if (iWordLen == 0)
					break;

				string sLine = this.Lines[this.CurPos.Line];
				BoundedElement oVarGroup = null;
				foreach (string sKey in this.QuotedTokenRules.Keys)
					if (string.Compare(sLine, this.CurPos.Char, sKey, 0, sKey.Length, false) == 0)
					{
						oVarGroup = this.QuotedTokenRules[sKey];
						break;
					}
				if (oVarGroup != null)
				{
					this.GetQuotedToken(tokens, oVarGroup);
					continue;
				}
				string sWord = sLine.Substring(this.CurPos.Char, iWordLen);
				TextStyle oStyle;
				if (this.charMap[(byte)sWord[0]] == LetterType.Operator)
					oStyle = this.Settings.OperatorsTextStyle;
				else
				{
					if (!this.KeywordsMap.TryGetValue(sWord, out oStyle))
						oStyle = this.Settings.NormalTextStyle;
				}

				TextPoint oStart = this.CurPos;
				this.CurPos.Char += iWordLen;
				this.CurPos.Col += iWordLen;
				tokens.Add(new Token(sWord, oStart, this.CurPos, oStyle));
			}

			return tokens;
		}
        private void dumpCursorInfo(TextPoint cursor)
        {
            // Discover every code element containing the insertion point.
            string elems = "";
            vsCMElement scopes = 0;

            foreach (vsCMElement scope in Enum.GetValues(scopes.GetType()))
            {
                CodeElement elem = cursor.CodeElement[scope];

                if (elem != null)
                {
                    elems += elem.Name +
                             " (" + scope.ToString() + ")\n";
                }
            }
            Debug.WriteLine(elems);
        }
Пример #31
0
        /// <summary>
        /// Used by C# ad-hoc methods (move and inline) to get information about the block of code, where right-click was performed.
        /// This methods makes use of document's FileCodeModel, which is not available for ASP .NET files - these files are thus
        /// handled by their own parser.
        /// </summary>
        /// <param name="text">Text of the block (e.g. code of a method, declaration of a variable...)</param>
        /// <param name="startPoint">Beginning of the text</param>
        /// <param name="codeFunctionName">Name of the function, where right-click was performed, null if right-click was performed on a variable.</param>
        /// <param name="codeVariableName">Name of the variable, where right-click was performed, null otherwise.</param>
        /// <param name="codeClass">Name of the class, where the code block is located.</param>
        /// <param name="selectionSpan">Current selection span.</param>
        /// <returns>True, if all necessary information was succesfully obtained, false otherwise.</returns>
        protected bool GetCodeBlockFromSelection(out string text, out TextPoint startPoint, out string codeFunctionName, out string codeVariableName, out CodeElement2 codeClass, out TextSpan selectionSpan, out bool isConst, out object codeModelSource)
        {
            // get current selection span
            TextSpan[] spans = new TextSpan[1];
            int        hr    = textView.GetSelectionSpan(spans);

            Marshal.ThrowExceptionForHR(hr);

            selectionSpan = spans[0];

            object o;

            hr = textLines.CreateTextPoint(selectionSpan.iStartLine, selectionSpan.iStartIndex, out o);
            Marshal.ThrowExceptionForHR(hr);
            TextPoint selectionPoint = (TextPoint)o;

            startPoint = null;
            text       = null;
            bool ok = false;

            codeFunctionName = null;
            codeVariableName = null;
            codeClass        = null;
            isConst          = false;
            codeModelSource  = null;

            // It is impossible to find out the code block, where right-click was performed. Following code
            // assumes that valid string literals or references can only be found in a method, in a class variable (as initializers)
            // or in a property code. C# syntax permits more locations (attributes, default argument values in .NET 4+) but we can ignore
            // these, because they are all evaluated at compile-time, making resource references impossible.

            // assume we are in a function (method)
            try {
                CodeFunction2 codeFunction = (CodeFunction2)currentCodeModel.CodeElementFromPoint(selectionPoint, vsCMElement.vsCMElementFunction);
                codeFunctionName = codeFunction.Name;
                codeClass        = codeFunction.GetClass(); // extension
                codeModelSource  = codeFunction;

                text = codeFunction.GetText();
                if (!string.IsNullOrEmpty(text))
                {
                    startPoint = codeFunction.GetStartPoint(vsCMPart.vsCMPartBody);
                    ok         = true;
                }
            } catch (Exception) {
                // it's not a method - maybe a property?
                try {
                    CodeProperty codeProperty = (CodeProperty)currentCodeModel.CodeElementFromPoint(selectionPoint, vsCMElement.vsCMElementProperty);
                    codeFunctionName = codeProperty.Name;
                    codeClass        = codeProperty.GetClass();
                    codeModelSource  = codeProperty;
                    text             = codeProperty.GetText();

                    if (!string.IsNullOrEmpty(text))
                    {
                        startPoint = codeProperty.GetStartPoint(vsCMPart.vsCMPartBody);
                        ok         = true;
                    }
                } catch (Exception) {
                    // not a property, either. It must be a variable - or there's no valid code block
                    try {
                        CodeVariable2 codeVariable = (CodeVariable2)currentCodeModel.CodeElementFromPoint(selectionPoint, vsCMElement.vsCMElementVariable);
                        if (codeVariable.InitExpression != null)
                        {
                            codeVariableName = codeVariable.Name;
                            codeClass        = codeVariable.GetClass();
                            isConst          = codeVariable.ConstKind == vsCMConstKind.vsCMConstKindConst;
                            codeModelSource  = codeVariable;

                            startPoint = codeVariable.StartPoint;
                            text       = codeVariable.GetText();
                            if ((codeClass.Kind == vsCMElement.vsCMElementStruct && codeVariable.IsShared) ||
                                (codeClass.Kind == vsCMElement.vsCMElementClass || codeClass.Kind == vsCMElement.vsCMElementModule) &&
                                !string.IsNullOrEmpty(text))
                            {
                                ok = true;
                            }
                        }
                    } catch (Exception) {
                        return(false);
                    }
                }
            }

            return(ok);
        }
        /// <summary>Parses for strings by iterating through the text lines.</summary>
        /// <param name="element">The element.</param>
        /// <param name="stringResources">The string resources.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="isCSharp">If set to <c>true</c> it is CSharp code.</param>
        /// <param name="startLine">The start line.</param>
        /// <param name="endLine">The end line.</param>
        /// <returns>The last parsed line number or -1.</returns>
        private static int ParseForStrings(CodeElement element,
                                           List <StringResource> stringResources,
                                           Settings settings,
                                           bool isCSharp,
                                           int startLine,
                                           int endLine)
        {
            TextPoint startPoint = element.StartPoint,
                      endPoint   = element.EndPoint;
            EditPoint2 editPoint = null;

            try
            {
                if (element.Kind == vsCMElement.vsCMElementFunction)
                {
#if DEBUG_OUTPUT
                    System.Diagnostics.Debug.Print("    function kind: {0}", (element as CodeFunction).FunctionKind);
#endif

                    try
                    {
                        //we want to have the body only (throws COMException when inspecting an expression bodied function)
                        startPoint = element.GetStartPoint(vsCMPart.vsCMPartBody);
                        endPoint   = element.GetEndPoint(vsCMPart.vsCMPartBody);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.Print("ParseForStrings(vsCMElementFunction, line {0}): {1} - {2}", startPoint.Line, ex.GetType().Name, ex.Message);
                    }
                }

                editPoint = startPoint.CreateEditPoint() as EditPoint2;

                int editLine       = editPoint.Line,
                    editColumn     = editPoint.LineCharOffset;
                string   text      = editPoint.GetText(endPoint);
                string[] txtLines  = text.Replace("\r", string.Empty).Split('\n');
                bool     isComment = false;
#if IGNORE_METHOD_ARGUMENTS
                bool isIgnoreMethodArguments = false;
#endif

                foreach (string txtLine in txtLines)
                {
                    if ((editLine >= startLine) && (editLine <= endLine))
                    {
                        //this is a changed text line in the block

#if !IGNORE_METHOD_ARGUMENTS
                        if (txtLine.Contains("\""))
                        {
                            ParseForStrings(txtLine, editLine, editColumn, stringResources, settings, isCSharp, ref isComment);
                        }
#else
                        if (line.Contains("\""))
                        {
                            ParseForStrings(line, editLine, editColumn, stringResources, settings, ref isComment, ref isIgnoreMethodArguments);
                        }
#endif
                    }

                    ++editLine;

                    //only for the first line of the text block LineCharOffset will be used
                    if (editColumn > 1)
                    {
                        editColumn = 1;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print("### Error: ParseForStrings(): {0} - {1}", ex.GetType().Name, ex.Message);
            }

            return(endPoint?.Line ?? (-1));
        }
Пример #33
0
 public IndentSquareBracket(TextPoint start, TextPoint end, IndentSquareBracket parent)
 {
     Start  = start.CreateEditPoint();//需要创建一个新的,相当于复制,不然后面操作,会影响到其他的
     End    = end.CreateEditPoint();
     Parent = parent;
 }
 public override void SelectRange(TextPoint selectionStart, TextPoint selectionEnd)
 {
     this.SelectRange(selectionStart.CurrentPosition, selectionEnd.CurrentPosition);
 }
Пример #35
0
        public static bool ViewPoint(TextMap map, int index)
        {
            TextPoint point = map[index];

            if (point == null)
            {
                Console.WriteLine("Такого элемента нет");
                return(false);
            }
            else
            {
                Console.WriteLine("Точка №{0} {1}", point.Number, (point.IsFinal) ? "финальная" : "");

                Console.WriteLine("Основной текст - " + point.TableText);

                Console.WriteLine("С размером шрифта {0}px", point.TextSize);

                switch (point.ColorPack)
                {
                case 1:
                {
                    Console.Write("Нормальный");
                    break;
                }

                case 2:
                {
                    Console.Write("Пессимистичный");
                    break;
                }

                case 3:
                {
                    Console.Write("Весёлый");
                    break;
                }

                case 4:
                {
                    Console.Write("Злой");
                    break;
                }

                case 5:
                {
                    Console.Write("Радужный");
                    break;
                }
                }
                Console.WriteLine(" цвет");

                if (point.IsFinal)
                {
                    return(false);
                }

                Console.WriteLine("Ответы:");
                if (point.NextTo(1) == 0)
                {
                    Console.WriteLine("Да - 0");
                }
                else if (map[point.NextTo(1)] == null)
                {
                    Console.WriteLine("Да - {0}, точки нет", point.NextTo(1));
                }
                else
                {
                    Console.WriteLine("Да - {0}, {1}", point.NextTo(1), map.Preview(point, 1));
                }

                if (point.NextTo(2) == 0)
                {
                    Console.WriteLine("Нет - 0");
                }
                else if (map[point.NextTo(2)] == null)
                {
                    Console.WriteLine("Нет - {0}, точки нет", point.NextTo(2));
                }
                else
                {
                    Console.WriteLine("Нет - {0}, {1}", point.NextTo(2), map.Preview(point, 2));
                }

                if (point.NextTo(3) == 0)
                {
                    Console.WriteLine("Альтернативный - 0");
                }
                else if (map[point.NextTo(3)] == null)
                {
                    Console.WriteLine("{1} - {0}, точки нет", point.NextTo(3), point.AlterText);
                }
                else
                {
                    Console.WriteLine("{2} - {0}, {1}", point.NextTo(3), map.Preview(point, 3), point.AlterText);
                }

                if (point.NextTo(1) == 0 && point.NextTo(2) == 0 && point.NextTo(3) == 0)
                {
                    return(false);
                }
                return(true);
            }
        }
Пример #36
0
 //=========================================================================================
 public Token(string text, TextPoint start, TextPoint end, TextStyle style)
     : this(null, text, start, end, style)
 {
 }
Пример #37
0
        private static CodeElement CodeElementFromMember(TextPoint Point, vsCMElement Scope, CodeTypeMember ctm)
        {
            CodeElement res = CheckAttributes(Point, Scope, ctm.CustomAttributes);

            if (res != null)
            {
                return(res);
            }

            CodeMemberMethod method = ctm as CodeMemberMethod;

            if (method != null)
            {
                if (Scope == vsCMElement.vsCMElementFunction)
                {
                    if (IsInBlockRange(method, Point))
                    {
                        return((CodeElement)method.UserData[CodeKey]);
                    }
                }
                //!!! walk method
                if (Scope == vsCMElement.vsCMElementParameter || Scope == vsCMElement.vsCMElementAttribute)
                {
                    foreach (CodeParameterDeclarationExpression param in method.Parameters)
                    {
                        if (IsInRange(param, Point))
                        {
                            return((CodeElement)method.UserData[CodeKey]);
                        }

                        res = CheckAttributes(Point, Scope, param.CustomAttributes);
                        if (res != null)
                        {
                            return(res);
                        }
                    }

                    foreach (CodeTypeParameter ctp in method.TypeParameters)
                    {
                        if (IsInRange(ctp, Point))
                        {
                            return((CodeElement)method.UserData[CodeKey]);
                        }

                        res = CheckAttributes(Point, Scope, ctp.CustomAttributes);
                        if (res != null)
                        {
                            return(res);
                        }
                    }
                }

                res = CheckAttributes(Point, Scope, method.ReturnTypeCustomAttributes);
                if (res != null)
                {
                    return(res);
                }

                res = WalkStatements(Point, Scope, method.Statements);
                if (res != null)
                {
                    return(res);
                }
            }
            else if (ctm is CodeMemberEvent)
            {
                if (Scope == vsCMElement.vsCMElementEvent)
                {
                    if (IsInRange(ctm, Point))
                    {
                        return((CodeElement)ctm.UserData[CodeKey]);
                    }
                }
            }
            else if (ctm is CodeMemberProperty)
            {
                CodeMemberProperty cmp = ctm as CodeMemberProperty;

                foreach (CodeParameterDeclarationExpression param in cmp.Parameters)
                {
                    if (IsInRange(param, Point))
                    {
                        return((CodeElement)method.UserData[CodeKey]);
                    }

                    res = CheckAttributes(Point, Scope, param.CustomAttributes);
                    if (res != null)
                    {
                        return(res);
                    }
                }

                if (Scope == vsCMElement.vsCMElementProperty)
                {
                    if (IsInBlockRange(ctm, Point))
                    {
                        return((CodeElement)ctm.UserData[CodeKey]);
                    }
                }

                if (cmp.HasGet)
                {
                    WalkStatements(Point, Scope, cmp.GetStatements);
                }
                if (cmp.HasSet)
                {
                    WalkStatements(Point, Scope, cmp.SetStatements);
                }
            }
            else if (ctm is CodeMemberField)
            {
                if (Scope == vsCMElement.vsCMElementVariable)
                {
                    if (IsInRange(ctm, Point))
                    {
                        return((CodeElement)ctm.UserData[CodeKey]);
                    }
                }
            }
            return(null);
        }
Пример #38
0
        /// <summary>
        /// Given a point and an element type to search for returns the element of that type at that point
        /// or null if no element is found.
        /// </summary>
        public CodeElement CodeElementFromPoint(TextPoint Point, vsCMElement Scope)
        {
            Initialize();

            CodeElement res;

            foreach (CDCodeNamespace cn in _ccu.Namespaces)
            {
                if (Scope == vsCMElement.vsCMElementNamespace)
                {
                    if (IsInBlockRange(cn, Point))
                    {
                        EnsureNamespaceLinked(cn);
                        return((CodeElement)cn.UserData[CodeKey]);
                    }
                }

                if (Scope == vsCMElement.vsCMElementImportStmt)
                {
                    foreach (CodeNamespaceImport import in cn.Imports)
                    {
                        if (IsInRange(import, Point))
                        {
                            return((CodeElement)import.UserData[CodeKey]);
                        }
                    }

                    continue;
                }

                foreach (CodeTypeDeclaration ctd in cn.Types)
                {
                    res = CheckAttributes(Point, Scope, ctd.CustomAttributes);
                    if (res != null)
                    {
                        return(res);
                    }

                    if ((ctd.IsClass && Scope == vsCMElement.vsCMElementClass) ||
                        (ctd.IsEnum && Scope == vsCMElement.vsCMElementEnum) ||
                        (ctd.IsInterface && Scope == vsCMElement.vsCMElementInterface) ||
                        (ctd.IsStruct && Scope == vsCMElement.vsCMElementStruct))
                    {
                        if (IsInBlockRange(ctd, Point))
                        {
                            return((CodeElement)ctd.UserData[CodeKey]);
                        }

                        continue;
                    }

                    foreach (CodeTypeMember ctm in ctd.Members)
                    {
                        res = CodeElementFromMember(Point, Scope, ctm);
                        if (res != null)
                        {
                            return(res);
                        }
                    }
                }
            }
            return(null);
        }
 public TextRange CreateTextRange(TextBuffer textBuffer, TextPoint startPoint, TextPoint endPoint)
 {
     return(new DefaultTextRangePrimitive(startPoint, endPoint, EditorOptionsFactoryService));
 }
Пример #40
0
        private void ReorderMembers(CodeElement2 type, IEnumerable <CodeMember> members, string orderedCode, TextPoint startPoint)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // Removing members will shift the startPoint back one line.
            // So we'll use the absolute offset to jump back to that insert point.
            int startPointOffset = 0;

            if (startPoint != null)
            {
                startPointOffset = startPoint.AbsoluteCharOffset;
            }

            FileCodeModel2 codeModel = this.textHandler.Document.ProjectItem.FileCodeModel as FileCodeModel2;

            codeModel.BeginBatch();
            try
            {
                foreach (CodeMember member in members)
                {
                    member.Remove();
                }
            }
            finally
            {
                codeModel.EndBatch();
            }

            if (startPoint != null)
            {
                EditPoint startEdit = startPoint.CreateEditPoint();
                startEdit.MoveToAbsoluteOffset(startPointOffset);
                startEdit.StartOfLine();

                // If the line above startEdit isn't empty and isn't the start of the class/struct/interface/enum,
                // then insert a blank line so the sortedCode will be separated from the code above it.
                EditPoint lineAboveEdit = startEdit.CreateEditPoint();
                lineAboveEdit.LineUp();
                lineAboveEdit.StartOfLine();
                string lineText = lineAboveEdit.GetText(lineAboveEdit.LineLength).Trim();
                if (lineText.Length != 0 &&
                    lineAboveEdit.Line > type.StartPoint.Line &&
                    (this.language != Language.CSharp || lineText != "{"))
                {
                    startEdit.Insert(Environment.NewLine);
                }

                startEdit.Insert(orderedCode);

                // If the line after startEdit isn't empty and isn't the end of the class/struct/interface/enum,
                // then insert a blank line so the sortedCode will be separated from the code below it.
                startEdit.StartOfLine();
                lineText = startEdit.GetText(startEdit.LineLength).Trim();
                if (lineText.Length != 0 &&
                    startEdit.Line < type.EndPoint.Line &&
                    (this.language != Language.CSharp || lineText != "}"))
                {
                    startEdit.Insert(Environment.NewLine);
                }
            }
        }
Пример #41
0
 /// <summary>
 /// Sets the position of the caret
 /// </summary>
 /// <param name="pos">Point containing the new x and y positions</param>
 public void SetPos(TextPoint pos)
 {
     this.Position = pos;
     RememberXPos();
 }
Пример #42
0
 /// <summary>
 /// </summary>
 public LineWidth(TextPoint start, Double width)
 {
     _start = start;
     _width = width;
 }
Пример #43
0
 public bool LessThan(TextPoint Point)
 {
     throw new NotImplementedException();
 }
Пример #44
0
 public override TextRange Find(string pattern, TextPoint endPoint)
 {
     return(_bufferPoint.Find(pattern, endPoint));
 }
Пример #45
0
 public override TextRange GetTextRange(TextPoint otherPoint)
 {
     return(_bufferPoint.GetTextRange(otherPoint));
 }
Пример #46
0
 /// <summary>
 /// Constructs new position.
 /// </summary>
 /// <param name="position">Position within document.</param>
 public ShortPosition(TextPoint position)
     : this(position.Line, position.Column)
 {
 }
Пример #47
0
 public IfStatement(Expression Condition, Statement IfBody, Statement ElseBody, TextSpan Location,
                    TextSpan HeaderLocation, TextPoint LeftParen, TextPoint RightParen, TextPoint Else)
     : base(Operation.If, Location)
 {
     this.Condition      = Condition;
     this.IfBody         = IfBody;
     this.ElseBody       = ElseBody;
     this.HeaderLocation = HeaderLocation;
     this.LeftParen      = LeftParen;
     this.RightParen     = RightParen;
     this.Else           = Else;
 }
Пример #48
0
 public bool GreaterThan(TextPoint Point)
 {
     throw new NotImplementedException();
 }
 public override void SetStart(TextPoint startPoint)
 {
     this.SelectRange(startPoint.CurrentPosition, GetDisplayEndPoint().CurrentPosition);
 }
Пример #50
0
 public DeclarationForStatement(List <VariableDeclarationListElement> Initial, Expression Condition, Expression Increment, Statement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint FirstSemicolon, TextPoint SecondSemicolon, TextPoint LeftParen, TextPoint RightParen)
     : base(Operation.DeclarationFor, Condition, Increment, Body, Location, HeaderLocation, FirstSemicolon, SecondSemicolon, LeftParen, RightParen)
 {
     this.Initial = Initial;
 }
 public override void SetEnd(TextPoint endPoint)
 {
     this.ExtendSelection(endPoint);
 }
 private void OnLineChanged(TextPoint StartPoint, TextPoint EndPoint, int Hint)
 {
     _documentManager.UpdateUserActivity();
 }
        public override bool Indent()
        {
            bool singleLineSelection = (GetStartPoint().LineNumber == GetEndPoint().LineNumber);
            bool entireLastLineSelected
                = (GetStartPoint().CurrentPosition != GetEndPoint().CurrentPosition&&
                   GetStartPoint().CurrentPosition == TextBuffer.GetEndPoint().StartOfLine&&
                   GetEndPoint().CurrentPosition == TextBuffer.GetEndPoint().EndOfLine);

            if (singleLineSelection && !entireLastLineSelected)
            {
                TextPoint endPoint = GetEndPoint();
                if (!Delete())
                {
                    return(false);
                }
                if (!endPoint.InsertIndent())
                {
                    return(false);
                }
                TextView.AdvancedTextView.Caret.MoveTo(endPoint.AdvancedTextPoint);
            }
            else // indent the selected lines
            {
                VirtualSnapshotPoint oldStartPoint = TextSelection.Start;
                VirtualSnapshotPoint oldEndPoint   = TextSelection.End;
                bool isReversed = TextSelection.IsReversed;

                ITextSnapshotLine startLine = AdvancedTextRange.Snapshot.GetLineFromPosition(oldStartPoint.Position);
                ITextSnapshotLine endLine   = AdvancedTextRange.Snapshot.GetLineFromPosition(oldEndPoint.Position);

                // If the selection span initially starts at the whitespace at the beginning of the line in the startLine or
                // ends at the whitespace at the beginning of the line in the endLine, restore selection and caret position,
                // *unless* the selection was in box mode.
                bool startAtStartLineWhitespace = oldStartPoint.Position <= _textView.GetTextPoint(startLine.Start).GetFirstNonWhiteSpaceCharacterOnLine().CurrentPosition;
                bool endAtEndLineWhitespace     = oldEndPoint.Position < _textView.GetTextPoint(endLine.Start).GetFirstNonWhiteSpaceCharacterOnLine().CurrentPosition;
                bool isBoxSelection             = AdvancedSelection.Mode == TextSelectionMode.Box;

                if (isBoxSelection)
                {
                    if (!this.BoxIndent())
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!TextRange.Indent())
                    {
                        return(false);
                    }
                }

                // Computing the new selection and caret position
                VirtualSnapshotPoint newStartPoint = TextSelection.Start;
                VirtualSnapshotPoint newEndPoint   = TextSelection.End;

                if (!isBoxSelection && (startAtStartLineWhitespace || endAtEndLineWhitespace))
                {
                    // After indent selection span should start at the start of startLine and end at the start of endLine
                    if (startAtStartLineWhitespace)
                    {
                        newStartPoint = new VirtualSnapshotPoint(AdvancedTextRange.Snapshot, oldStartPoint.Position.Position);
                    }

                    if (endAtEndLineWhitespace && oldEndPoint.Position.Position != endLine.Start && endLine.Length != 0)
                    {
                        int insertedTextSize = _editorOptions.IsConvertTabsToSpacesEnabled() ? _editorOptions.GetTabSize() : 1;
                        newEndPoint = new VirtualSnapshotPoint(AdvancedTextRange.Snapshot, newEndPoint.Position.Position - insertedTextSize);
                    }

                    if (!isReversed)
                    {
                        TextSelection.Select(newStartPoint, newEndPoint);
                    }
                    else
                    {
                        TextSelection.Select(newEndPoint, newStartPoint);
                    }

                    TextView.AdvancedTextView.Caret.MoveTo(TextSelection.ActivePoint, PositionAffinity.Successor);
                }
            }
            TextView.AdvancedTextView.Caret.EnsureVisible();
            return(true);
        }
Пример #54
0
 public bool EqualTo(TextPoint Point)
 {
     throw new NotImplementedException();
 }
Пример #55
0
 public QualifiedExpression(Expression Base, Identifier Qualifier, TextSpan Location, TextPoint DotLocation, TextPoint QualifierLocation)
     : base(Operation.Qualified, Location)
 {
     this.Base              = Base;
     this.Qualifier         = Qualifier;
     this.DotLocation       = DotLocation;
     this.QualifierLocation = QualifierLocation;
 }
Пример #56
0
 public LabelStatement(Identifier Label, Statement Labeled, TextSpan Location, TextPoint Colon)
     : base(Operation.Label, Location)
 {
     this.Label   = Label;
     this.Labeled = Labeled;
     this.Colon   = Colon;
 }
        /// <summary>Parses for strings by iterating through the FileCodeModel.</summary>
        /// <param name="startPoint">The start point.</param>
        /// <param name="endPoint">The end point.</param>
        /// <param name="lastDocumentLength">Last length of the document.</param>
        private void ParseForStrings(TextPoint startPoint,
                                     TextPoint endPoint,
                                     int lastDocumentLength)
        {
            //0.35-0.06 seconds (threaded: 2.47-1.77 seconds)
            List <StringResource> stringResources = new List <StringResource>();

            bool isFullDocument          = startPoint.AtStartOfDocument && endPoint.AtEndOfDocument,
                 isTextWithStringLiteral = true;
            int startLine      = startPoint.Line,
                startCol       = startPoint.LineCharOffset,
                endLine        = endPoint.Line,
                endCol         = endPoint.LineCharOffset,
                documentLength = endPoint.Parent.EndPoint.Line,
                insertIndex    = 0;

            if (isFullDocument)
            {
                m_StringResources.Clear();
            }
            else
            {
                #region document manipulated -> adapt string resources and locations

                //determine whether the text between startLine and endLine (including) contains double quotes
                EditPoint editPoint = startPoint.CreateEditPoint() as EditPoint2;
                if (!startPoint.AtStartOfLine)
                {
                    editPoint.StartOfLine();
                }
                isTextWithStringLiteral = editPoint.GetLines(startLine, endLine + 1).Contains("\"");

                //move trailing locations behind changed lines if needed and
                //remove string resources on changed lines

                int lineOffset = documentLength - lastDocumentLength;
#if DEBUG_OUTPUT
                System.Diagnostics.Debug.Print("  Line offset is {0}", lineOffset);
#endif

                for (int i = m_StringResources.Count - 1; i >= 0; --i)
                {
                    StringResource stringResource = m_StringResources[i];
                    int            lineNo         = stringResource.Location.X;

                    if (lineNo + lineOffset > endLine)
                    {
                        if (lineOffset != 0)
                        {
#if DEBUG_OUTPUT
                            System.Diagnostics.Debug.Print("  Move string literal from line {0} to {1}", lineNo, lineNo + lineOffset);
#endif
                            stringResource.Offset(lineOffset, 0); //move
                        }
                    }
                    else if (lineNo >= startLine)
                    {
#if DEBUG_OUTPUT
                        System.Diagnostics.Debug.Print("  Remove string literal {0} ({1}): {2}", i, stringResource.Location, stringResource.Text);
#endif
                        m_StringResources.RemoveAt(i); //remove changed line
                    }
                    else if (insertIndex == 0)
                    {
#if DEBUG_OUTPUT
                        System.Diagnostics.Debug.Print("  List insert index is {0} / {1}", i + 1, m_StringResources.Count - 1);
#endif
                        insertIndex = i + 1;
                    }
                }

                #endregion
            }

#if DEBUG_OUTPUT
            System.Diagnostics.Debug.Print("  Text has{0} string literals.", isTextWithStringLiteral ? string.Empty : " no");
#endif

            if (isTextWithStringLiteral)
            {
                CodeElements elements = m_Window.Document.ProjectItem.FileCodeModel.CodeElements;

                foreach (CodeElement element in elements)
                {
                    ParseForStrings(element, m_DoProgress, stringResources, m_Settings, m_IsCSharp, startLine, endLine);

#if DEBUG
                    if (element.Kind == vsCMElement.vsCMElementProperty)
                    {
                        CodeProperty prop = element as CodeProperty;

                        if ((prop.Getter == null) && (prop.Setter == null))
                        {
                        }
                    }
#endif
                }

#if DEBUG_OUTPUT
                System.Diagnostics.Debug.Print("  Found {0} string literals", stringResources.Count);
#endif

                if (isFullDocument)
                {
                    m_StringResources.AddRange(stringResources);
                }
                else if (stringResources.Count > 0)
                {
                    m_StringResources.InsertRange(insertIndex, stringResources);
                }
            }

            m_DoCompleted(isFullDocument || (stringResources.Count > 0));
        }
Пример #58
0
 public override Collection <TextRange> FindAll(string pattern, FindOptions findOptions, TextPoint endPoint)
 {
     return(_bufferPoint.FindAll(pattern, findOptions, endPoint));
 }
Пример #59
0
        // to what control does the caret belong??

        #endregion

        #region Constructor(s)

        /// <summary>
        /// Caret constructor
        /// </summary>
        /// <param name="control">The control that will use the caret</param>
        public Caret(EditViewControl control)
        {
            Position = new TextPoint(0, 0);
            Control  = control;
        }
Пример #60
0
 public TextRange(TextPoint sp, TextPoint ep)
 {
     StartPoint = sp;
     EndPoint   = ep;
 }