هل هناك أي برامج جيدة لـ actionscript/flex والتي ستحسب أسطر التعليمات البرمجية وعدد الوظائف والملفات والحزم وما إلى ذلك
-
09-06-2019 - |
سؤال
لقد ابتكر دوج ماكيون شيئًا كان بالضبط ما أحتاجه (http://dougmccune.com/blog/2007/05/10/analyze-your-actionscript-code-with-this-apollo-app/) ولكن للأسف - كان ذلك لـ AIR beta 2.أريد فقط بعض الأدوات التي يمكنني تشغيلها والتي من شأنها أن توفر بعض المقاييس اللائقة...هل لديك أي فكرة؟
المحلول
يوجد مستكشف قياسات الكود في البرنامج الإضافي Enterprise Flex أدناه:
نصائح أخرى
أداة بسيطة تسمى لوكميتريكس يمكن أن تعمل مع ملفات .as أيضًا...
أو
find . -name '*.as' -or -name '*.mxml' | xargs wc -l
أو إذا كنت تستخدم zsh
wc -l **/*.{as,mxml}
لن يوضح لك الجزء الذي تمثله التعليقات أو الأسطر الفارغة من تلك السطور، ولكن إذا كنت مهتمًا فقط بكيفية اختلاف مشروع عن الآخر وقمت بكتابتهما معًا، فهذا مقياس مفيد.
إليك نصًا صغيرًا كتبته للعثور على إجمالي عدد مرات الظهور لعناصر التعليمات البرمجية المصدر المختلفة في كود ActionScript 3 (تمت كتابة هذا بلغة Python ببساطة لأنني على دراية بها، بينما من المحتمل أن يكون Perl أكثر ملاءمة لبرنامج نصي ثقيل regex مثله):
#!/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.