Пример #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, @"\{"));
        }
Пример #2
0
        private static bool ProcessClassGuidAttribute(CodeEditPoint editorEditPoint, string guid)
        {
            CodeFunction currentFunction =
                editorEditPoint.GetCurrentCodeElement <CodeFunction>(vsCMElement.vsCMElementFunction);

            // if inside the function, then applying of an attribute to class/struct is prohibited:
            if (currentFunction != null)
            {
                return(false);
            }

            // if the current place is inside string characters: ""
            // then don't jump to the class definition:
            EditPoint startString = editorEditPoint.EditPoint.CreateEditPoint();

            startString.CharLeft(1);
            string s = startString.GetText(2);

            if (s == "\"\"" || editorEditPoint.IsSelected)
            {
                return(false);
            }

            CodeClass          currentClass  = editorEditPoint.GetCurrentCodeElement <CodeClass>(vsCMElement.vsCMElementClass);
            CodeStruct         currentStruct = editorEditPoint.GetCurrentCodeElement <CodeStruct>(vsCMElement.vsCMElementStruct);
            EditPoint          start         = null;
            CodeModelLanguages language      = CodeModelLanguages.Unknown;

            // find the start location of current class:
            if (currentClass != null)
            {
                start    = currentClass.GetStartPoint(vsCMPart.vsCMPartHeader).CreateEditPoint();
                language = CodeHelper.GetCodeLanguage(currentClass.Language);
            }

            // find the start location of current structure:
            if (currentStruct != null)
            {
                start    = currentStruct.GetStartPoint(vsCMPart.vsCMPartHeader).CreateEditPoint();
                language = CodeHelper.GetCodeLanguage(currentStruct.Language);
            }

            // append attributes at the 'start' location:
            if (start != null)
            {
                string sourceCodeSnippet = CodeHelper.GenerateFromAttribute(language,
                                                                            VariableHelper.GetGuidAttribute(guid));

                if (language == CodeModelLanguages.VisualBasic)
                {
                    sourceCodeSnippet += Environment.NewLine;
                }

                start.ReplaceText(start, sourceCodeSnippet, (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
                return(true);
            }

            // nothing special found... just insert the Guid string...
            return(false);
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// Get EndPoint of specified element of parent object.
        /// </summary>
        public TextPoint GetStartPoint(vsCMPart part)
        {
            if (parentClass != null)
            {
                return(parentClass.GetStartPoint(part));
            }
            else
            if (parentStruct != null)
            {
                return(parentStruct.GetStartPoint(part));
            }

            return(null);
        }
Пример #5
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, @"\{");
        }