Ejemplo n.º 1
0
        public void GetStartPoint_WholeWithAttributes()
        {
            CodeNamespace testObject = GetCodeNamespace("A.B");
            TextPoint     startPoint = testObject.GetStartPoint(vsCMPart.vsCMPartWholeWithAttributes);

            Assert.Equal(18, startPoint.Line);
            Assert.Equal(1, startPoint.LineCharOffset);
        }
Ejemplo n.º 2
0
        public async Task GetStartPoint_Navigate()
        {
            CodeNamespace testObject = await GetCodeNamespaceAsync("A.B");

            TextPoint startPoint = testObject.GetStartPoint(vsCMPart.vsCMPartNavigate);

            Assert.Equal(18, startPoint.Line);
            Assert.Equal(11, startPoint.LineCharOffset);
        }
Ejemplo n.º 3
0
        public void GetStartPoint_Navigate()
        {
            CodeNamespace testObject = GetCodeNamespace("A.B");

            TextPoint startPoint = testObject.GetStartPoint(vsCMPart.vsCMPartNavigate);

            Assert.Equal(18, startPoint.Line);
            Assert.Equal(11, startPoint.LineCharOffset);
        }
Ejemplo n.º 4
0
        public static void Execute(ProjectItem projectItem)
        {
            var           txtSel    = (TextSelection)projectItem.Document.ActiveWindow.Selection;
            CodeNamespace nameSpace = SearchService.FindNameSpace(projectItem);

            MoveUsingsInsideNameSpace(projectItem, txtSel, nameSpace);

            var usings       = SearchService.FindUsings(nameSpace.Members);
            var systemUsings = new List <string>();

            if (!AreUsingStatementsOrdered(usings))
            {
                try
                {
                    projectItem.DTE.ExecuteCommand("ProjectandSolutionContextMenus.Project.PowerCommands.RemoveandSortUsings");
                }
                catch (Exception)
                {
                    try
                    {
                        projectItem.DTE.ExecuteCommand("Edit.RemoveAndSort");
                    }
                    catch
                    {
                        try
                        {
                            projectItem.DTE.ExecuteCommand("Edit.SortUsings");
                        }
                        catch { }
                    }
                }



                foreach (var systemUsing in usings)
                {
                    string txt = systemUsing.InnerText();
                    if (IsSystemUsingStatement(txt))
                    {
                        systemUsings.Add(txt);
                        systemUsing.Delete();
                    }
                }

                if (systemUsings.Any())
                {
                    var editPoint = nameSpace.GetStartPoint().CreateEditPoint();
                    editPoint.FindPattern("{", (int)vsFindOptions.vsFindOptionsNone, ref editPoint);
                    txtSel.MoveToPoint(editPoint);
                    foreach (var line in systemUsings)
                    {
                        txtSel.NewLine();
                        txtSel.Insert(line);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void GetStartPoint_Body()
        {
            CodeNamespace testObject = GetCodeNamespace("A.B");

            TextPoint startPoint = testObject.GetStartPoint(vsCMPart.vsCMPartBody);

            Assert.Equal(20, startPoint.Line);
            Assert.Equal(1, startPoint.LineCharOffset);
        }
Ejemplo n.º 6
0
        private static void MoveUsingsInsideNameSpace(ProjectItem projectItem, TextSelection txtSel, CodeNamespace nameSpace)
        {
            var usingsOutsideNameSpace = SearchService.FindUsings(projectItem.FileCodeModel.CodeElements);

            if (usingsOutsideNameSpace.Any())
            {
                List <string> linesToMove = new List <string>();
                for (int i = 0; i < usingsOutsideNameSpace.Count(); i++)
                {
                    linesToMove.Add(usingsOutsideNameSpace[i].InnerText());
                    usingsOutsideNameSpace[i].Delete();
                }

                var editPoint = nameSpace.GetStartPoint().CreateEditPoint();
                editPoint.FindPattern("{", (int)vsFindOptions.vsFindOptionsNone, ref editPoint);
                txtSel.MoveToPoint(editPoint);
                txtSel.NewLine();
                foreach (var line in linesToMove)
                {
                    txtSel.Insert(line);
                    txtSel.NewLine();
                }
            }
        }
Ejemplo n.º 7
0
        public async Task GetStartPoint_Whole()
        {
            CodeNamespace testObject = await GetCodeNamespaceAsync("A.B");

            Assert.Throws <NotImplementedException>(() => testObject.GetStartPoint(vsCMPart.vsCMPartWhole));
        }
Ejemplo n.º 8
0
        public async Task GetStartPoint_HeaderWithAttributes()
        {
            CodeNamespace testObject = await GetCodeNamespaceAsync("A.B");

            Assert.Throws <NotImplementedException>(() => testObject.GetStartPoint(vsCMPart.vsCMPartHeaderWithAttributes));
        }
Ejemplo n.º 9
0
        public async Task GetStartPoint_BodyWithDelimiter()
        {
            CodeNamespace testObject = await GetCodeNamespaceAsync("A.B");

            Assert.Throws <NotImplementedException>(() => testObject.GetStartPoint(vsCMPart.vsCMPartBodyWithDelimiter));
        }
Ejemplo n.º 10
0
        public async Task GetStartPoint_AttributesWithDelimiter()
        {
            CodeNamespace testObject = await GetCodeNamespaceAsync("A.B");

            Assert.Throws <COMException>(() => testObject.GetStartPoint(vsCMPart.vsCMPartAttributesWithDelimiter));
        }
Ejemplo n.º 11
0
        public void GetStartPoint_Whole()
        {
            CodeNamespace testObject = GetCodeNamespace("A.B");

            Assert.Throws <NotImplementedException>(() => testObject.GetStartPoint(vsCMPart.vsCMPartWhole));
        }
Ejemplo n.º 12
0
        public void GetStartPoint_AttributesWithDelimiter()
        {
            CodeNamespace testObject = GetCodeNamespace("A.B");

            Assert.Throws <COMException>(() => testObject.GetStartPoint(vsCMPart.vsCMPartAttributesWithDelimiter));
        }
        public void GetStartPoint_HeaderWithAttributes()
        {
            CodeNamespace testObject = GetCodeNamespace("A.B");

            AssertEx.Throws <NotImplementedException>(() => testObject.GetStartPoint(vsCMPart.vsCMPartHeaderWithAttributes));
        }
        public void GetStartPoint_BodyWithDelimiter()
        {
            CodeNamespace testObject = GetCodeNamespace("A.B");

            AssertEx.Throws <NotImplementedException>(() => testObject.GetStartPoint(vsCMPart.vsCMPartBodyWithDelimiter));
        }
		private static void MoveUsingsInsideNameSpace(ProjectItem projectItem, TextSelection txtSel, CodeNamespace nameSpace)
		{
			var usingsOutsideNameSpace = SearchService.FindUsings(projectItem.FileCodeModel.CodeElements);
			if (usingsOutsideNameSpace.Any())
			{
				List<string> linesToMove = new List<string>();
				for (int i = 0; i < usingsOutsideNameSpace.Count(); i++)
				{
					linesToMove.Add(usingsOutsideNameSpace[i].InnerText());
					usingsOutsideNameSpace[i].Delete();
				}

				var editPoint = nameSpace.GetStartPoint().CreateEditPoint();
				editPoint.FindPattern("{", (int)vsFindOptions.vsFindOptionsNone, ref editPoint);
				txtSel.MoveToPoint(editPoint);
				txtSel.NewLine();
				foreach (var line in linesToMove)
				{
					txtSel.Insert(line);
					txtSel.NewLine();
				}
			}
		}