hyeonk lab

블로그 이미지

hyeonk

hello world! hyeonk lab.

클래스, 함수 설명 주석 매크로

visual_studio 2013. 8. 8. 11:42

참조: http://majorss.tistory.com/29

 

- 함수 주석 매크로

' Usage : 함수를 모두 선택(ex : int GetLength(char strArr[]))후 매크로 실행

 

- 클래스 주석 매크로

' Usage : 클래스 이름을 선택(ex : class MyTest : public base)후 매크로를 실행

 

 

Option Strict Off
Option Explicit Off

 

'Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Imports Microsoft.VisualBasic
Imports Microsoft.VisualBasic.ControlChars

 

Public Module MyModule

    Dim ParamArr() As String
    Dim previousSelection As String
    Dim completionWords As String
    Dim completionWordsIndex As Integer

 

    Function StripTabs(ByVal MyStr As String)
        ' 앞에 있는 탭 공백을 제거합니다.
        While InStr(MyStr, Microsoft.VisualBasic.ControlChars.Tab) > 1
            MyStr = Right(MyStr, Len(MyStr) - InStr(MyStr, CStr(Microsoft.VisualBasic.ControlChars.Tab)))
        End While
        StripTabs = Trim(MyStr)
    End Function

 

    Sub AddFunctionComment()
        ' 설명: 현재 선택된 C/C++ 함수 프로토타입의 주석 블록을 만듭니다.
        Dim Header, prms As String
        Dim fcName, Descr As String
        Dim iPrm, iPrmA As Integer
        Dim selection As EnvDTE.TextSelection
        Dim RetTp As String

        ' 이 파일 전체에서 DTE.ActiveDocument.Selection이
        ' DTE.ActiveDocument.Selection.Text 대신 사용됩니다. 이 둘은
        ' 동일하므로 서로 바꿔 사용할 수 있습니다. 이 둘이 같은 이유는 Text가
        ' 사용할 기본 속성으로 간주되기 때문입니다. 다른 속성 없이
        ' ActiveDocument.Selection을 사용하면 기본적으로 Text 속성이
        ' 사용됩니다.
        If (DTE.ActiveDocument Is Nothing) Then
            Exit Sub
        End If
        If DTE.ActiveDocument.Language = EnvDTE.Constants.dsCPP Or DTE.ActiveDocument.Language = "CSharp" Then

            selection = DTE.ActiveDocument.Selection()
            Trim(selection.Text)
            Header = ""

            If selection.Text <> "" Then
                Header = StripTabs(Trim(selection.Text))
            End If

            ' 함수 반환 형식을 가져옵니다.
            If Header <> "" Then
                If DTE.ActiveDocument.Language = "CSharp" Then
                    ' public/private 등과 같은 보호 정보를 건너뜁니다.
                    Header = Right(Header, Len(Header) - InStr(Header, " "))
                End If
                Reti = InStr(Header, " ")
                Loc1 = InStr(Header, "(")
                If Reti < Loc1 Then
                    RetTp = Left(Header, Loc1 - 1)
                    Header = Right(Header, Len(Header) - Reti)
                End If
                RetTp = Left(RetTp, InStr(RetTp, " "))

                ' 함수 이름을 가져옵니다.
                Loc1 = InStr(Header, "(") - 1
                Loc2 = InStr(Header, ")")

                If Loc1 > 0 And Loc2 > 0 Then ' '(' 및 ')'가 있는지 확인합니다.
                    fcName = Left(Header, Loc1)
                    Header = Right(Header, Len(Header) - Len(fcName))

                    ' 반환 형식에 저장소 형식이 있는지 여부
                    Trim(fcName)
                    If InStr(fcName, " ") <> 0 Then
                        RetTp = RetTp + Left(fcName, InStr(fcName, " "))
                        fcName = Right(fcName, Len(fcName) - InStr(fcName, " "))
                    End If

                    ' 함수 매개 변수를 가져옵니다.
                    iPrm = 0
                    iPrmA = 0
                    prms = Header

                    ' 매개 변수 개수를 계산합니다.
                    Do While InStr(prms, ",") <> 0
                        iPrm = iPrm + 1
                        prms = Right(prms, Len(prms) - InStr(prms, ","))
                    Loop

                    ' 배열에 매개 변수 목록을 저장합니다.
                    If iPrm > 0 Then ' 매개 변수가 여러 개인 경우입니다.
                        iPrm = iPrm + 1
                        iPrmA = iPrm
                        ReDim ParamArr(iPrm)
                        Do While InStr(Header, ",") <> 0
                            ParamArr(iPrm - 1) = Left(Header, InStr(Header, ",") - 1)
                            ' 첫 번째 매개 변수에서 중괄호를 제거합니다.
                            If InStr(ParamArr(iPrm - 1), " (") <> 0 Then
                                ParamArr(iPrm - 1) = Right(ParamArr(iPrm - 1), (Len(ParamArr(iPrm - 1)) - (Len(ParamArr(iPrm - 1)) - (Len(ParamArr(iPrm - 1)) - InStr(ParamArr(iPrm - 1), " (")))))
                                Trim(ParamArr(iPrm))
                            End If
                            Header = Right(Header, Len(Header) - InStr(Header, ","))
                            iPrm = iPrm - 1
                        Loop
                        ParamArr(iPrm - 1) = Header

                        ' 마지막 매개 변수에서 닫는 중괄호를 제거합니다.
                        If InStr(ParamArr(iPrm - 1), ")") <> 0 Then
                            ParamArr(iPrm - 1) = Left(ParamArr(iPrm - 1), InStr(ParamArr(iPrm - 1), ")") - 1)
                            Trim(ParamArr(iPrm - 1))
                        End If
                    Else ' 대부분 매개 변수가 하나인 경우입니다.

                        ReDim ParamArr(1)
                        Header = Right(Header, Len(Header) - 1) ' 첫 번째 중괄호를 제거합니다.
                        Trim(Header)
                        ParamArr(0) = StripTabs(Header)
                        If InStr(ParamArr(0), ")") <> 1 Then
                            ParamArr(0) = Left(ParamArr(0), InStr(ParamArr(0), ")") - 1)
                            Trim(ParamArr(0))
                            iPrmA = 1
                        End If
                    End If

                    ' 선택한 텍스트의 한 줄 위에 커서를 둡니다.
                    DTE.ActiveDocument.Selection.LineUp()
                    DTE.ActiveDocument.Selection.LineDown()
                    DTE.ActiveDocument.Selection.StartOfLine()
                    selection = DTE.ActiveDocument.Selection()
                    'selection.text = Lf

                    Descr = CStr(Lf) + "//////////////////////////////////////////////////////////////////////////" + CStr(Lf)
                    Descr = Descr + "/// @Function Name : " + fcName + CStr(Lf)
                    Descr = Descr + "/// @Description   : " + CStr(Lf)
                    Descr = Descr + "/// @Return Type   : " + RetTp + Chr(9) + "-> (설명)" + CStr(Lf)

                    ' 매개 변수 목록을 인쇄합니다.
                    Last = iPrmA
                    Do While iPrmA <> 0
                        ' 모든 argumentextSelection에서 줄 바꿈을 제거합니다.
                        If InStr(ParamArr(iPrmA - 1), CStr(Lf)) <> 0 Then
                            ParamArr(iPrmA - 1) = Right(ParamArr(iPrmA - 1), (Len(ParamArr(iPrmA - 1)) - (Len(ParamArr(iPrmA - 1)) - (Len(ParamArr(iPrmA - 1)) - InStr(ParamArr(iPrmA - 1), CStr(Lf))))))
                            Trim(ParamArr(iPrmA - 1))
                        End If
                        ParamArr(iPrmA - 1) = StripTabs(ParamArr(iPrmA - 1))
                        ' 매개 변수가 둘 이상인 경우 첫 번째 매개 변수의 앞에
                        ' '('가 붙어 있게 됩니다. 여기에서 이를 제거합니다.
                        If iPrmA = Last And Last <> 1 Then
                            ParamArr(iPrmA - 1) = Right(ParamArr(iPrmA - 1), Len(ParamArr(iPrmA - 1)) - 1)
                        End If
                        Descr = Descr + "/// @Parameter     : " + ParamArr(iPrmA - 1) + Chr(9) + "-> (설명)" + CStr(Lf)
                        iPrmA = iPrmA - 1
                    Loop
                    Descr = Descr + "/// @Author        : Seung Hyeon Kim" + CStr(Lf)
                    selection = DTE.ActiveDocument.Selection()
                    selection.Text = Descr
                Else
                    MsgBox("It is possible that the function you are trying to work with has a syntax error.")
                End If
            End If
        Else
            MsgBox("You need to have an active C/C++ document open" + CStr(Lf) + "with the function prototype selected.")
        End If
    End Sub

 

    Sub AddSimpleFunctionComment()
        ' 설명: 현재 선택된 C/C++ 함수 프로토타입의 기능설명 주석 블록을 만듭니다.
        Dim selection As EnvDTE.TextSelection

        ' 선택한 텍스트의 한 줄 위에 커서를 둡니다.
        DTE.ActiveDocument.Selection.LineUp()
        DTE.ActiveDocument.Selection.LineDown()
        DTE.ActiveDocument.Selection.StartOfLine()
        selection = DTE.ActiveDocument.Selection()

        Descr = CStr(Lf) + "//////////////////////////////////////////////////////////////////////////" + CStr(Lf)
        Descr = Descr + "/// @기능설명  : " + CStr(Lf)
        Descr = Descr + "//////////////////////////////////////////////////////////////////////////" + CStr(Lf)

        selection = DTE.ActiveDocument.Selection()
        selection.Text = Descr
    End Sub

 

    Sub AddClassComment()
        ' 설명: 현재 선택된 C/C++ 함수 프로토타입의 주석 블록을 만듭니다.
        Dim CName As String
        Dim selection As EnvDTE.TextSelection

        ' 이 파일 전체에서 DTE.ActiveDocument.Selection이
        ' DTE.ActiveDocument.Selection.Text 대신 사용됩니다. 이 둘은
        ' 동일하므로 서로 바꿔 사용할 수 있습니다. 이 둘이 같은 이유는 Text가
        ' 사용할 기본 속성으로 간주되기 때문입니다. 다른 속성 없이
        ' ActiveDocument.Selection을 사용하면 기본적으로 Text 속성이
        ' 사용됩니다.
        If (DTE.ActiveDocument Is Nothing) Then
            Exit Sub
        End If
        If DTE.ActiveDocument.Language = EnvDTE.Constants.dsCPP Or DTE.ActiveDocument.Language = "CSharp" Then

            selection = DTE.ActiveDocument.Selection()
            Trim(selection.Text)

            CName = StripTabs(Trim(selection.Text))

            ' 선택한 텍스트의 한 줄 위에 커서를 둡니다.
            DTE.ActiveDocument.Selection.LineUp()
            DTE.ActiveDocument.Selection.LineDown()
            DTE.ActiveDocument.Selection.StartOfLine()

            Descr = CStr(Lf) + "//////////////////////////////////////////////////////////////////////////" + CStr(Lf)
            'Descr = Descr + "/**" + CStr(Lf)
            Descr = Descr + "/// @Class Name    : " + CName + CStr(Lf)
            Descr = Descr + "/// @Description   : " + CStr(Lf)
            Descr = Descr + "/// @Author        : Seung Hyeon Kim" + CStr(Lf)
            Descr = Descr + "/// @Warning       : " + CStr(Lf)
            Descr = Descr + "/// @Date          : " + System.DateTime.Now.ToShortDateString() + CStr(Lf)
            'Descr = Descr + "*/" + CStr(Lf)

            selection = DTE.ActiveDocument.Selection()
            selection.Text = Descr
        Else
            MsgBox("It is possible that the class you are trying to work with has a syntax error.")
        End If
    End Sub


End Module

 

저작자표시 (새창열림)

'visual_studio' 카테고리의 다른 글

Visual Studio 단축키 활용하기  (0) 2013.01.21
Posted by hyeonk
블로그 이미지

hello world! hyeonk lab.

by hyeonk

공지사항

    최근...

  • 포스트
  • 댓글
  • 트랙백
  • 더 보기

태그

글 보관함

«   2025/07   »
일 월 화 수 목 금 토
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

링크

카테고리

전체 (44)
ios (1)
mfc & winAPI (17)
c & c++ (4)
java (1)
eclipse (1)
visual_studio (2)
javascript (3)
asp (1)
oracle (3)
개발이야기 (5)
윈도우 일반 (2)
etc (2)
reference (2)
personal_reference (0)

카운터

Total
Today
Yesterday
방명록 : 관리자 : 글쓰기
hyeonk's Blog is powered by daumkakao
Skin info material T Mark3 by 뭐하라
favicon

hyeonk lab

hello world! hyeonk lab.

  • 태그
  • 링크 추가
  • 방명록

관리자 메뉴

  • 관리자 모드
  • 글쓰기
  • 전체 (44)
    • ios (1)
    • mfc & winAPI (17)
    • c & c++ (4)
    • java (1)
    • eclipse (1)
    • visual_studio (2)
    • javascript (3)
    • asp (1)
    • oracle (3)
    • 개발이야기 (5)
    • 윈도우 일반 (2)
    • etc (2)
    • reference (2)
    • personal_reference (0)

카테고리

PC화면 보기 티스토리 Daum

티스토리툴바