2

Doug McCune 创造了一些正是我所需要的东西(http://dougmccune.com/blog/2007/05/10/analyze-your-actionscript-code-with-this-apollo-app/)但是唉 - 它是对于 AIR beta 2。我只是想要一些我可以运行的工具,它可以提供一些不错的指标……有什么想法吗?

4

6 回答 6

3

下面的 Enterprise Flex 插件中有一个 Code Metrics Explorer:

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

于 2008-09-28T06:39:07.227 回答
2

名为LocMetrics的简单工具也可以用于 .as 文件...

于 2008-09-28T16:28:32.473 回答
1

或者

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

或者如果你使用 zsh

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

它不会告诉您这些行中有多少是注释或空白行,但如果您只对一个项目与另一个项目的不同之处感兴趣并且您已经编写了它们,那么它是一个有用的指标。

于 2008-08-30T08:35:57.307 回答
1

这是我编写的一个小脚本,用于查找 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
于 2008-09-01T22:53:46.807 回答
1

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 =====================
于 2010-04-27T17:57:12.950 回答
0

为了粗略估计,find . -type f -exec cat {} \; | wc -l如果您使用的是 Mac OS X,则始终可以在项目目录中运行。

于 2008-08-30T01:29:49.200 回答