Example #1
0
        bool ICodeModelEditorFilter.Filter(EnvDTE.CodeElement codeElement)
        {
            AttributeTargets target = GetTarget(codeElement);

            if ((target & this.attributeUsage) != 0)
            {
                CodeElements attributes = new CodeElementEx(codeElement).Attributes;
                foreach (CodeElement attribute in attributes)
                {
                    try
                    {
                        if (attribute.FullName.Equals(
                                this.attributeType.FullName,
                                StringComparison.InvariantCultureIgnoreCase))
                        {
                            return(false);
                        }
                    }
                    catch
                    {
                    }
                }
                return(true);
            }
            return(false);
        }
Example #2
0
 /// <summary>
 /// Documents a specific element.
 /// </summary>
 /// <param name="document">The TextDocument that contains the code.</param>
 /// <param name="element">The element to document.</param>
 private void DocumentElement(EnvDTE.TextDocument document, EnvDTE.CodeElement element)
 {
     EnvDTE.EditPoint startPoint;
     document.Selection.GotoLine(element.StartPoint.Line, true);
     startPoint = document.CreateEditPoint(document.Selection.ActivePoint);
     document.Selection.MoveToPoint(startPoint, true);
     window.SetFocus();
     window.DTE.ExecuteCommand("Tools.Submain.GhostDoc.DocumentThis", string.Empty);
 }
Example #3
0
        /// <summary>
        /// Create a new instance of a CodeClass object.
        /// </summary>
        public CodeClass(vsDTE.CodeElement dteClass, CodeLine classDeclarationLine) : base()
        {
            // set the DTEClass
            this.DTEClass = dteClass;

            // set the Class Declaration Line
            this.ClassDeclarationLine = classDeclarationLine;

            // perform initializations for this object
            Init();
        }
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public string GetCurrentMethodName()
 {
     try{
         EnvDTE.TextSelection   SelectedText    = this.Application.ActiveDocument.Selection as EnvDTE.TextSelection;
         EnvDTE.TextPoint       tp              = SelectedText.TopPoint as EnvDTE.TextPoint;
         EnvDTE.CodeElement     c               = this.Application.ActiveDocument.ProjectItem.FileCodeModel.CodeElementFromPoint(tp, EnvDTE.vsCMElement.vsCMElementFunction);
         EnvDTE80.CodeFunction2 CurrentFunction = c as EnvDTE80.CodeFunction2;
         return(c.Name);
     }
     catch {
         return("");
     }
 }
Example #5
0
 public void ElementDeleted(object Parent, EnvDTE.CodeElement Element)
 {
     _outputWindowPane.OutputString("CodeModelEvents, ElementDeleted\n");
     _outputWindowPane.OutputString("\tElement: " + Element.FullName + "\n");
     if (Parent is CodeElement)
     {
         _outputWindowPane.OutputString("\tParent: " + ((CodeElement)Parent).FullName + "\n");
     }
     else if (Parent is ProjectItem)
     {
         _outputWindowPane.OutputString("\tParent: " + ((ProjectItem)Parent).get_FileNames(0) + "\n");
     }
 }
Example #6
0
 bool ICodeModelEditorFilter.Filter(EnvDTE.CodeElement codeElement)
 {
     if (codeElement is CodeClass)
     {
         return(!CheckImplements((CodeClass)codeElement));
     }
     else if (codeElement is CodeNamespace)
     {
         return(!HasClassThatImplements((CodeNamespace)codeElement));
     }
     // Filter everything else
     return(true);
 }
Example #7
0
        bool ICodeModelEditorFilter.Filter(EnvDTE.CodeElement codeElement)
        {
            CodeElementEx codeElementEx = new CodeElementEx(codeElement);

            if (codeElementEx.Bases != null)
            {
                return(!CheckInheritsFrom(codeElementEx));
            }
            else if (codeElement is CodeNamespace)
            {
                return(!HasClassInheritFrom((CodeNamespace)codeElement));
            }
            // Filter everything else
            return(true);
        }
Example #8
0
 // Look for a TypeName in "stranger" projects
 public EnvDTE.CodeElement LookupForStranger(string typeName, bool caseInvariant)
 {
     // If not found....
     EnvDTE.CodeElement foundElement = null;
     // Enumerate all referenced external Projects
     //foreach (EnvDTE.Project project in this.StrangerProjects)
     //{
     //    //
     //    foundElement = SearchInItems(project.ProjectItems, typeName, caseInvariant);
     //    //
     //    if (foundElement != null)
     //        break;
     //}
     //
     return(foundElement);
 }
