Example #1
0
 public CheckCPPoint(VCCodeClass _ownerClass, string _projName, string _fileName, string _fileFullName, int _lineNum, int _linePos)
 {
     ownerClass   = _ownerClass;
     projName     = _projName;
     fileName     = _fileName;
     fileFullName = _fileFullName;
     lineNum      = _lineNum;
     linePos      = _linePos;
 }
Example #2
0
            private ClassElement GetClassImpl()
            {
                if (classElem == null)
                {
                    VCCodeClass targetClassElem = GetClassCodeElem();
                    if (targetClassElem != null)
                    {
                        classElem = new ClassElement(targetClassElem, this);
                    }
                }

                return(classElem);
            }
Example #3
0
        private bool IsElementAcceptableType(VCCodeElement element)
        {
            switch (element.Kind)
            {
            case vsCMElement.vsCMElementFunction:
                VCCodeFunction function = (VCCodeFunction)element;

                if (element.Name.StartsWith("~") ||
                    function.Access != vsCMAccess.vsCMAccessPublic)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }

            case vsCMElement.vsCMElementClass:
                VCCodeClass klass = (VCCodeClass)element;

                if (klass.Access != vsCMAccess.vsCMAccessPublic)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }

            case vsCMElement.vsCMElementNamespace:
                return(true);

            case vsCMElement.vsCMElementStruct:
                VCCodeStruct strukt = (VCCodeStruct)element;

                if (strukt.Access != vsCMAccess.vsCMAccessPublic)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }

            default:
                return(false);
            }
        }
Example #4
0
            public bool Validate(ITextPosition pos)
            {
                ent = fileElem.GetMethodCodeElemFromFilePos(pos);
                if (ent == null)
                {
                    return(false);
                }
                VCCodeClass targetClass = GetClassCodeElem();

                if (targetClass != null && !classElem.Validate(targetClass))
                {
                    return(false);
                }

                return(true);
            }
