有没有什么好的 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 beta 2 的。我只是想要一些可以运行的工具,它可以提供一些不错的指标......有什么想法吗?

有帮助吗?

解决方案

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

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

其他提示

简单的工具称为 本地度量 也可以用于 .as 文件...

或者

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

或者如果你使用 zsh

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

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

这是我编写的一个小脚本,用于查找 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

克洛克- 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