17
|
1 |
Object subclass:#Java
|
|
2 |
instanceVariableNames:''
|
90
|
3 |
classVariableNames:'Classes UnresolvedClassRefs SourceDirectories JavaString'
|
17
|
4 |
poolDictionaries:''
|
|
5 |
category:'Java-Support'
|
|
6 |
!
|
|
7 |
|
|
8 |
|
65
|
9 |
!Java class methodsFor:'accessing'!
|
24
|
10 |
|
90
|
11 |
classNamed:aString
|
|
12 |
^ self at:aString
|
32
|
13 |
!
|
|
14 |
|
90
|
15 |
javaString
|
|
16 |
^ JavaString
|
76
|
17 |
!
|
|
18 |
|
|
19 |
sourceDirectories
|
|
20 |
^ SourceDirectories
|
|
21 |
!
|
|
22 |
|
|
23 |
sourceDirectories:aCollectionOfPaths
|
|
24 |
SourceDirectories := aCollectionOfPaths asOrderedCollection
|
|
25 |
|
|
26 |
"
|
|
27 |
Java
|
|
28 |
sourceDirectories:#(
|
|
29 |
'/phys/ibm3/java/src'
|
|
30 |
)
|
|
31 |
"
|
|
32 |
|
|
33 |
|
24
|
34 |
! !
|
|
35 |
|
65
|
36 |
!Java class methodsFor:'class initialization'!
|
47
|
37 |
|
|
38 |
initAllClasses
|
|
39 |
self allClassesDo:[:cls |
|
|
40 |
cls isInitialized ifFalse:[
|
|
41 |
cls classInit
|
|
42 |
]
|
|
43 |
]
|
|
44 |
|
|
45 |
!
|
|
46 |
|
76
|
47 |
initialize
|
|
48 |
self
|
|
49 |
sourceDirectories:#(
|
|
50 |
'/home/cg/java/JDK/src'
|
|
51 |
'/home/cg/java/JWS/src'
|
|
52 |
'/home/cg/java/src'
|
|
53 |
'/phys/ibm3/java/src'
|
|
54 |
)
|
|
55 |
|
|
56 |
"
|
|
57 |
Java initialize
|
|
58 |
"
|
|
59 |
|
|
60 |
|
|
61 |
!
|
|
62 |
|
47
|
63 |
reinitAllClasses
|
|
64 |
self markAllClassesUninitialized.
|
|
65 |
self initAllClasses
|
|
66 |
! !
|
|
67 |
|
65
|
68 |
!Java class methodsFor:'enumerating'!
|
43
|
69 |
|
90
|
70 |
allClasses
|
|
71 |
^ Classes
|
|
72 |
!
|
|
73 |
|
43
|
74 |
allClassesDo:aBlock
|
|
75 |
Classes notNil ifTrue:[
|
|
76 |
Classes do:aBlock
|
|
77 |
]
|
|
78 |
! !
|
|
79 |
|
65
|
80 |
!Java class methodsFor:'registering java classes'!
|
17
|
81 |
|
|
82 |
at:aJavaName
|
43
|
83 |
"search & return for a class by name;
|
|
84 |
if there is no such class, return nil.
|
|
85 |
The argument, aJavaName may be either an internal name
|
|
86 |
(sep'd by slashes) or an external name (sep'd by periods).
|
|
87 |
The 'java/lang' standard packages prefix may be ommitted."
|
|
88 |
|
|
89 |
|sym nm cls|
|
|
90 |
|
17
|
91 |
Classes isNil ifTrue:[^ nil].
|
43
|
92 |
|
|
93 |
sym := aJavaName asSymbolIfInterned.
|
|
94 |
sym notNil ifTrue:[
|
|
95 |
cls := Classes at:sym ifAbsent:nil.
|
|
96 |
cls notNil ifTrue:[^ cls].
|
|
97 |
].
|
17
|
98 |
|
43
|
99 |
nm := aJavaName.
|
|
100 |
(nm includes:$.) ifTrue:[
|
90
|
101 |
nm := (nm asString copy replaceAll:$. by:$/).
|
43
|
102 |
sym := nm asSymbolIfInterned.
|
|
103 |
sym notNil ifTrue:[
|
|
104 |
cls := Classes at:sym ifAbsent:nil.
|
|
105 |
cls notNil ifTrue:[^ cls].
|
|
106 |
].
|
|
107 |
].
|
|
108 |
|
|
109 |
(nm includes:$/) ifFalse:[
|
|
110 |
"/
|
|
111 |
"/ try java.lang.Foo
|
|
112 |
"/
|
|
113 |
nm := 'java/lang/' , nm.
|
|
114 |
sym := nm asSymbolIfInterned.
|
|
115 |
sym notNil ifTrue:[
|
|
116 |
cls := Classes at:sym ifAbsent:nil.
|
|
117 |
cls notNil ifTrue:[^ cls].
|
|
118 |
].
|
|
119 |
].
|
|
120 |
|
|
121 |
^ nil
|
|
122 |
|
|
123 |
"
|
|
124 |
Java at:'java/lang/String'
|
|
125 |
Java at:'java.lang.String'
|
|
126 |
Java at:'String'
|
|
127 |
Java at:'System'
|
|
128 |
Java at:'Foo'
|
|
129 |
"
|
17
|
130 |
!
|
|
131 |
|
|
132 |
at:aJavaName put:aJavaClass
|
90
|
133 |
|nameSymbol|
|
|
134 |
|
17
|
135 |
Classes isNil ifTrue:[
|
|
136 |
Classes := IdentityDictionary new.
|
|
137 |
].
|
90
|
138 |
|
|
139 |
nameSymbol := aJavaName asSymbol.
|
|
140 |
(Classes includesKey:nameSymbol) ifTrue:[
|
65
|
141 |
self halt:'class ' , aJavaName , ' is already loaded'.
|
|
142 |
].
|
54
|
143 |
|
90
|
144 |
Classes at:nameSymbol put:aJavaClass.
|
|
145 |
nameSymbol == #'java/lang/String' ifTrue:[
|
|
146 |
JavaString := aJavaClass
|
|
147 |
].
|
21
|
148 |
|
43
|
149 |
"/ UnresolvedClassRefs notNil ifTrue:[
|
|
150 |
"/ UnresolvedClassRefs do:[:toResolve |
|
|
151 |
"/ ]
|
|
152 |
"/ ].
|
|
153 |
|
27
|
154 |
self changed:#classes
|
17
|
155 |
|
|
156 |
"Created: 17.4.1996 / 23:29:31 / cg"
|
21
|
157 |
"Modified: 18.4.1996 / 00:45:39 / cg"
|
|
158 |
!
|
|
159 |
|
|
160 |
flushClasses
|
90
|
161 |
Classes := UnresolvedClassRefs := JavaString := nil.
|
71
|
162 |
JavaInterpreter terminateAllThreads.
|
84
|
163 |
JavaInterpreter releaseAllMonitors.
|
90
|
164 |
JavaInterpreter releaseAllWindows.
|
|
165 |
JavaUnresolvedConstant flushPatchLists.
|
21
|
166 |
|
|
167 |
"
|
|
168 |
Java flushClasses
|
|
169 |
"
|
|
170 |
|
|
171 |
"Modified: 18.4.1996 / 00:20:23 / cg"
|
|
172 |
!
|
|
173 |
|
43
|
174 |
markAllClassesUninitialized
|
|
175 |
self allClassesDo:[:aJavaClass |
|
|
176 |
aJavaClass markUninitialized
|
|
177 |
].
|
|
178 |
|
|
179 |
"
|
|
180 |
Java markAllClassesUninitialized
|
|
181 |
"
|
|
182 |
!
|
|
183 |
|
90
|
184 |
nextUnresolved
|
|
185 |
|unresolved|
|
|
186 |
|
|
187 |
UnresolvedClassRefs isNil ifTrue:[
|
|
188 |
^ nil
|
|
189 |
].
|
|
190 |
unresolved := UnresolvedClassRefs removeFirst.
|
|
191 |
UnresolvedClassRefs isEmpty ifTrue:[
|
|
192 |
UnresolvedClassRefs := nil
|
|
193 |
].
|
|
194 |
^ unresolved
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
!
|
|
199 |
|
21
|
200 |
rememberUnresolved:anUnresolvedClassRef
|
90
|
201 |
('JAVA: remember unresolved class: ' , anUnresolvedClassRef fullName) infoPrintCR.
|
|
202 |
|
|
203 |
UnresolvedClassRefs isNil ifTrue:[
|
|
204 |
UnresolvedClassRefs := Set new.
|
|
205 |
].
|
|
206 |
UnresolvedClassRefs add:anUnresolvedClassRef
|
21
|
207 |
|
|
208 |
"Created: 18.4.1996 / 00:05:31 / cg"
|
|
209 |
"Modified: 18.4.1996 / 00:05:41 / cg"
|
90
|
210 |
!
|
|
211 |
|
|
212 |
unresolvedClassRefFor:aClassName
|
|
213 |
UnresolvedClassRefs isNil ifTrue:[^ nil].
|
|
214 |
^ UnresolvedClassRefs at:aClassName ifAbsent:nil.
|
17
|
215 |
! !
|
|
216 |
|
76
|
217 |
!Java class methodsFor:'source management'!
|
|
218 |
|
|
219 |
classSourceOf:aClass
|
|
220 |
|package dirName binary sourceFileName sourceFile dirHolder fileName path|
|
|
221 |
|
|
222 |
aClass isNil ifTrue:[
|
|
223 |
^ nil
|
|
224 |
].
|
|
225 |
package := aClass package.
|
|
226 |
|
|
227 |
"/ first, look in the directory, where the binary
|
|
228 |
"/ was loaded from.
|
|
229 |
|
|
230 |
binary := aClass binaryFile asFilename.
|
|
231 |
sourceFileName := binary withSuffix:'java'.
|
|
232 |
sourceFile := sourceFileName asFilename.
|
|
233 |
|
|
234 |
sourceFile exists ifFalse:[
|
|
235 |
sourceFileName := binary withSuffix:'jav'.
|
|
236 |
sourceFile := sourceFileName asFilename.
|
|
237 |
sourceFile exists ifFalse:[
|
|
238 |
sourceFileName := binary withSuffix:'JAV'.
|
|
239 |
sourceFile := sourceFileName asFilename.
|
|
240 |
sourceFile exists ifFalse:[
|
|
241 |
sourceFileName := binary withSuffix:'JAVA'.
|
|
242 |
sourceFile := sourceFileName asFilename.
|
|
243 |
].
|
|
244 |
].
|
|
245 |
].
|
|
246 |
|
|
247 |
"/ special case: there where multiple classes in a single
|
|
248 |
"/ source file.
|
|
249 |
|
|
250 |
binary withoutSuffix baseName ~= aClass sourceFile asFilename withoutSuffix baseName ifTrue:[
|
|
251 |
'JAVA: trouble extracting fileName: ' print.
|
|
252 |
binary withoutSuffix baseName print. ' vs. ' print.
|
|
253 |
aClass sourceFile asFilename withoutSuffix baseName printCR.
|
|
254 |
].
|
|
255 |
|
|
256 |
"/ if that fails, look in standard places
|
|
257 |
|
|
258 |
sourceFile exists ifFalse:[
|
|
259 |
sourceFileName := aClass sourceFile.
|
|
260 |
sourceFile := sourceFileName asFilename.
|
|
261 |
sourceFile exists ifFalse:[
|
|
262 |
"/
|
|
263 |
"/ mhmh - look for its directory
|
|
264 |
"/
|
|
265 |
dirName := sourceFile directoryName.
|
|
266 |
fileName := sourceFile baseName.
|
|
267 |
|
|
268 |
(dirName asFilename exists
|
|
269 |
and:[(dirName asFilename construct:(package , '/' , fileName)) exists])
|
|
270 |
ifFalse:[
|
|
271 |
(dirName asFilename exists
|
|
272 |
and:[(dirName asFilename construct:(fileName)) exists])
|
|
273 |
ifFalse:[
|
|
274 |
dirName := self findSourceDirOf:fileName inPackage:package.
|
|
275 |
|
|
276 |
"/ [dirName isNil] whileTrue:[
|
|
277 |
"/ dirName := Dialog requestDirectoryName:'top directory for ' , package , '/' , fileName.
|
|
278 |
"/ (dirName isNil or:[dirName isEmpty]) ifTrue:[^ self].
|
|
279 |
"/ ].
|
|
280 |
].
|
|
281 |
].
|
|
282 |
|
|
283 |
(dirName notNil and:[dirName asFilename exists]) ifTrue:[
|
|
284 |
path := (dirName asFilename construct:(package , '/' , fileName)) asFilename.
|
|
285 |
path exists ifFalse:[
|
|
286 |
path := (dirName asFilename construct:(fileName)) asFilename.
|
|
287 |
].
|
|
288 |
].
|
|
289 |
|
|
290 |
(path notNil and:[path exists]) ifFalse:[
|
|
291 |
^ nil
|
|
292 |
].
|
|
293 |
|
|
294 |
sourceFile := path asFilename.
|
|
295 |
].
|
|
296 |
].
|
|
297 |
^ (sourceFile contentsOfEntireFile).
|
|
298 |
|
|
299 |
|
|
300 |
!
|
|
301 |
|
|
302 |
findSourceDirOf:fileName inPackage:aPackage
|
|
303 |
SourceDirectories notNil ifTrue:[
|
|
304 |
SourceDirectories do:[:aDir |
|
|
305 |
(aDir asFilename construct:('/' , aPackage , '/' , fileName))
|
|
306 |
asFilename exists ifTrue:[
|
|
307 |
^ aDir
|
|
308 |
].
|
|
309 |
(aDir asFilename construct:('/' , fileName))
|
|
310 |
asFilename exists ifTrue:[
|
|
311 |
^ aDir
|
|
312 |
].
|
|
313 |
]
|
|
314 |
].
|
|
315 |
^ nil
|
|
316 |
|
|
317 |
|
|
318 |
! !
|
|
319 |
|
65
|
320 |
!Java class methodsFor:'documentation'!
|
17
|
321 |
|
|
322 |
version
|
90
|
323 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/Java.st,v 1.14 1996/06/28 21:36:24 cg Exp $'
|
17
|
324 |
! !
|
76
|
325 |
Java initialize!
|