Example #1
0
        /// <summary>
        /// Gets the declaration of the specified code struct as a string.
        /// </summary>
        /// <param name="codeStruct">The code struct.</param>
        /// <returns>The string declaration.</returns>
        internal static string GetStructDeclaration(CodeStruct codeStruct)
        {
            // Get the start point after the attributes.
            var startPoint = codeStruct.GetStartPoint(vsCMPart.vsCMPartHeader);

            return TextDocumentHelper.GetTextToFirstMatch(startPoint, @"\{");
        }
 private static string getStructName(CodeStruct structure)
 {
     string parents = GetParents(structure);
     var nspace = GetNameSpaceName(structure.Namespace);
     return nspace + "." + parents;
 }
 public static string GetParents(CodeStruct c)
 {
     var parent = c.Parent as CodeClass;
     return GetParents((CodeElement)c, parent);
 }
Example #4
0
 void CreateStruct()
 {
     codeStruct = new CodeStruct(helper.ProjectContent, fakeStruct);
 }
Example #5
0
 protected virtual void VisitStruct(CodeStruct codeStruct)
 {
 }
Example #6
0
        /// <summary>
        /// Returns a CodeElement's documentation comment if it has
        /// one, otherwise returns relevant information from the prototype.
        /// </summary>
        /// <param name="element">A CodeElement object.</param>
        /// <returns>A string representing the element's definition.</returns>
        public static string GetPrototypeFromCMElement(CodeElement element)
        {
            System.Xml.XmlDocument docComment = new System.Xml.XmlDocument();

            try
            {
                if (element == null)
                {
                    throw new ArgumentNullException("element");
                }

                switch (element.Kind)
                {
                case vsCMElement.vsCMElementFunction:
                    CodeFunction codeFunction = ((CodeFunction)element);
                    if (!string.IsNullOrEmpty(codeFunction.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeFunction.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(String.Format("{0}\n{1}", node.InnerText.Trim(),
                                                 codeFunction.get_Prototype(
                                                     (int)vsCMPrototype.vsCMPrototypeType | (int)vsCMPrototype.vsCMPrototypeParamNames | (int)vsCMPrototype.vsCMPrototypeParamTypes)));
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(codeFunction.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                          (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                          (int)vsCMPrototype.vsCMPrototypeParamTypes));
                    }

                case vsCMElement.vsCMElementProperty:
                    CodeProperty codeProperty = ((CodeProperty)element);
                    if (!string.IsNullOrEmpty(codeProperty.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeProperty.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(String.Format("{0}\n{1}", node.InnerText.Trim(),
                                                 codeProperty.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                                            (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                                            (int)vsCMPrototype.vsCMPrototypeParamTypes)));
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(codeProperty.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                          (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                          (int)vsCMPrototype.vsCMPrototypeParamTypes));
                    }

                case vsCMElement.vsCMElementVariable:
                    CodeVariable codeVariable = ((CodeVariable)element);
                    return(codeVariable.get_Prototype((int)vsCMPrototype.vsCMPrototypeType));

                case vsCMElement.vsCMElementEvent:
                    CodeEvent codeEvent = ((CodeEvent)element);
                    if (!string.IsNullOrEmpty(codeEvent.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeEvent.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(String.Format("{0}\n{1}", node.InnerText.Trim(),
                                                 codeEvent.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                                         (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                                         (int)vsCMPrototype.vsCMPrototypeParamTypes)));
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(codeEvent.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                       (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                       (int)vsCMPrototype.vsCMPrototypeParamTypes));
                    }

                case vsCMElement.vsCMElementDelegate:
                    CodeDelegate codeDelegate = ((CodeDelegate)element);
                    if (!string.IsNullOrEmpty(codeDelegate.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeDelegate.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(String.Format("{0}\n{1}", node.InnerText.Trim(),
                                                 codeDelegate.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                                            (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                                            (int)vsCMPrototype.vsCMPrototypeParamTypes)));
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(codeDelegate.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                          (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                          (int)vsCMPrototype.vsCMPrototypeParamTypes));
                    }

                case vsCMElement.vsCMElementClass:
                    CodeClass codeClass = ((CodeClass)element);
                    if (!string.IsNullOrEmpty(codeClass.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeClass.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(node.InnerText.Trim());
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(string.Empty);
                    }

                //nemerle variant type and variant options
                case vsCMElement.vsCMElementUnion:
                    CodeClass codeVariant = ((CodeClass)element);
                    if (!string.IsNullOrEmpty(codeVariant.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeVariant.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(node.InnerText.Trim());
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(string.Empty);
                    }


                case vsCMElement.vsCMElementStruct:
                    CodeStruct codeStruct = ((CodeStruct)element);
                    if (!string.IsNullOrEmpty(codeStruct.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeStruct.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(node.InnerText.Trim());
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(string.Empty);
                    }

                case vsCMElement.vsCMElementInterface:
                    CodeInterface codeInterface = ((CodeInterface)element);
                    if (!string.IsNullOrEmpty(codeInterface.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeInterface.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(node.InnerText.Trim());
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(string.Empty);
                    }

                default:
                    return(string.Empty);
                }
            }
            catch
            {
                return(string.Empty);
            }
        }
Example #7
0
        public static string GetParents(CodeStruct c)
        {
            var parent = c.Parent as CodeClass;

            return(GetParents((CodeElement)c, parent));
        }
Example #8
0
        /// <summary>
        /// Gets the parent class or structure for given cursor location in file.
        /// </summary>
        public static bool GetParent(Data.CodeEditPoint editorEditPoint, out CodeClass codeClass, out CodeStruct codeStruct)
        {
            codeClass  = editorEditPoint.GetCurrentCodeElement <CodeClass>(vsCMElement.vsCMElementClass);
            codeStruct = editorEditPoint.GetCurrentCodeElement <CodeStruct>(vsCMElement.vsCMElementStruct);

            if (codeClass != null && codeStruct != null)
            {
                if (codeClass.GetStartPoint(vsCMPart.vsCMPartBody).Line < codeStruct.GetStartPoint(vsCMPart.vsCMPartBody).Line)
                {
                    codeClass = null;
                }
                else
                if (codeStruct.GetStartPoint(vsCMPart.vsCMPartBody).Line < codeClass.GetStartPoint(vsCMPart.vsCMPartBody).Line)
                {
                    codeStruct = null;
                }
            }

            return(codeClass != null || codeStruct != null);
        }