1
|
1 |
ClassDescription subclass:#JavaClass
|
27
|
2 |
instanceVariableNames:'fullName accessFlags constantPool sourceFile fields'
|
1
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Java-Classes'
|
|
6 |
!
|
|
7 |
|
|
8 |
|
|
9 |
!JavaClass class methodsFor:'instance creation'!
|
|
10 |
|
7
|
11 |
fullName:aString
|
|
12 |
^ self new setFullName:aString
|
|
13 |
|
|
14 |
"Created: 15.4.1996 / 15:52:55 / cg"
|
|
15 |
!
|
|
16 |
|
38
|
17 |
fullName:aString numStatic:nStatic
|
|
18 |
|meta cls|
|
|
19 |
|
|
20 |
"create the metaclass first"
|
|
21 |
|
40
|
22 |
meta := Metaclass new.
|
|
23 |
meta setSuperclass:(self).
|
38
|
24 |
meta instSize:(JavaClass class instSize + nStatic).
|
|
25 |
meta setName:(aString , 'class') asSymbol.
|
|
26 |
meta setClassVariableString:''.
|
|
27 |
|
|
28 |
"then let the new meta create the class"
|
|
29 |
cls := meta new.
|
|
30 |
cls setSuperclass:JavaObject.
|
|
31 |
cls instSize:0.
|
|
32 |
cls setName:aString.
|
|
33 |
cls flags:0.
|
40
|
34 |
"/ cls setClassVariableString:''.
|
38
|
35 |
cls setInstanceVariableString:''.
|
|
36 |
cls category:#java.
|
40
|
37 |
|
|
38 |
cls setFullName:aString.
|
38
|
39 |
^ cls
|
|
40 |
|
|
41 |
"/ ^ self new setFullName:aString
|
|
42 |
|
|
43 |
"Created: 15.4.1996 / 15:52:55 / cg"
|
|
44 |
!
|
|
45 |
|
1
|
46 |
name:aString
|
7
|
47 |
self shouldNotImplement
|
1
|
48 |
|
|
49 |
"Created: 15.4.1996 / 15:52:55 / cg"
|
|
50 |
! !
|
|
51 |
|
40
|
52 |
!JavaClass class methodsFor:'special'!
|
|
53 |
|
|
54 |
setInstanceVariableStringFromFields:f in:aClass
|
|
55 |
|varNames|
|
|
56 |
|
|
57 |
varNames := ''.
|
|
58 |
f do:[:aField |
|
|
59 |
varNames := varNames , aField name , ' '
|
|
60 |
].
|
|
61 |
aClass setInstanceVariableString:varNames.
|
|
62 |
|
|
63 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
|
64 |
! !
|
|
65 |
|
5
|
66 |
!JavaClass methodsFor:'accessing'!
|
|
67 |
|
7
|
68 |
category
|
|
69 |
"java classes do not really hav a category;
|
|
70 |
simulate one by separating its name into individual components,
|
|
71 |
prepending 'java'"
|
|
72 |
|
|
73 |
|nameComponents|
|
|
74 |
|
|
75 |
nameComponents := fullName asCollectionOfSubstringsSeparatedBy:$/.
|
|
76 |
^ 'java-' , (nameComponents asStringWith:$/ from:1 to:(nameComponents size - 1))
|
|
77 |
!
|
|
78 |
|
5
|
79 |
constantPool
|
|
80 |
^ constantPool
|
7
|
81 |
!
|
|
82 |
|
|
83 |
fullName
|
|
84 |
^ fullName
|
8
|
85 |
!
|
|
86 |
|
|
87 |
name
|
27
|
88 |
^ name "/ fullName
|
22
|
89 |
!
|
|
90 |
|
|
91 |
package
|
|
92 |
"extract from the fullName"
|
|
93 |
|
|
94 |
|components|
|
|
95 |
|
|
96 |
components := fullName asCollectionOfSubstringsSeparatedBy:$/.
|
24
|
97 |
components size > 1 ifTrue:[
|
|
98 |
^ (components copyWithoutLast:1) asStringWith:$/
|
|
99 |
].
|
|
100 |
^ fullName
|
22
|
101 |
|
|
102 |
"
|
|
103 |
Java allClasses first fullName
|
|
104 |
Java allClasses first package
|
|
105 |
"
|
24
|
106 |
!
|
|
107 |
|
|
108 |
sourceFile
|
|
109 |
^ sourceFile
|
5
|
110 |
! !
|
|
111 |
|
29
|
112 |
!JavaClass methodsFor:'instance creation'!
|
|
113 |
|
|
114 |
basicNew
|
|
115 |
|newJavaObject|
|
|
116 |
|
|
117 |
newJavaObject := super basicNew.
|
|
118 |
newJavaObject initializeToZero. "/ mhmh
|
|
119 |
^ newJavaObject
|
|
120 |
!
|
|
121 |
|
|
122 |
new
|
|
123 |
|newJavaObject|
|
|
124 |
|
|
125 |
newJavaObject := self basicNew.
|
|
126 |
newJavaObject invoke:#'<init>'.
|
|
127 |
^ newJavaObject
|
|
128 |
|
|
129 |
|
|
130 |
! !
|
|
131 |
|
1
|
132 |
!JavaClass methodsFor:'printing & storing'!
|
|
133 |
|
|
134 |
displayString
|
41
|
135 |
^ fullName copy replaceAll:$/ by:$.
|
|
136 |
"/ ^ 'JAVA-' , name .
|
|
137 |
"/ ^ name , '(Java)' "/ 'JavaClass(' , name , ')'
|
1
|
138 |
|
|
139 |
"Created: 15.4.1996 / 16:02:48 / cg"
|
|
140 |
! !
|
|
141 |
|
|
142 |
!JavaClass methodsFor:'private accessing'!
|
|
143 |
|
5
|
144 |
addMethod:m name:name signature:signature
|
|
145 |
selectorArray isNil ifTrue:[
|
|
146 |
selectorArray := #().
|
|
147 |
methodArray := #()
|
|
148 |
].
|
29
|
149 |
selectorArray := selectorArray copyWith:(name , signature) asSymbol. "/ name.
|
|
150 |
"/ selectorArray := selectorArray copyWith:name asSymbol. "/ name.
|
5
|
151 |
methodArray := methodArray copyWith:m
|
|
152 |
|
|
153 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
|
154 |
!
|
|
155 |
|
1
|
156 |
setAccessFlags:flags
|
3
|
157 |
accessFlags := flags.
|
1
|
158 |
|
|
159 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
5
|
160 |
!
|
|
161 |
|
|
162 |
setConstantPool:anArray
|
|
163 |
constantPool := anArray.
|
|
164 |
|
|
165 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
|
166 |
!
|
|
167 |
|
27
|
168 |
setFields:f
|
40
|
169 |
JavaClass setInstanceVariableStringFromFields:f in:self.
|
27
|
170 |
|
|
171 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
|
172 |
!
|
|
173 |
|
7
|
174 |
setFullName:aString
|
|
175 |
|nameComponents|
|
|
176 |
|
|
177 |
fullName := aString.
|
|
178 |
nameComponents := aString asCollectionOfSubstringsSeparatedBy:$/.
|
|
179 |
name := nameComponents last
|
|
180 |
|
|
181 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
|
182 |
!
|
|
183 |
|
5
|
184 |
setSourceFile:aFilename
|
|
185 |
sourceFile := aFilename.
|
|
186 |
|
|
187 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
27
|
188 |
!
|
|
189 |
|
|
190 |
setSuperclass:aClass
|
|
191 |
aClass isNil ifTrue:[
|
29
|
192 |
super setSuperclass:JavaObject
|
|
193 |
] ifFalse:[
|
|
194 |
(aClass isMemberOf:JavaUnresolvedClassConstant) ifTrue:[
|
|
195 |
self halt.
|
|
196 |
].
|
|
197 |
super setSuperclass:aClass.
|
27
|
198 |
].
|
29
|
199 |
|
|
200 |
instvars notNil ifTrue:[
|
|
201 |
(superclass notNil and:[(superclass isMemberOf:JavaUnresolvedClassConstant) not]) ifTrue:[
|
|
202 |
instSize := superclass instSize + (instvars asCollectionOfWords size)
|
|
203 |
] ifFalse:[
|
|
204 |
instSize := instvars asCollectionOfWords size
|
|
205 |
]
|
|
206 |
].
|
27
|
207 |
|
|
208 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
1
|
209 |
! !
|
|
210 |
|
18
|
211 |
!JavaClass methodsFor:'queries'!
|
|
212 |
|
42
|
213 |
browserClass
|
|
214 |
"return the browser to use for this class -
|
|
215 |
this can be redefined in special classes, to get different browsers"
|
|
216 |
|
|
217 |
^ JavaBrowser
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
!
|
|
223 |
|
27
|
224 |
isClass
|
|
225 |
^ true
|
|
226 |
!
|
|
227 |
|
18
|
228 |
isFinal
|
|
229 |
^ (accessFlags bitAnd:16r0010) ~~ 0
|
|
230 |
!
|
|
231 |
|
|
232 |
isInterface
|
|
233 |
^ (accessFlags bitAnd:16r0200) ~~ 0
|
|
234 |
!
|
|
235 |
|
|
236 |
isPublic
|
|
237 |
^ (accessFlags bitAnd:16r0001) ~~ 0
|
|
238 |
! !
|
|
239 |
|
21
|
240 |
!JavaClass methodsFor:'resolving class refs'!
|
|
241 |
|
|
242 |
resolveClassRefs
|
|
243 |
|newClass const newConst|
|
|
244 |
|
|
245 |
(superclass isMemberOf:JavaUnresolvedClassConstant) ifTrue:[
|
|
246 |
newClass := superclass resolve.
|
|
247 |
newClass isNil ifTrue:[
|
38
|
248 |
newClass := JavaClassReader loadClassLazy:(superclass fullName).
|
21
|
249 |
].
|
|
250 |
newClass notNil ifTrue:[
|
|
251 |
superclass := newClass
|
|
252 |
]
|
|
253 |
].
|
|
254 |
|
|
255 |
1 to:constantPool size do:[:index |
|
|
256 |
const := constantPool at:index.
|
|
257 |
(const isMemberOf:JavaUnresolvedClassConstant) ifTrue:[
|
|
258 |
"/ try to resolve
|
|
259 |
newConst := const resolve.
|
|
260 |
newConst isNil ifTrue:[
|
38
|
261 |
newConst := JavaClassReader loadClassLazy:(const fullName).
|
21
|
262 |
].
|
|
263 |
newConst notNil ifTrue:[
|
|
264 |
constantPool at:index put:newConst
|
|
265 |
]
|
|
266 |
]
|
|
267 |
].
|
27
|
268 |
|
|
269 |
(superclass notNil and:[(superclass isMemberOf:JavaUnresolvedClassConstant) not]) ifTrue:[
|
29
|
270 |
superclass resolveClassRefs.
|
27
|
271 |
instSize := superclass instSize + (instvars asCollectionOfWords size)
|
|
272 |
] ifFalse:[
|
|
273 |
instSize := instvars asCollectionOfWords size
|
|
274 |
].
|
38
|
275 |
"/Transcript show:'resolved '; show: self displayString;
|
|
276 |
"/ show: ' instSize='; showCr: instSize.
|
21
|
277 |
! !
|
|
278 |
|
1
|
279 |
!JavaClass class methodsFor:'documentation'!
|
|
280 |
|
|
281 |
version
|
42
|
282 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaClass.st,v 1.16 1996/05/03 11:44:24 cg Exp $'
|
1
|
283 |
! !
|