FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
flashdevelop/External/Tools/AS2API/api_model.rb at development · SandersAlex/flashdevelop · GitHub
SandersAlex
flashdevelop
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
flashdevelop
/
External
/
Tools
/
AS2API
/
api_model.rb
Copy path
More file actions
More file actions
Latest commit
History
History
History
430 lines (354 loc) · 9.11 KB
Breadcrumbs
flashdevelop
/
External
/
Tools
/
AS2API
/
api_model.rb
Copy path
File metadata and controls
430 lines (354 loc) · 9.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# These classes represent the data-model upon which as2api operates. The
# class names are all prefixed with 'AS' becase many would otherwise clash
# with Ruby's inbuild classes with the same name.
# TODO: The interfaces to these classes still, in places, make direct use of
# types provided by ActionScript::Parse (i.e. methods expecting or
# returning subclasses of ASToken). These classes should be refactored
# to insulate the documentation-generating subsystem from those details
# Superclass for ASClass and ASInterface, one instance of an ASType subclass
# is created per compilation unit successfully parsed
class
ASType
# give this ASType the given name (an array of IdentifierToken values
# found by the parser)
def
initialize
(
name
)
@package_name
=
name
[
0
,
name
.
length
-
1
]
.
join
(
"."
)
@name
=
name
.
last
.
body
@source_utf8
=
false
@methods
=
[
]
@constructor
=
nil
@extends
=
nil
@comment
=
nil
@type_resolver
=
nil
@import_manager
=
nil
@input_file
=
nil
@document
=
true
end
attr_accessor
:package
,
:extends
,
:comment
,
:source_utf8
,
:type_resolver
,
:import_manager
,
:intrinsic
,
:constructor
def
input_filename
@input_file
.
suffix
end
def
input_file
=
(
file
)
@input_file
=
file
sourcepath_location
(
File
.
dirname
(
file
.
suffix
)
)
end
attr_reader
:input_file
def
add_method
(
method
)
@methods
<<
method
end
def
each_method
@methods
.
each
do
|
meth
|
yield
meth
end
end
def
methods
@methods
.
dup
end
def
methods?
!
@methods
.
empty?
end
def
constructor?
!
@constructor
.
nil?
end
def
get_method_called
(
name
)
each_method
do
|
method
|
return
method
if
method
.
name
==
name
end
nil
end
# The type's name, excluding its package-prefix
def
unqualified_name
@name
end
# ascends the hierarchy of resolved supertypes of this type, passing
# each ASType to the given block. Stops when a type does not extend
# anything, or when the class it extends wasn't resolved.
def
each_ancestor
parent
=
@extends
while
!
parent
.
nil?
&&
parent
.
resolved?
yield
parent
.
resolved_type
parent
=
parent
.
resolved_type
.
extends
end
end
def
has_ancestor?
!
@extends
.
nil?
&&
@extends
.
resolved?
end
# The whole type name, including package-prefix
def
qualified_name
if
@package_name
==
""
@name
else
"
#{
@package_name
}
.
#{
@name
}
"
end
end
# The package-prefix on this type's name
def
package_name
@package_name
end
# This exists mostly as a hack to handle types that are declaired without
# a package-prefix 'class SomeClass {', but shich are located in the
# directory structure such that a package is implied (and indeed used by
# Flash when the fileis found).
#
# When a type has no package-prefix, and this method is called on it with
# an argument "com/foobar", we will 're-package' the type to subsequently
# become 'com.foobar.SomeClass'
def
sourcepath_location
(
path
)
path
=
""
if
path
==
"."
if
@package_name
==
""
and
path
!=
""
@package_name
=
path
.
gsub
(
"/"
,
"."
)
else
if
@package_name
!=
path
.
gsub
(
"/"
,
"."
)
$stderr
.
puts
(
"package
#{
@package_name
.
inspect
}
doesn't match location
#{
path
.
inspect
}
"
)
end
end
end
# compare two types based on their qualified names
def
<=>
(
other
)
cmp
=
qualified_name
.
downcase
<=>
other
.
qualified_name
.
downcase
return
cmp
unless
cmp
==
0
qualified_name
<=>
other
.
qualified_name
end
def
document?
@document
end
def
document
=
(
is_allowed_in_documentation
)
@document
=
is_allowed_in_documentation
end
end
class
ASVoidType
<
ASType
def
initialize
@name
=
"Void"
@package_name
=
""
@document
=
false
end
end
AS_VOID
=
ASVoidType
.
new
# Classes are types that (just for the perposes of API docs) have fields, and
# implement interfaces
class
ASClass
<
ASType
def
initialize
(
name
)
@dynamic
=
false
@interfaces
=
[
]
@fields
=
[
]
super
(
name
)
end
attr_accessor
:dynamic
def
implements_interfaces?
!
@interfaces
.
empty?
end
def
add_interface
(
name
)
@interfaces
<<
name
end
def
each_interface
@interfaces
.
each
do
|
name
|
yield
name
end
end
# like #each_interface, but then also reports each_interface of each_ancestor
def
each_implemented_interface
each_interface
do
|
interface
|
yield
interface
.
resolved_type
if
interface
.
resolved?
end
each_ancestor
do
|
supertype
|
supertype
.
each_interface
do
|
interface
|
yield
interface
.
resolved_type
if
interface
.
resolved?
end
end
end
def
add_field
(
field
)
@fields
<<
field
end
def
fields?
!
@fields
.
empty?
end
# returns true if this class, or any superclass has fields
def
inherited_fields?
return
true
if
fields?
each_ancestor
do
|
supertype
|
return
true
if
supertype
.
fields?
end
false
end
def
each_field
@fields
.
each
do
|
field
|
yield
field
end
end
def
fields
@fields
.
dup
end
def
get_field_called
(
name
)
each_field
do
|
field
|
return
field
if
field
.
name
==
name
end
nil
end
end
# ASInterface doesn't add anything to the superclass, it just affirms that
# the API only supported by ASClass will not be available here
class
ASInterface
<
ASType
def
initialize
(
name
)
super
(
name
)
end
def
implements_interfaces?
false
end
def
fields?
false
end
end
# A member in some type
class
ASMember
def
initialize
(
containing_type
,
access
,
name
)
@containing_type
=
containing_type
@access
=
access
@name
=
name
@comment
=
nil
end
attr_accessor
:containing_type
,
:access
,
:name
,
:comment
# compares two members based on their names
def
<=>
(
other
)
cmp
=
name
.
downcase
<=>
other
.
name
.
downcase
return
cmp
unless
cmp
==
0
name
<=>
other
.
name
end
end
# A method member, which may appear in an ASClass or ASInterface
class
ASMethod
<
ASMember
def
initialize
(
containing_type
,
access
,
name
)
super
(
containing_type
,
access
,
name
)
@return_type
=
nil
@args
=
[
]
end
attr_accessor
:return_type
def
add_arg
(
arg
)
@args
<<
arg
end
def
arguments
@args
end
def
argument
(
index
)
@args
[
index
]
end
def
specified_by
raise
"not applicable to interface methods"
unless
containing_type
.
is_a?
(
ASClass
)
containing_type
.
each_implemented_interface
do
|
interface
|
spec_method
=
interface
.
get_method_called
(
name
)
return
spec_method
unless
spec_method
.
nil?
end
nil
end
def
overrides
containing_type
.
each_ancestor
do
|
as_class
|
as_method
=
as_class
.
get_method_called
(
name
)
return
as_method
unless
as_method
.
nil?
end
end
def
inherited_comment
raise
"method
#{
name
.
inspect
}
has a comment of its own"
unless
comment
.
nil?
containing_type
.
each_ancestor
do
|
as_class
|
as_method
=
as_class
.
get_method_called
(
name
)
return
as_method
unless
as_method
.
nil?
||
as_method
.
comment
.
nil?
end
if
containing_type
.
is_a?
(
ASClass
)
containing_type
.
each_implemented_interface
do
|
as_interface
|
as_method
=
as_interface
.
get_method_called
(
name
)
return
as_method
unless
as_method
.
nil?
||
as_method
.
comment
.
nil?
end
end
end
end
# A field member, which may appear in an ASClass, but not an ASInterface
class
ASField
<
ASMember
end
class
ASExplicitField
<
ASField
def
initialize
(
containing_tyye
,
access
,
name
)
super
(
containing_tyye
,
access
,
name
)
@field_type
=
nil
end
attr_accessor
:field_type
def
readwrite?
;
true
;
end
def
read?
;
true
;
end
def
write?
;
true
;
end
end
# A field implied by the presence of "get" or "set" methods with this name
class
ASImplicitField
<
ASField
def
initialize
(
containing_tyye
,
name
)
super
(
containing_tyye
,
nil
,
name
)
@getter_method
=
nil
@setter_method
=
nil
end
attr_accessor
:getter_method
,
:setter_method
def
readwrite?
!
(
@getter_method
.
nil?
||
@setter_method
.
nil?
)
end
def
read?
!
@getter_method
.
nil?
end
def
write?
!
@setter_method
.
nil?
end
def
access
(
@getter_method
||
@setter_method
)
.
access
end
def
comment
(
@getter_method
||
@setter_method
)
.
comment
end
def
field_type
if
read?
return
@getter_method
.
return_type
else
unless
@setter_method
.
arguments
.
empty?
arg
=
@setter_method
.
arguments
[
0
]
return
arg
.
arg_type
end
end
return
nil
end
end
# A formal function parameter, a list of which appear in an ASMethod
class
ASArg
def
initialize
(
name
)
@name
=
name
@arg_type
=
nil
end
attr_accessor
:name
,
:arg_type
end
# A simple aggregation of ASType objects
class
ASPackage
def
initialize
(
name
)
@name
=
name
@types
=
[
]
end
attr_accessor
:name
def
add_type
(
type
)
@types
<<
type
end
def
types
@types
end
def
each_type
@types
.
each
do
|
type
|
yield
type
end
end
def
classes
result
=
[
]
each_type
do
|
type
|
result
<<
type
if
type
.
instance_of?
(
ASClass
)
end
result
end
def
interfaces
result
=
[
]
each_type
do
|
type
|
result
<<
type
if
type
.
instance_of?
(
ASInterface
)
end
result
end
def
<=>
(
other
)
cmp
=
name
.
downcase
<=>
other
.
name
.
downcase
return
cmp
unless
cmp
==
0
name
<=>
other
.
name
end
end
Back
|
FazBrowse Home
|
New Git URL