Example #9
0
        /*public void GetCodeElementAtCursor()
         * {
         *      EnvDTE.CodeElement objCodeElement = default(EnvDTE.CodeElement);
         *      EnvDTE.TextPoint objCursorTextPoint = default(EnvDTE.TextPoint);
         *
         *      try
         *      {
         *              objCursorTextPoint = GetCursorTextPoint();
         *
         *              if ((objCursorTextPoint != null))
         *              {
         *                      // Get the class at the cursor
         *                      objCodeElement = GetCodeElementAtTextPoint(vsCMElement.vsCMElementClass, DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElements, objCursorTextPoint);
         *              }
         *
         *              if (objCodeElement == null)
         *              {
         *                      MessageBox.Show("No class found at the cursor!");
         *              }
         *              else
         *              {
         *                      MessageBox.Show("Class at the cursor: " + objCodeElement.FullName);
         *              }
         *      }
         *      catch (System.Exception ex)
         *      {
         *              MessageBox.Show(ex.ToString);
         *      }
         * }*/

        /*private EnvDTE.TextPoint GetCursorTextPoint()
         * {
         *      EnvDTE.TextDocument objTextDocument = default(EnvDTE.TextDocument);
         *      EnvDTE.TextPoint objCursorTextPoint = default(EnvDTE.TextPoint);
         *
         *      try
         *      {
         *              objTextDocument = (EnvDTE.TextDocument)DTE.ActiveDocument.Object;
         *              objCursorTextPoint = objTextDocument.Selection.ActivePoint();
         *      }
         *      catch (System.Exception ex)
         *      {
         *      }
         *
         *      return objCursorTextPoint;
         * }*/

        public static EnvDTE.CodeElement GetCodeElementAtTextPoint(EnvDTE.vsCMElement eRequestedCodeElementKind, EnvDTE.CodeElements colCodeElements, EnvDTE.TextPoint objTextPoint)
        {
            EnvDTE.CodeElement  objResultCodeElement  = default(EnvDTE.CodeElement);
            EnvDTE.CodeElements colCodeElementMembers = default(EnvDTE.CodeElements);
            EnvDTE.CodeElement  objMemberCodeElement  = default(EnvDTE.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);
        }
Example #10
0
 private CodeElement SearchInItems(ProjectItems projectItems, string typeName, bool caseInvariant)
 {
     // If not found....
     EnvDTE.CodeElement foundElement = null;
     // VSConstants.GUID_ItemType_PhysicalFolder.ToString().ToUpper();
     //String folderKind = "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}";
     //String itemKind = "";
     //// Retrieve items -> Projects
     //foreach (EnvDTE.ProjectItem item in projectItems)
     //{
     //    itemKind = item.Kind.ToUpper();
     //    if (  itemKind == folderKind ) // "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}"
     //    {
     //        // A Folder ! Recursive search...
     //        foundElement = SearchInItems( item.ProjectItems, typeName, caseInvariant);
     //        //
     //        if (foundElement != null)
     //            break;
     //    }
     //    // Does this project provide a FileCodeModel ?
     //    // XSharp is (currently) not providing such object
     //    EnvDTE.FileCodeModel fileCodeModel = null;
     //    try
     //    {
     //        fileCodeModel = item.FileCodeModel;
     //    }
     //    catch (Exception )
     //    {
     //        fileCodeModel = null;
     //    }
     //    if (fileCodeModel == null)
     //        continue;
     //    // First, search for Namespaces, this is where we will find Classes
     //    foreach (EnvDTE.CodeElement codeElementNS in fileCodeModel.CodeElements)
     //    {
     //        if (codeElementNS.Kind == EnvDTE.vsCMElement.vsCMElementNamespace)
     //        {
     //            // May be here, we could speed up search if the TypeName doesn't start with the Namespace name ??
     //            //
     //            // Classes are childs, so are Enums and Structs
     //            foreach (EnvDTE.CodeElement elt in codeElementNS.Children)
     //            {
     //                // TODO: And what about Enums, Structures, ... ???
     //                // is it a Class/Enum/Struct ?
     //                if ((elt.Kind == EnvDTE.vsCMElement.vsCMElementClass) ||
     //                    (elt.Kind == EnvDTE.vsCMElement.vsCMElementEnum) ||
     //                    (elt.Kind == EnvDTE.vsCMElement.vsCMElementStruct))
     //                {
     //                    // So the element name is
     //                    string elementName = elt.FullName;
     //                    // !!!! WARNING !!! We may have nested types
     //                    elementName = elementName.Replace("+", ".");
     //                    // Got it ?
     //                    if (caseInvariant)
     //                    {
     //                        if (elementName.ToLowerInvariant() == typeName.ToLowerInvariant())
     //                        {
     //                            // Bingo !
     //                            foundElement = elt;
     //                            break;
     //                        }
     //                    }
     //                    else
     //                    {
     //                        if (elementName.ToLower() == typeName.ToLower())
     //                        {
     //                            // Bingo !
     //                            foundElement = elt;
     //                            break;
     //                        }
     //                    }
     //                }
     //            }
     //            //
     //            if (foundElement != null)
     //                break;
     //        }
     //    }
     //    //
     //    if (foundElement != null)
     //        break;
     //}
     ////
     return(foundElement);
 }
Example #11
0
 public static void doInheritsFrom(EnvDTE.CodeElement codeElem, string indent)
 {
     Debug.WriteLine(indent + "inherits from:" + codeElem.Name);
 }
Example #12
0
 public static void doCodeElement(EnvDTE.CodeElement codeElem, string indent)
 {
     Debug.WriteLine(indent + "code element:" + codeElem.Name + " kind: " + codeElem.Kind);
 }
Example #13
0
 public void ElementChanged(EnvDTE.CodeElement Element, EnvDTE80.vsCMChangeKind Change)
 {
     _outputWindowPane.OutputString("CodeModelEvents, ElementChanged\n");
     _outputWindowPane.OutputString("\tElement: " + Element.FullName + "\n");
     _outputWindowPane.OutputString("\tChange: " + Change.ToString() + "\n");
 }
Example #14
0
 //CodeModelEvents
 public void ElementAdded(EnvDTE.CodeElement Element)
 {
     _outputWindowPane.OutputString("CodeModelEvents, ElementAdded\n");
     _outputWindowPane.OutputString("\tElement: " + Element.FullName + "\n");
 }