-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathType.as
152 lines (152 loc) · 3.74 KB
/
Type.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package hxasm {
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
import flash.utils.describeType;
import flash.utils.getQualifiedSuperclassName;
public class Type {
static public function toEnum(t : *) : Class {
try {
if(!t.__isenum) return null;
return t;
}
catch( e : * ){
null;
}
return null;
}
static public function toClass(t : *) : Class {
try {
if(!t.hasOwnProperty("prototype")) return null;
return t;
}
catch( e : * ){
null;
}
return null;
}
static public function getClass(o : *) : Class {
var cname : String = getQualifiedClassName(o);
if(cname == "null" || cname == "Object" || cname == "int" || cname == "Number" || cname == "Boolean") return null;
if(o.hasOwnProperty("prototype")) return null;
var c : * = getDefinitionByName(cname) as Class;
if(c.__isenum) return null;
return c;
}
static public function getEnum(o : *) : Class {
var cname : String = getQualifiedClassName(o);
if(cname == "null" || cname.substr(0,8) == "builtin.") return null;
if(o.hasOwnProperty("prototype")) return null;
var c : * = getDefinitionByName(cname) as Class;
if(!c.__isenum) return null;
return c;
}
static public function getSuperClass(c : Class) : Class {
var cname : String = getQualifiedSuperclassName(c);
if(cname == "Object") return null;
return getDefinitionByName(cname) as Class;
}
static public function getClassName(c : Class) : String {
if(c == null) return null;
var str : String = getQualifiedClassName(c);
return str.split("::").join(".");
}
static public function getEnumName(e : Class) : String {
var n : String = getQualifiedClassName(e);
return n;
}
static public function resolveClass(name : String) : Class {
var cl : Class;
{
try {
cl = getDefinitionByName(name) as Class;
if(cl.__isenum) return null;
return cl;
}
catch( e : * ){
return null;
}
if(cl == null || cl.__name__ == null) return null;
else null;
}
return cl;
}
static public function resolveEnum(name : String) : Class {
var e : *;
{
try {
e = getDefinitionByName(name);
if(!e.__isenum) return null;
return e;
}
catch( e1 : * ){
return null;
}
if(e == null || e.__ename__ == null) return null;
else null;
}
return e;
}
static public function createInstance(cl : Class,args : Array) : * {
return function() : * {
var $r : *;
switch(args.length) {
case 0:{
$r = new cl();
}break;
case 1:{
$r = new cl(args[0]);
}break;
case 2:{
$r = new cl(args[0],args[1]);
}break;
case 3:{
$r = new cl(args[0],args[1],args[2]);
}break;
case 4:{
$r = new cl(args[0],args[1],args[2],args[3]);
}break;
case 5:{
$r = new cl(args[0],args[1],args[2],args[3],args[4]);
}break;
default:{
$r = function() : * {
var $r2 : *;
throw "Too many arguments";
return $r2;
}();
}break;
}
return $r;
}();
}
static public function getEnumConstructs(e : Class) : Array {
return e.__constructs__;
}
static public function enumEq(a : *,b : *) : Boolean {
if(a == b) return true;
try {
if(a.tag != b.tag) return false;
{
var _g1 : int = 0, _g : int = a.params.length;
while(_g1 < _g) {
var i : int = _g1++;
if(!enumEq(a.params[i],b.params[i])) return false;
}
}
}
catch( e : * ){
return false;
}
return true;
}
static public function enumConstructor(e : *) : String {
return e.tag;
}
static public function enumParameters(e : *) : Array {
return (e.params == null?[]:e.params);
}
static public function enumIndex(e : *) : int {
return e.index;
}
}
}