Doug McCuneは、まさに私が必要としていたものを作成しました(http://dougmccune.com/blog/2007/05/10/analyze-your-actionscript-code-with-this-apollo-app/)が、残念ながら-それはAIRベータ2の場合。まともなメトリックを提供する実行可能なツールが欲しいだけです...何かアイデアはありますか?
6 に答える
以下の Enterprise Flex Plug-in には Code Metrics Explorer があります。
LocMetricsと呼ばれるシンプルなツールは、.as ファイルにも使用できます...
これは、ActionScript 3コードのさまざまなソースコード要素の出現総数を見つけるために書いた小さなスクリプトです(これは、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
CLOC - 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 . -name '*.as' -or -name '*.mxml' | xargs wc -l
または zsh を使用する場合
wc -l **/*.{as,mxml}
これらの行のどの部分がコメントまたは空白行であるかはわかりませんが、あるプロジェクトが別のプロジェクトとどのように異なるかだけに関心があり、両方を書いている場合、これは有用な指標です。
find . -type f -exec cat {} \; | wc -l
大まかな見積もりを取得するには、Mac OS Xを使用している場合は、常にプロジェクトディレクトリで実行できます。