Example #5
0
        /**
         * Determines if a class is a valid CxxTest test suite by checking
         * for CxxTest::TestSuite in the superclass list.
         *
         * @param element the class handle to check
         *
         * @return true if the class is a test suite; otherwise, false.
         */
        private bool IsClassTestSuite(VCCodeClass klass)
        {
            foreach (VCCodeElement element in klass.Bases)
            {
                if (Constants.CxxTestSuiteClassRegex.IsMatch(element.Name))
                {
                    currentSuite = new TestSuite(klass);
                    testSuites.Add(currentSuite);

                    ProjectItem item = klass.ProjectItem;
                    if (item != null)
                    {
                        RemovePossibleTestFile(item);
                    }

                    return(true);
                }
            }

            return(false);
        }
        //~ Constructors .....................................................

        // ------------------------------------------------------
        /// <summary>
        /// Creates a new test suite based on the specified class in the VC
        /// code model.
        /// </summary>
        /// <param name="testClass">
        /// The VC code model class object from which to create the test
        /// suite.
        /// </param>
        public TestSuite(VCCodeClass testClass)
        {
            this.testClass = (VCCodeElement)testClass;

            Initialize();
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            try
            {
                if (VsShellUtilities.IsInAutomationFunction(m_provider.ServiceProvider))
                {
                    return(m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
                }

                // make a copy of this so we can look at it after forwarding some commands
                uint commandID = nCmdID;
                char typedChar = char.MinValue;

                // make sure the input is a char before getting it
                if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
                {
                    typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
                }

                // check for the triple slash
                if (typedChar == '!' && m_dte != null)
                {
                    var currentILine = m_textView.TextSnapshot.GetLineFromPosition(
                        m_textView.Caret.Position.BufferPosition.Position);
                    int    len             = m_textView.Caret.Position.BufferPosition.Position - currentILine.Start.Position;
                    string currentLine     = m_textView.TextSnapshot.GetText(currentILine.Start.Position, len);
                    string currentLineFull = currentILine.GetText();

                    if ((currentLine + typedChar).Trim() == "/*!")
                    {
                        // Calculate how many spaces
                        string        spaces    = currentLine.Replace(currentLine.TrimStart(), "");
                        TextSelection ts        = m_dte.ActiveDocument.Selection as TextSelection;
                        int           oldLine   = ts.ActivePoint.Line;
                        int           oldOffset = ts.ActivePoint.LineCharOffset;

                        if (!currentLineFull.Contains("*/"))
                        {
                            ts.Insert("*/");
                        }
                        ts.LineDown();
                        ts.EndOfLine();

                        CodeElement   codeElement = null;
                        FileCodeModel fcm         = m_dte.ActiveDocument.ProjectItem.FileCodeModel;
                        if (fcm != null)
                        {
                            while (codeElement == null)
                            {
                                codeElement = fcm.CodeElementFromPoint(ts.ActivePoint, vsCMElement.vsCMElementFunction);

                                if (codeElement == null)
                                {
                                    ts.LineDown();
                                }
                            }
                        }

                        var cls  = codeElement as VCCodeClass;
                        var cls2 = codeElement as CodeClass;
                        var fnc  = codeElement as VCCodeFunction;

                        var kind = codeElement.Kind;

                        if (codeElement != null && codeElement is CodeFunction)
                        {
                            VCCodeFunction function = codeElement as VCCodeFunction;
                            StringBuilder  sb       = new StringBuilder("!\r\n" + spaces + " * \r\n" + spaces + " * ");
                            foreach (CodeElement child in codeElement.Children)
                            {
                                CodeParameter parameter = child as CodeParameter;
                                if (parameter != null)
                                {
                                    sb.AppendFormat("\r\n" + spaces + " * \\param {0}", parameter.Name);
                                }
                            }

                            if (function.Type.AsString != "void")
                            {
                                sb.AppendFormat("\r\n" + spaces + " * \\return ");
                            }

                            sb.AppendFormat("\r\n" + spaces + " ");

                            ts.MoveToLineAndOffset(oldLine, oldOffset);
                            ts.Insert(sb.ToString());
                            ts.MoveToLineAndOffset(oldLine, oldOffset);
                            ts.LineDown();
                            ts.EndOfLine();
                            return(VSConstants.S_OK);
                        }
                        else if (codeElement != null && codeElement is VCCodeClass)
                        {
                            VCCodeClass   function = codeElement as VCCodeClass;
                            StringBuilder sb       = new StringBuilder("!\r\n" + spaces + " * \r\n" + spaces + " * ");

                            foreach (CodeElement child in function.TemplateParameters)
                            {
                                CodeParameter parameter = child as CodeParameter;
                                if (parameter != null)
                                {
                                    sb.AppendFormat("\r\n" + spaces + " * \\tparam {0}", parameter.Name);
                                }
                            }

                            sb.AppendFormat("\r\n" + spaces + " ");

                            ts.MoveToLineAndOffset(oldLine, oldOffset);
                            ts.Insert(sb.ToString());
                            ts.MoveToLineAndOffset(oldLine, oldOffset);
                            ts.LineDown();
                            ts.EndOfLine();
                            return(VSConstants.S_OK);
                        }
                        else
                        {
                            ts.MoveToLineAndOffset(oldLine, oldOffset);
                            ts.Insert("!\r\n" + spaces + " * \r\n" + spaces + " * \r\n" + spaces + " ");
                            ts.MoveToLineAndOffset(oldLine, oldOffset);
                            ts.LineDown();
                            ts.EndOfLine();
                            return(VSConstants.S_OK);
                        }
                    }
                }

                if (m_session != null && !m_session.IsDismissed)
                {
                    // check for a commit character

                    if (nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN ||
                        nCmdID == (uint)VSConstants.VSStd2KCmdID.TAB)
                    {
                        // check for a selection
                        // if the selection is fully selected, commit the current session
                        if (m_session.SelectedCompletionSet.SelectionStatus.IsSelected)
                        {
                            string selectedCompletion = m_session.SelectedCompletionSet.SelectionStatus.Completion.DisplayText;
                            m_session.Commit();

                            // also, don't add the character to the buffer
                            return(VSConstants.S_OK);
                        }
                        else
                        {
                            // if there is no selection, dismiss the session
                            m_session.Dismiss();
                        }
                    }
                }
                else
                {
                    if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN)
                    {
                        string currentLine = m_textView.TextSnapshot.GetLineFromPosition(
                            m_textView.Caret.Position.BufferPosition.Position).GetText();
                        if (currentLine.TrimStart().StartsWith("*"))
                        {
                            TextSelection ts     = m_dte.ActiveDocument.Selection as TextSelection;
                            string        spaces = currentLine.Replace(currentLine.TrimStart(), "");
                            ts.Insert("\r\n" + spaces + "* ");
                            return(VSConstants.S_OK);
                        }
                    }
                }

                // pass along the command so the char is added to the buffer
                int retVal = m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                if (typedChar == '\\')
                {
                    string currentLine = m_textView.TextSnapshot.GetLineFromPosition(
                        m_textView.Caret.Position.BufferPosition.Position).GetText();
                    if (currentLine.TrimStart().StartsWith("*"))
                    {
                        if (m_session == null || m_session.IsDismissed) // If there is no active session, bring up completion
                        {
                            if (this.TriggerCompletion())
                            {
                                m_session.SelectedCompletionSet.SelectBestMatch();
                                m_session.SelectedCompletionSet.Recalculate();
                                return(VSConstants.S_OK);
                            }
                        }
                    }
                }
                else if (
                    commandID == (uint)VSConstants.VSStd2KCmdID.BACKSPACE ||
                    commandID == (uint)VSConstants.VSStd2KCmdID.DELETE ||
                    char.IsLetter(typedChar))
                {
                    if (m_session != null && !m_session.IsDismissed) // the completion session is already active, so just filter
                    {
                        m_session.SelectedCompletionSet.SelectBestMatch();
                        m_session.SelectedCompletionSet.Recalculate();
                        return(VSConstants.S_OK);
                    }
                }

                return(retVal);
            }
            catch
            {
            }

            return(VSConstants.E_FAIL);
        }
        /**
         * Determines if a class is a valid CxxTest test suite by checking
         * for CxxTest::TestSuite in the superclass list.
         *
         * @param element the class handle to check
         *
         * @return true if the class is a test suite; otherwise, false.
         */
        private bool IsClassTestSuite(VCCodeClass klass)
        {
            foreach (VCCodeElement element in klass.Bases)
            {
                if (Constants.CxxTestSuiteClassRegex.IsMatch(element.Name))
                {
                    currentSuite = new TestSuite(klass);
                    testSuites.Add(currentSuite);

                    ProjectItem item = klass.ProjectItem;
                    if (item != null)
                        RemovePossibleTestFile(item);

                    return true;
                }
            }

            return false;
        }
