예제 #1
0
        private void CopyFullyQualifiedNameInternal()
        {
            try
            {
                TextSelection sel =
                    (TextSelection)dte.ActiveDocument.Selection;
                TextPoint pnt = sel.ActivePoint as TextPoint;
                if (pnt == null)
                {
                    // Not in editor? Exit.
                    ActivityLog.LogWarning(NameForLogging.Value, "Can't obtain TextPoint, returning.");
                }

                // Discover every code element containing the insertion point.
                FileCodeModel fcm =
                    dte.ActiveDocument.ProjectItem.FileCodeModel;
                vsCMElement scopes = 0;

                // Super-dumb way of getting fully qualified name - find longest full name
                // Seems to be working. It is late and I don't want to invent some heuristic that depend on the Scope type
                string longestName = string.Empty;

                foreach (vsCMElement scope in Enum.GetValues(scopes.GetType()))
                {
                    CodeElement elem = null;
                    try
                    {
                        elem = fcm.CodeElementFromPoint(pnt, scope);

                        if (elem != null)
                        {
                            var name = elem.FullName;
                            if (name.Length > longestName.Length)
                            {
                                longestName = name;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ActivityLog.LogInformation(this.GetType().FullName, "Unable to get code element, exception: " + ex.Message);
                        continue;
                    }
                }

                if (!string.IsNullOrWhiteSpace(longestName))
                {
                    Clipboard.SetText(longestName);
                }
            }
            catch (Exception ex)
            {
                ActivityLog.LogError(this.GetType().FullName, "Error when trying to copy fully qualified name: " + ex.Message);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        private OnDemandRun getFromCodeModel()
        {
            try
            {
                getCodeFromPosition();

                foreach (vsCMElement scope in Enum.GetValues(_scopes.GetType()))
                {
                    if (!validScope(scope))
                    {
                        continue;
                    }

                    try
                    {
                        CodeElement elem = _fcm.CodeElementFromPoint(_point, scope);
                        if (elem == null)
                        {
                            continue;
                        }

                        analyzeElement(elem);
                    }
                    catch (Exception ex)
                    {
                        AutoTest.Core.DebugLog.Debug.WriteException(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                AutoTest.Core.DebugLog.Debug.WriteException(ex);
            }
            if (_test.Length > 0 || _member.Length > 0)
            {
                return(new OnDemandRun(_project, _test, _member, new string[] { }));
            }
            else
            {
                return(new OnDemandRun(_project, _test, _member, _namespace));
            }
        }
예제 #4
0
        private void CodeModelCmdEvent_Click(object CommandBarControl, ref bool Handled, ref bool CancelDefault)
        {
            TextSelection selected = _applicationObject.ActiveDocument.Selection as TextSelection;
            //EditPoint topPoint = selected.TopPoint.CreateEditPoint();
            //EditPoint bottomPoint = selected.BottomPoint.CreateEditPoint();
            TextPoint   pnt    = (TextPoint)selected.ActivePoint;
            vsCMElement scopes = 0;
            string      elems  = string.Empty;

            foreach (vsCMElement scope in Enum.GetValues(scopes.GetType()))
            {
                CodeElement elem = pnt.get_CodeElement(scope);
                if (elem != null)
                {
                    elems += elem.Name + " (" + scope.ToString() + ") \n";
                }
            }

            MessageBox.Show(elems);
        }
예제 #5
0
        private static void CodeElementsByScopes(StringBuilder sb, VirtualPoint activePoint)
        {
            sb.AppendLine("Code elements");

            string      elems  = "";
            vsCMElement scopes = 0;

            foreach (vsCMElement scope in Enum.GetValues(scopes.GetType()))
            {
                CodeElement elem = activePoint.get_CodeElement(scope);

                if (elem != null)
                {
                    elems += elem.Name +
                             " (" + scope.ToString() + ")\n";
                }
            }

            sb.Append(elems);
        }