어도비의 액션스크립트 3.0 레퍼런스 flash.utils.describeType 함수 부분 링크입니다.
http://livedocs.adobe.com/flash/9.0_kr/ActionScriptLangRefV3/flash/utils/package.html#describeType()
public function describeType(value:*):XML
매개변수 value를 설명하는 XML 객체를 만듭니다.
생성된 XML 객체에는 value의 타입, 확장한 슈퍼클래스, 구현한 인터페이스, getter/setter 메서드, 상수, 메서드, 변수.. 등의 정보가 담겨있습니다. 자바의 리플렉션에서는 private, protected 멤버에 접근하는 짓도 가능한데 액션스크립트에서는 안 되네여..
XML 객체는 public 속성과 메서드 정보만 담고 있으며, 패키지 내부와 사용자 정의 네임스페이스에 있는 것들은 표시하지 않습니다.
그럼 간단한 실험을 해보겠습니다.
Object 객체를 describeType에 인수로 넘깁니다 :
var obj:Object = {};
trace(describeType(obj));
결과는 :
<type name="Object" isDynamic="true" isFinal="false" isStatic="false">
<method name="hasOwnProperty" declaredBy="Object" returnType="Boolean" uri="http://adobe.com/AS3/2006/builtin">
<parameter index="1" type="*" optional="true"/>
</method>
<method name="isPrototypeOf" declaredBy="Object" returnType="Boolean" uri="http://adobe.com/AS3/2006/builtin">
<parameter index="1" type="*" optional="true"/>
</method>
<method name="propertyIsEnumerable" declaredBy="Object" returnType="Boolean" uri="http://adobe.com/AS3/2006/builtin">
<parameter index="1" type="*" optional="true"/>
</method>
</type>
자세한 설명은 레퍼런스에 있으니까 하지 않겠습니다.
describeType()이 쓰일만한 곳이 생각나지 않네요.
xUnit을 위한, test로 시작하는 모든 메서드를 호출하는 기능이라면 모를까...
단위 프레임워크를 위한 TestCase#run()
xUnit 프레임워크에서 TestCase 클래스는 run() 메서드를 호출하면
이름이 test로 시작하는 모든 메서드를 실행합니다.
이 글에선 describeType 공부가 목적이므로 오직 run() 메서드만을 구현합니다.
// TestCase.as
package {
import flash.utils.describeType;
public class TestCase {
public function run():void {
var me:XML = describeType(this);
var testMethods:XMLList = me..method.(@name.slice(0,4)=="test");
for each(var method:XML in testMethods){
this[method.@name]();
}
}
}
}
그리고 run() 메서드 테스트를 위해 TestCase를 확장하는 클래스를 정의합니다.
// MyTester.as
package {
public class MyTester extends TestCase {
public function testA():void {
trace("testA() 호출");
}
public function testBB():void {
trace("testBB() 호출");
}
public function testCCC():void {
trace("testCCC() 호출");
}
// 호출되지 않는다
public function notExcuted():void {
trace("notExcuted() 호출");
}
}
}
이제 실행해 보는 일만 남았습니다.
var tester:MyTester = new MyTester();
tester.run();
// 출력
testBB() 호출
testCCC() 호출
testA() 호출
'정리 또는 폐기 중 > 플래시' 카테고리의 다른 글
[번역] Proxy 클래스 (0) | 2008.07.16 |
---|---|
fl.motion.Motion.interpolateFilter() (0) | 2008.05.03 |
잔상(afterimage) 효과 (0) | 2008.03.29 |
[번역] 글꼴 끼워넣기 (2) | 2008.03.23 |
시각화 만들기 (6) | 2008.02.02 |