views:

1510

answers:

6

Doug McCune had created something that was exactly what I needed (http://dougmccune.com/blog/2007/05/10/analyze-your-actionscript-code-with-this-apollo-app/) but alas - it was for AIR beta 2. I just would like some tool that I can run that would provide some decent metrics...any idea's?

A: 

To get a rough estimate, you could always run find . -type f -exec cat {} \; | wc -l in the project directory if you're using Mac OS X.

hoyhoy
+1  A: 

Or

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

Or if you use zsh

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

It won't give you what fraction of those lines are comments, or blank lines, but if you're only interested in how one project differs from another and you've written them both, it's a useful metric.

Theo
+1  A: 

Here's a small script I wrote for finding the total numbers of occurrence for different source code elements in ActionScript 3 code (this is written in Python simply because I'm familiar with it, while Perl would probably be better suited for a regex-heavy script like this):

#!/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 ''

Pass paths to all of the source code files in your project as arguments for this script to get it to process all of them and report the totals.

A command like this:

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

Will output something like this:

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
hasseg
+3  A: 

There is a Code Metrics Explorer in the Enterprise Flex Plug-in below:

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

Brandon
+1  A: 

Simple tool called LocMetrics can work for .as files too...

Borek
A: 

CLOC - http://cloc.sourceforge.net/. Even though it is Windows commandline based, it works with AS3.0, has all the features you would want, and is well-documented. Here is the BAT file setup I am using:

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 =====================
Delfeld