unageanu-javaclass 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,279 +1,279 @@
1
- require "javaclass/base"
2
-
3
- module JavaClass
4
-
5
- #
6
- #===クラスのアクセスフラグの基底クラス。
7
- #
8
- class AccessFlag
9
- include JavaClass::Base
10
-
11
- def initialize( flag )
12
- @flag = flag
13
- end
14
- def on?(flag)
15
- @flag & flag > 0
16
- end
17
- def on(flag)
18
- @flag |= flag
19
- self
20
- end
21
- def off(flag)
22
- @flag &= ~flag
23
- self
24
- end
25
- def to_bytes()
26
- to_byte( @flag, 2 )
27
- end
28
- end
29
-
30
- #
31
- #===クラスのアクセスフラグ
32
- #
33
- class ClassAccessFlag < AccessFlag
34
-
35
- # Declared public; may be accessed from outside its package.
36
- ACC_PUBLIC = 0x0001
37
- # Declared final; no subclasses allowed.
38
- ACC_FINAL = 0x0010
39
- # Treat superclass methods specially when invoked by the invokespecial instruction.
40
- ACC_SUPER = 0x0020 # 旧コンパイラが出力する値らしい。
41
- # Is an interface, not a class.
42
- ACC_INTERFACE = 0x0200
43
- # Declared abstract; must not be instantiated.
44
- ACC_ABSTRACT = 0x0400
45
- # Declared synthetic; Not present in the source code.
46
- ACC_SYNTHETIC = 0x1000 # ソースには出てこない。コンパイラが付加する場合があるとのこと。
47
- # Declared as an annotation type.
48
- ACC_ANNOTATION = 0x2000
49
- # Declared as an enum type.
50
- ACC_ENUM = 0x4000
51
-
52
- #
53
- #===ソースコードに登場するモディファイアを配列で取得する。
54
- #
55
- #<b>戻り値</b>::ソースコードに登場するモディファイアの配列
56
- #
57
- def source_modifiers
58
- modifiers = []
59
- modifiers << "final" if on? ACC_FINAL
60
- modifiers << "abstract" if on? ACC_ABSTRACT
61
- return modifiers
62
- end
63
-
64
- #
65
- #===アクセサを文字列で取得する。
66
- #
67
- #<b>戻り値</b>::アクセサを示す文字列
68
- #
69
- def accessor
70
- return "public" if on? ACC_PUBLIC
71
- return ""
72
- end
73
-
74
- #
75
- #===クラスの種別(class or interface or enum ..) を文字列で取得する。
76
- #
77
- #<b>戻り値</b>::クラスの種別
78
- #
79
- def type
80
- return "@interface" if on?(ACC_INTERFACE) && on?(ACC_ANNOTATION)
81
- return "interface" if on? ACC_INTERFACE
82
- return "enum" if on? ACC_ENUM
83
- return "class"
84
- end
85
-
86
- def to_s
87
- list = accessor.length > 0 ? [accessor] : []
88
- (list + source_modifiers << type).join(" ")
89
- end
90
- end
91
-
92
- #
93
- #===フィールドのアクセスフラグ
94
- #
95
- class FieldAccessFlag < AccessFlag
96
- # Declared public; may be accessed from outside its package.
97
- ACC_PUBLIC = 0x0001
98
- # Declared private; usable only within the defining class.
99
- ACC_PRIVATE = 0x0002
100
- # Declared protected; may be accessed within subclasses.
101
- ACC_PROTECTED = 0x0004
102
- # Declared static.
103
- ACC_STATIC = 0x0008
104
- # Declared final; no further assignment after initialization.
105
- ACC_FINAL = 0x0010
106
- # Declared volatile; cannot be cached.
107
- ACC_VOLATILE = 0x0040
108
- # Declared transient; not written or read by a persistent object manager.
109
- ACC_TRANSIENT = 0x0080
110
- # Declared synthetic; Not present in the source code.
111
- ACC_SYNTHETIC = 0x1000 # ソースには出てこない。コンパイラが付加する場合があるとのこと。
112
- # Declared as an element of an enum.
113
- ACC_ENUM = 0x4000
114
-
115
- #
116
- #===ソースコードに登場するモディファイアを配列で取得する。
117
- #
118
- #<b>戻り値</b>::ソースコードに登場するモディファイアの配列
119
- #
120
- def source_modifiers
121
- modifiers = []
122
- modifiers << "static" if on? ACC_STATIC
123
- modifiers << "final" if on? ACC_FINAL
124
- modifiers << "volatile" if on? ACC_VOLATILE
125
- modifiers << "transient" if on? ACC_TRANSIENT
126
- return modifiers
127
- end
128
-
129
- #
130
- #===アクセサを文字列で取得する。
131
- #
132
- #<b>戻り値</b>::アクセサを示す文字列
133
- #
134
- def accessor
135
- return "public" if on? ACC_PUBLIC
136
- return "protected" if on? ACC_PROTECTED
137
- return "private" if on? ACC_PRIVATE
138
- return ""
139
- end
140
-
141
- def to_s
142
- list = accessor.length > 0 ? [accessor] : []
143
- (list + source_modifiers).join(" ")
144
- end
145
- end
146
-
147
- #
148
- #===メソッドのアクセスフラグ
149
- #
150
- class MethodAccessFlag < AccessFlag
151
- # Declared public; may be accessed from outside its package.
152
- ACC_PUBLIC = 0x0001
153
- # Declared private; accessible only within the defining class.
154
- ACC_PRIVATE = 0x0002
155
- # Declared protected; may be accessed within subclasses.
156
- ACC_PROTECTED = 0x0004
157
- # Declared static.
158
- ACC_STATIC = 0x0008
159
- # Declared final; must not be overridden.
160
- ACC_FINAL = 0x0010
161
- # Declared synchronized; invocation is wrapped in a monitor lock.
162
- ACC_SYNCHRONIZED = 0x0020
163
- # A bridge method, generated by the compiler.
164
- ACC_BRIDGE = 0x0040
165
- # Declared with variable number of arguments.
166
- ACC_VARARGS = 0x0080
167
- # Declared native; implemented in a language other than Java.
168
- ACC_NATIVE = 0x0100
169
- # Declared abstract; no implementation is provided.
170
- ACC_ABSTRACT = 0x0400
171
- # Declared strictfp; floating-point mode is FP-strict
172
- ACC_STRICT = 0x0800
173
- # Declared synthetic; Not present in the source code.
174
- ACC_SYNTHETIC = 0x1000
175
-
176
- #
177
- #===ソースコードに登場するモディファイアを配列で取得する。
178
- #
179
- #<b>戻り値</b>::ソースコードに登場するモディファイアの配列
180
- #
181
- def source_modifiers
182
- modifiers = []
183
- modifiers << "static" if on? ACC_STATIC
184
- modifiers << "final" if on? ACC_FINAL
185
- modifiers << "synchronized" if on? ACC_SYNCHRONIZED
186
- modifiers << "native" if on? ACC_NATIVE
187
- modifiers << "abstract" if on? ACC_ABSTRACT
188
- modifiers << "strictfp" if on? ACC_STRICT
189
- return modifiers
190
- end
191
-
192
- #
193
- #===アクセサを文字列で取得する。
194
- #
195
- #<b>戻り値</b>::アクセサを示す文字列
196
- #
197
- def accessor
198
- return "public" if on? ACC_PUBLIC
199
- return "protected" if on? ACC_PROTECTED
200
- return "private" if on? ACC_PRIVATE
201
- return ""
202
- end
203
-
204
- def to_s
205
- list = accessor.length > 0 ? [accessor] : []
206
- (list + source_modifiers).join(" ")
207
- end
208
- end
209
-
210
- #
211
- #===インナークラスのアクセスフラグ
212
- #
213
- class InnerClassAccessFlag < AccessFlag
214
-
215
- # Marked or implicitly public in source.
216
- ACC_PUBLIC = 0x0001
217
- # Marked private in source.
218
- ACC_PRIVATE = 0x0002
219
- # Marked protected in source.
220
- ACC_PROTECTED = 0x0004
221
- # Marked or implicitly static in source.
222
- ACC_STATIC = 0x0008
223
- # Marked final in source.
224
- ACC_FINAL = 0x0010
225
- # Was an interface in source.
226
- ACC_INTERFACE = 0x0200
227
- # Marked or implicitly abstract in source.
228
- ACC_ABSTRACT = 0x0400
229
- # Declared synthetic; Not present in the source code.
230
- ACC_SYNTHETIC = 0x1000 # ソースには出てこない。コンパイラが付加する場合があるとのこと。
231
- # Declared as an annotation type.
232
- ACC_ANNOTATION = 0x2000
233
- # Declared as an enum type.
234
- ACC_ENUM = 0x4000
235
-
236
- #
237
- #===ソースコードに登場するモディファイアを配列で取得する。
238
- #
239
- #<b>戻り値</b>::ソースコードに登場するモディファイアの配列
240
- #
241
- def source_modifiers
242
- modifiers = []
243
- modifiers << "static" if on? ACC_STATIC
244
- modifiers << "final" if on? ACC_FINAL
245
- modifiers << "abstract" if on? ACC_ABSTRACT
246
- return modifiers
247
- end
248
-
249
- #
250
- #===アクセサを文字列で取得する。
251
- #
252
- #<b>戻り値</b>::アクセサを示す文字列
253
- #
254
- def accessor
255
- return "public" if on? ACC_PUBLIC
256
- return "protected" if on? ACC_PROTECTED
257
- return "private" if on? ACC_PRIVATE
258
- return ""
259
- end
260
-
261
- #
262
- #===クラスの種別(class or interface or enum ..) を文字列で取得する。
263
- #
264
- #<b>戻り値</b>::クラスの種別
265
- #
266
- def type
267
- return "@interface" if on?(ACC_INTERFACE) && on?(ACC_ANNOTATION)
268
- return "interface" if on? ACC_INTERFACE
269
- return "enum" if on? ACC_ENUM
270
- return "class"
271
- end
272
-
273
- def to_s
274
- list = accessor.length > 0 ? [accessor] : []
275
- (list + source_modifiers << type).join(" ")
276
- end
277
- end
278
-
1
+ require "javaclass/base"
2
+
3
+ module JavaClass
4
+
5
+ #
6
+ #===クラスのアクセスフラグの基底クラス。
7
+ #
8
+ class AccessFlag
9
+ include JavaClass::Base
10
+
11
+ def initialize( flag )
12
+ @flag = flag
13
+ end
14
+ def on?(flag)
15
+ @flag & flag > 0
16
+ end
17
+ def on(flag)
18
+ @flag |= flag
19
+ self
20
+ end
21
+ def off(flag)
22
+ @flag &= ~flag
23
+ self
24
+ end
25
+ def to_bytes()
26
+ to_byte( @flag, 2 )
27
+ end
28
+ end
29
+
30
+ #
31
+ #===クラスのアクセスフラグ
32
+ #
33
+ class ClassAccessFlag < AccessFlag
34
+
35
+ # Declared public; may be accessed from outside its package.
36
+ ACC_PUBLIC = 0x0001
37
+ # Declared final; no subclasses allowed.
38
+ ACC_FINAL = 0x0010
39
+ # Treat superclass methods specially when invoked by the invokespecial instruction.
40
+ ACC_SUPER = 0x0020 # 旧コンパイラが出力する値らしい。
41
+ # Is an interface, not a class.
42
+ ACC_INTERFACE = 0x0200
43
+ # Declared abstract; must not be instantiated.
44
+ ACC_ABSTRACT = 0x0400
45
+ # Declared synthetic; Not present in the source code.
46
+ ACC_SYNTHETIC = 0x1000 # ソースには出てこない。コンパイラが付加する場合があるとのこと。
47
+ # Declared as an annotation type.
48
+ ACC_ANNOTATION = 0x2000
49
+ # Declared as an enum type.
50
+ ACC_ENUM = 0x4000
51
+
52
+ #
53
+ #===ソースコードに登場するモディファイアを配列で取得する。
54
+ #
55
+ #<b>戻り値</b>::ソースコードに登場するモディファイアの配列
56
+ #
57
+ def source_modifiers
58
+ modifiers = []
59
+ modifiers << "final" if on? ACC_FINAL
60
+ modifiers << "abstract" if on? ACC_ABSTRACT
61
+ return modifiers
62
+ end
63
+
64
+ #
65
+ #===アクセサを文字列で取得する。
66
+ #
67
+ #<b>戻り値</b>::アクセサを示す文字列
68
+ #
69
+ def accessor
70
+ return "public" if on? ACC_PUBLIC
71
+ return ""
72
+ end
73
+
74
+ #
75
+ #===クラスの種別(class or interface or enum ..) を文字列で取得する。
76
+ #
77
+ #<b>戻り値</b>::クラスの種別
78
+ #
79
+ def type
80
+ return "@interface" if on?(ACC_INTERFACE) && on?(ACC_ANNOTATION)
81
+ return "interface" if on? ACC_INTERFACE
82
+ return "enum" if on? ACC_ENUM
83
+ return "class"
84
+ end
85
+
86
+ def to_s
87
+ list = accessor.length > 0 ? [accessor] : []
88
+ (list + source_modifiers << type).join(" ")
89
+ end
90
+ end
91
+
92
+ #
93
+ #===フィールドのアクセスフラグ
94
+ #
95
+ class FieldAccessFlag < AccessFlag
96
+ # Declared public; may be accessed from outside its package.
97
+ ACC_PUBLIC = 0x0001
98
+ # Declared private; usable only within the defining class.
99
+ ACC_PRIVATE = 0x0002
100
+ # Declared protected; may be accessed within subclasses.
101
+ ACC_PROTECTED = 0x0004
102
+ # Declared static.
103
+ ACC_STATIC = 0x0008
104
+ # Declared final; no further assignment after initialization.
105
+ ACC_FINAL = 0x0010
106
+ # Declared volatile; cannot be cached.
107
+ ACC_VOLATILE = 0x0040
108
+ # Declared transient; not written or read by a persistent object manager.
109
+ ACC_TRANSIENT = 0x0080
110
+ # Declared synthetic; Not present in the source code.
111
+ ACC_SYNTHETIC = 0x1000 # ソースには出てこない。コンパイラが付加する場合があるとのこと。
112
+ # Declared as an element of an enum.
113
+ ACC_ENUM = 0x4000
114
+
115
+ #
116
+ #===ソースコードに登場するモディファイアを配列で取得する。
117
+ #
118
+ #<b>戻り値</b>::ソースコードに登場するモディファイアの配列
119
+ #
120
+ def source_modifiers
121
+ modifiers = []
122
+ modifiers << "static" if on? ACC_STATIC
123
+ modifiers << "final" if on? ACC_FINAL
124
+ modifiers << "volatile" if on? ACC_VOLATILE
125
+ modifiers << "transient" if on? ACC_TRANSIENT
126
+ return modifiers
127
+ end
128
+
129
+ #
130
+ #===アクセサを文字列で取得する。
131
+ #
132
+ #<b>戻り値</b>::アクセサを示す文字列
133
+ #
134
+ def accessor
135
+ return "public" if on? ACC_PUBLIC
136
+ return "protected" if on? ACC_PROTECTED
137
+ return "private" if on? ACC_PRIVATE
138
+ return ""
139
+ end
140
+
141
+ def to_s
142
+ list = accessor.length > 0 ? [accessor] : []
143
+ (list + source_modifiers).join(" ")
144
+ end
145
+ end
146
+
147
+ #
148
+ #===メソッドのアクセスフラグ
149
+ #
150
+ class MethodAccessFlag < AccessFlag
151
+ # Declared public; may be accessed from outside its package.
152
+ ACC_PUBLIC = 0x0001
153
+ # Declared private; accessible only within the defining class.
154
+ ACC_PRIVATE = 0x0002
155
+ # Declared protected; may be accessed within subclasses.
156
+ ACC_PROTECTED = 0x0004
157
+ # Declared static.
158
+ ACC_STATIC = 0x0008
159
+ # Declared final; must not be overridden.
160
+ ACC_FINAL = 0x0010
161
+ # Declared synchronized; invocation is wrapped in a monitor lock.
162
+ ACC_SYNCHRONIZED = 0x0020
163
+ # A bridge method, generated by the compiler.
164
+ ACC_BRIDGE = 0x0040
165
+ # Declared with variable number of arguments.
166
+ ACC_VARARGS = 0x0080
167
+ # Declared native; implemented in a language other than Java.
168
+ ACC_NATIVE = 0x0100
169
+ # Declared abstract; no implementation is provided.
170
+ ACC_ABSTRACT = 0x0400
171
+ # Declared strictfp; floating-point mode is FP-strict
172
+ ACC_STRICT = 0x0800
173
+ # Declared synthetic; Not present in the source code.
174
+ ACC_SYNTHETIC = 0x1000
175
+
176
+ #
177
+ #===ソースコードに登場するモディファイアを配列で取得する。
178
+ #
179
+ #<b>戻り値</b>::ソースコードに登場するモディファイアの配列
180
+ #
181
+ def source_modifiers
182
+ modifiers = []
183
+ modifiers << "static" if on? ACC_STATIC
184
+ modifiers << "final" if on? ACC_FINAL
185
+ modifiers << "synchronized" if on? ACC_SYNCHRONIZED
186
+ modifiers << "native" if on? ACC_NATIVE
187
+ modifiers << "abstract" if on? ACC_ABSTRACT
188
+ modifiers << "strictfp" if on? ACC_STRICT
189
+ return modifiers
190
+ end
191
+
192
+ #
193
+ #===アクセサを文字列で取得する。
194
+ #
195
+ #<b>戻り値</b>::アクセサを示す文字列
196
+ #
197
+ def accessor
198
+ return "public" if on? ACC_PUBLIC
199
+ return "protected" if on? ACC_PROTECTED
200
+ return "private" if on? ACC_PRIVATE
201
+ return ""
202
+ end
203
+
204
+ def to_s
205
+ list = accessor.length > 0 ? [accessor] : []
206
+ (list + source_modifiers).join(" ")
207
+ end
208
+ end
209
+
210
+ #
211
+ #===インナークラスのアクセスフラグ
212
+ #
213
+ class InnerClassAccessFlag < AccessFlag
214
+
215
+ # Marked or implicitly public in source.
216
+ ACC_PUBLIC = 0x0001
217
+ # Marked private in source.
218
+ ACC_PRIVATE = 0x0002
219
+ # Marked protected in source.
220
+ ACC_PROTECTED = 0x0004
221
+ # Marked or implicitly static in source.
222
+ ACC_STATIC = 0x0008
223
+ # Marked final in source.
224
+ ACC_FINAL = 0x0010
225
+ # Was an interface in source.
226
+ ACC_INTERFACE = 0x0200
227
+ # Marked or implicitly abstract in source.
228
+ ACC_ABSTRACT = 0x0400
229
+ # Declared synthetic; Not present in the source code.
230
+ ACC_SYNTHETIC = 0x1000 # ソースには出てこない。コンパイラが付加する場合があるとのこと。
231
+ # Declared as an annotation type.
232
+ ACC_ANNOTATION = 0x2000
233
+ # Declared as an enum type.
234
+ ACC_ENUM = 0x4000
235
+
236
+ #
237
+ #===ソースコードに登場するモディファイアを配列で取得する。
238
+ #
239
+ #<b>戻り値</b>::ソースコードに登場するモディファイアの配列
240
+ #
241
+ def source_modifiers
242
+ modifiers = []
243
+ modifiers << "static" if on? ACC_STATIC
244
+ modifiers << "final" if on? ACC_FINAL
245
+ modifiers << "abstract" if on? ACC_ABSTRACT
246
+ return modifiers
247
+ end
248
+
249
+ #
250
+ #===アクセサを文字列で取得する。
251
+ #
252
+ #<b>戻り値</b>::アクセサを示す文字列
253
+ #
254
+ def accessor
255
+ return "public" if on? ACC_PUBLIC
256
+ return "protected" if on? ACC_PROTECTED
257
+ return "private" if on? ACC_PRIVATE
258
+ return ""
259
+ end
260
+
261
+ #
262
+ #===クラスの種別(class or interface or enum ..) を文字列で取得する。
263
+ #
264
+ #<b>戻り値</b>::クラスの種別
265
+ #
266
+ def type
267
+ return "@interface" if on?(ACC_INTERFACE) && on?(ACC_ANNOTATION)
268
+ return "interface" if on? ACC_INTERFACE
269
+ return "enum" if on? ACC_ENUM
270
+ return "class"
271
+ end
272
+
273
+ def to_s
274
+ list = accessor.length > 0 ? [accessor] : []
275
+ (list + source_modifiers << type).join(" ")
276
+ end
277
+ end
278
+
279
279
  end