코드 줄, 함수 수, 파일, 패키지 등을 계산하는 Actionscript/flex에 적합한 프로그램이 있습니까?

StackOverflow https://stackoverflow.com/questions/35541

문제

Doug McCune은 제가 꼭 필요했던 것을 만들어냈습니다(http://dougmccune.com/blog/2007/05/10/analyze-your-actionscript-code-with-this-apollo-app/) 하지만 아쉽게도 AIR 베타 2용이었습니다.저는 단지 적절한 측정항목을 제공할 수 있는 도구를 실행하고 싶습니다. 어떤 아이디어가 있습니까?

도움이 되었습니까?

해결책

아래 Enterprise Flex 플러그인에는 Code Metrics Explorer가 있습니다.

http://www.deitte.com/archives/2008/09/flex_builder_pl.htm

다른 팁

라는 간단한 도구 LocMetrics .as 파일에서도 작동할 수 있습니다...

또는

find . -name '*.as' -or -name '*.mxml' | xargs wc -l

아니면 zsh를 사용한다면

wc -l **/*.{as,mxml}

해당 줄 중 주석이나 빈 줄이 얼마나 되는지는 알려주지 않지만, 한 프로젝트가 다른 프로젝트와 어떻게 다른지에만 관심이 있고 두 프로젝트를 모두 작성한 경우 이는 유용한 측정항목입니다.

다음은 ActionScript 3 코드에서 다양한 소스 코드 요소의 총 발생 횟수를 찾기 위해 작성한 작은 스크립트입니다(이것은 단순히 Python에 익숙하기 때문에 Python으로 작성된 반면 Perl은 아마도 정규식이 많은 스크립트에 더 적합할 것입니다). 이와 같이):

#!/usr/bin/python

import sys, os, re

# might want to improve on the regexes used here
codeElements = {
'package':{
    'regex':re.compile('^\s*[(private|public|static)\s]*package\s+([A-Za-z0-9_.]+)\s*', re.MULTILINE),
    'numFound':0
    },
'class':{
    'regex':re.compile('^\s*[(private|public|static|dynamic|final|internal|(\[Bindable\]))\s]*class\s', re.MULTILINE),
    'numFound':0
    },
'interface':{
    'regex':re.compile('^\s*[(private|public|static|dynamic|final|internal)\s]*interface\s', re.MULTILINE),
    'numFound':0
    },
'function':{
    'regex':re.compile('^\s*[(private|public|static|protected|internal|final|override)\s]*function\s', re.MULTILINE),
    'numFound':0
    },
'member variable':{
    'regex':re.compile('^\s*[(private|public|static|protected|internal|(\[Bindable\]))\s]*var\s+([A-Za-z0-9_]+)(\s*\\:\s*([A-Za-z0-9_]+))*\s*', re.MULTILINE),
    'numFound':0
    },
'todo note':{
    'regex':re.compile('[*\s/][Tt][Oo]\s?[Dd][Oo][\s\-:_/]', re.MULTILINE),
    'numFound':0
    }
}
totalLinesOfCode = 0

filePaths = []
for i in range(1,len(sys.argv)):
    if os.path.exists(sys.argv[i]):
        filePaths.append(sys.argv[i])

for filePath in filePaths:
    thisFile = open(filePath,'r')
    thisFileContents = thisFile.read()
    thisFile.close()
    totalLinesOfCode = totalLinesOfCode + len(thisFileContents.splitlines())
    for codeElementName in codeElements:
        matchSubStrList = codeElements[codeElementName]['regex'].findall(thisFileContents)
        codeElements[codeElementName]['numFound'] = codeElements[codeElementName]['numFound'] + len(matchSubStrList)

for codeElementName in codeElements:
    print str(codeElements[codeElementName]['numFound']) + ' instances of element "'+codeElementName+'" found'
print '---'
print str(totalLinesOfCode) + ' total lines of code'
print ''

프로젝트의 모든 소스 코드 파일에 대한 경로를 이 스크립트에 대한 인수로 전달하여 모든 소스 코드 파일을 처리하고 총계를 보고하도록 합니다.

다음과 같은 명령:

find /path/to/project/root/ -name "*.as" -or -name "*.mxml" | xargs /path/to/script

다음과 같이 출력됩니다.

1589 instances of element "function" found
147 instances of element "package" found
58 instances of element "todo note" found
13 instances of element "interface" found
2033 instances of element "member variable" found
156 instances of element "class" found
---
40822 total lines of code

클록 - http://cloc.sourceforge.net/.Windows 명령줄 기반이지만 AS3.0에서 작동하고 원하는 모든 기능을 갖추고 있으며 잘 문서화되어 있습니다.내가 사용하고 있는 BAT 파일 설정은 다음과 같습니다.

REM =====================

echo off

cls

REM set variables

set ASDir=C:\root\directory\of\your\AS3\code\

REM run the program

REM See docs for different output formats.

cloc-1.09.exe --by-file-by-lang --force-lang="ActionScript",as --exclude_dir=.svn --ignored=ignoredFiles.txt --report-file=totalLOC.txt %ASDir% 

REM show the output

totalLOC.txt

REM end

pause

REM =====================

대략적인 추정치를 얻으려면 언제든지 다음을 실행할 수 있습니다. find . -type f -exec cat {} \; | wc -l Mac OS X를 사용하는 경우 프로젝트 디렉토리에 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top