Example #9
0
            public ICheckCPPoint CheckCursorPos()
            {
                ICheckCPPoint checkPnt  = null;
                Document      activeDoc = ChartPoints.Globals.dte.ActiveDocument;
                string        projName  = activeDoc.ProjectItem.ContainingProject.Name;
                TextSelection sel       = (TextSelection)activeDoc.Selection;
                TextPoint     caretPnt  = (TextPoint)sel.ActivePoint;
                VCCodeElement targetClassElem;

                for (;;)
                {
                    // checks if we are in text document
                    if (activeDoc == null)
                    {
                        break;
                    }
                    var textDoc = activeDoc.Object() as TextDocument;
                    if (textDoc == null)
                    {
                        break;
                    }
                    // we work only with project items
                    ProjectItem projItem = activeDoc.ProjectItem;
                    if (projItem == null)
                    {
                        break;
                    }
                    // only c++ items
                    FileCodeModel fcModel = projItem.FileCodeModel;
                    if (fcModel == null)
                    {
                        break;
                    }
                    if (fcModel.Language != CodeModelLanguageConstants.vsCMLanguageVC)
                    {
                        break;
                    }
                    vcCodeModel.Synchronize();// !!! MOVE TO METHOD ???
                    // chartpoint allowed only in class methods
                    CodeElement elem = fcModel.CodeElementFromPoint(caretPnt, vsCMElement.vsCMElementFunction);
                    if (elem == null)
                    {
                        break;
                    }
                    if (elem.Kind != vsCMElement.vsCMElementFunction)
                    {
                        break;
                    }
                    VCCodeFunction targetFunc = (VCCodeFunction)elem;
                    if (targetFunc == null)
                    {
                        break;
                    }
                    // check that we are in method definition (not declaration) in case of declaration in one file & definition in other
                    if (!targetFunc.File.Equals(activeDoc.FullName, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    // we are working only with class methods not global function
                    targetFunc.CodeModel.Synchronize();
                    targetFunc.CodeModel.SynchronizeFiles();
                    foreach (CodeElement _cl in targetFunc.CodeModel.Classes)
                    {
                        foreach (CodeElement _f in _cl.Children)
                        {
                            if (targetFunc.FullName.Equals(_f.FullName, StringComparison.OrdinalIgnoreCase))
                            {
                                targetFunc = (VCCodeFunction)_f;
                                break;
                            }
                        }
                    }
                    targetClassElem = (VCCodeElement)targetFunc.Parent;
                    if (targetClassElem == null)
                    {
                        break;
                    }
                    if (targetClassElem.Kind != vsCMElement.vsCMElementClass)
                    {
                        targetClassElem = null;
                        break;
                    }
                    VCCodeClass ownerClass = (VCCodeClass)targetClassElem;

                    TextPoint startFuncBody = targetFunc.StartPointOf[vsCMPart.vsCMPartBody, vsCMWhere.vsCMWhereDefinition];
                    TextPoint endFuncBody   = targetFunc.EndPointOf[vsCMPart.vsCMPartBody, vsCMWhere.vsCMWhereDefinition];
                    EditPoint startPnt      = startFuncBody.CreateEditPoint();
                    EditPoint endPnt        = endFuncBody.CreateEditPoint();
                    startPnt.FindPattern("{", (int)vsFindOptions.vsFindOptionsBackwards);
                    endPnt.FindPattern("}");
                    if ((caretPnt.Line > startPnt.Line && caretPnt.Line < endPnt.Line) ||
                        (caretPnt.Line == startPnt.Line && caretPnt.LineCharOffset >= startPnt.LineCharOffset) ||
                        (caretPnt.Line == endPnt.Line && caretPnt.LineCharOffset <= endPnt.LineCharOffset))
                    {
                        // Oh, oh you're in the body, now.. (c)
                        int linePos = (caretPnt.Line == startPnt.Line ? startPnt.LineCharOffset + 1 : 1 /*0*/);
                        checkPnt = new CheckCPPoint(ownerClass, projName, activeDoc.Name, System.IO.Path.GetFullPath(activeDoc.FullName).ToLower(), caretPnt.Line, linePos);

                        return(checkPnt);
                    }
                    break;
                }

                return(checkPnt);
            }