/*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); }
/// <summary> /// Determines whether a particular CodeElement type is one that can have child elements. /// </summary> /// <param name="kind">An object type identifier from the CodeElement.Kind enumeration.</param> /// <returns>true if the CodeElement type can have children, otherwise false.</returns> public static bool HasChildrenKind(EnvDTE.vsCMElement kind) { switch (kind) { case EnvDTE.vsCMElement.vsCMElementClass: case EnvDTE.vsCMElement.vsCMElementDelegate: case EnvDTE.vsCMElement.vsCMElementEnum: case EnvDTE.vsCMElement.vsCMElementInterface: case EnvDTE.vsCMElement.vsCMElementModule: case EnvDTE.vsCMElement.vsCMElementNamespace: case EnvDTE.vsCMElement.vsCMElementStruct: case EnvDTE.vsCMElement.vsCMElementUnion: //nemerle variant type and variant options return(true); default: return(false); } }
/// <summary> /// Determines whether a particular CodeElement type is one that will be diagrammed. /// </summary> /// <param name="kind">An object type identifier from the CodeElement.Kind enumeration.</param> /// <returns>true if Source Outliner is interested in the type, otherwise false.</returns> public static bool IsInterestingKind(EnvDTE.vsCMElement kind) { switch (kind) { case EnvDTE.vsCMElement.vsCMElementClass: case EnvDTE.vsCMElement.vsCMElementDelegate: case EnvDTE.vsCMElement.vsCMElementEnum: case EnvDTE.vsCMElement.vsCMElementEvent: case EnvDTE.vsCMElement.vsCMElementFunction: case EnvDTE.vsCMElement.vsCMElementInterface: case EnvDTE.vsCMElement.vsCMElementModule: case EnvDTE.vsCMElement.vsCMElementNamespace: case EnvDTE.vsCMElement.vsCMElementProperty: case EnvDTE.vsCMElement.vsCMElementStruct: case EnvDTE.vsCMElement.vsCMElementVariable: case EnvDTE.vsCMElement.vsCMElementParameter: case EnvDTE.vsCMElement.vsCMElementUnion: return(true); default: return(false); } }