author | hlopkmar |
Fri, 13 May 2011 15:28:12 +0000 | |
branch | jk_new_structure |
changeset 781 | d27c59bcf38a |
parent 777 | e6e61412ae43 |
child 809 | 0fd3dbe06abb |
permissions | -rw-r--r-- |
752 | 1 |
"{ Package: 'stx:libjava' }" |
2 |
||
774 | 3 |
Object subclass:#JavaRef2 |
777 | 4 |
instanceVariableNames:'valueCache constantPool' |
752 | 5 |
classVariableNames:'' |
6 |
poolDictionaries:'' |
|
7 |
category:'Languages-Java-Reader-Support-new' |
|
8 |
! |
|
9 |
||
758 | 10 |
!JavaRef2 class methodsFor:'documentation'! |
11 |
||
12 |
documentation |
|
13 |
" |
|
14 |
I am parent of all reference types found in runtime constant pool. I define basic api - resolve and invalidate. |
|
15 |
Basic use case is to call resolve on my instance to get resolved thing, or to call invalidate to tell me, |
|
16 |
that world has changed and my cache is no longer valid. |
|
17 |
||
18 |
[author:] |
|
19 |
Marcel Hlopko <hlopkmar@fel.cvut.cz> |
|
20 |
||
21 |
[instance variables:] |
|
22 |
isResolved - flag telling whether instance is resolved |
|
23 |
valueCache - field holding resolved object |
|
24 |
owner - java class owning constant pool |
|
25 |
[class variables:] |
|
26 |
||
27 |
[see also:] |
|
28 |
||
29 |
" |
|
30 |
! ! |
|
752 | 31 |
|
32 |
!JavaRef2 class methodsFor:'instance creation'! |
|
33 |
||
34 |
new |
|
758 | 35 |
"Don't call me directly" |
36 |
||
761 | 37 |
'[JavaRef] Dont instantiate me with new. Call my custom overriden object creation method' |
38 |
infoPrintCR. |
|
39 |
^ self basicNew initialize. |
|
752 | 40 |
|
761 | 41 |
"Modified: / 11-04-2011 / 19:44:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 42 |
! ! |
43 |
||
44 |
!JavaRef2 methodsFor:'accessing'! |
|
45 |
||
774 | 46 |
constantPool |
47 |
^constantPool. |
|
48 |
||
49 |
"Created: / 10-05-2011 / 17:16:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
50 |
! |
|
51 |
||
52 |
constantPool: aJavaConstantPool |
|
53 |
constantPool := aJavaConstantPool. |
|
54 |
||
55 |
"Created: / 10-05-2011 / 17:16:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
56 |
! |
|
57 |
||
752 | 58 |
isResolved |
758 | 59 |
^ valueCache isNil not. |
752 | 60 |
|
61 |
"Created: / 08-04-2011 / 11:36:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
758 | 62 |
"Modified: / 08-04-2011 / 17:39:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
63 |
! |
|
64 |
||
65 |
name |
|
66 |
^ self subclassResponsibility. |
|
67 |
||
68 |
"Created: / 08-04-2011 / 13:53:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
69 |
! |
|
70 |
||
774 | 71 |
owner |
777 | 72 |
^ constantPool owner. |
73 |
||
74 |
"Modified: / 12-05-2011 / 18:31:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
774 | 75 |
! |
76 |
||
777 | 77 |
owner: javaClass |
78 |
constantPool owner: javaClass. |
|
79 |
||
80 |
"Modified: / 12-05-2011 / 18:32:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
774 | 81 |
! |
82 |
||
752 | 83 |
valueCache |
84 |
^ valueCache. |
|
85 |
||
86 |
"Created: / 08-04-2011 / 11:37:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
87 |
! ! |
|
88 |
||
781
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
777
diff
changeset
|
89 |
!JavaRef2 methodsFor:'backward compatibility'! |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
777
diff
changeset
|
90 |
|
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
777
diff
changeset
|
91 |
preResolve |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
777
diff
changeset
|
92 |
"does nothing and will be deleted as soon as transition to new resolving is finished" |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
777
diff
changeset
|
93 |
|
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
777
diff
changeset
|
94 |
"Created: / 13-05-2011 / 17:26:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
777
diff
changeset
|
95 |
! ! |
d27c59bcf38a
added preResolve compatibility method + JavaStringRef - will be used soon
hlopkmar
parents:
777
diff
changeset
|
96 |
|
752 | 97 |
!JavaRef2 methodsFor:'comparing'! |
98 |
||
99 |
= anotherJavaRef |
|
100 |
^ self subclassResponsibility. |
|
101 |
||
102 |
"Created: / 08-04-2011 / 12:15:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
103 |
! |
|
104 |
||
105 |
hash |
|
106 |
||
107 |
^ self subclassResponsibility. |
|
108 |
||
109 |
"Created: / 08-04-2011 / 12:15:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
110 |
! ! |
|
111 |
||
112 |
!JavaRef2 methodsFor:'initialization'! |
|
113 |
||
114 |
initialize |
|
115 |
valueCache := nil. |
|
116 |
super initialize. |
|
117 |
||
758 | 118 |
"Modified: / 08-04-2011 / 17:39:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 119 |
! ! |
120 |
||
774 | 121 |
!JavaRef2 methodsFor:'logging'! |
122 |
||
123 |
info: arg |
|
124 |
Transcript show: arg printString. |
|
125 |
||
126 |
"Created: / 10-05-2011 / 16:50:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
127 |
! |
|
128 |
||
129 |
warning: arg |
|
130 |
Transcript show: arg printString. |
|
131 |
||
132 |
"Created: / 10-05-2011 / 15:01:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
133 |
! ! |
|
134 |
||
135 |
!JavaRef2 methodsFor:'private - resolving'! |
|
136 |
||
137 |
findResolvedStaticValue |
|
138 |
"raise an error: must be redefined in concrete subclass(es)" |
|
139 |
||
140 |
^ self subclassResponsibility |
|
141 |
! |
|
142 |
||
143 |
findResolvedValue |
|
144 |
"raise an error: must be redefined in concrete subclass(es)" |
|
145 |
||
146 |
^ self subclassResponsibility |
|
147 |
! ! |
|
148 |
||
758 | 149 |
!JavaRef2 methodsFor:'queries'! |
150 |
||
151 |
isJavaRef |
|
152 |
"return true if object represents reference in java constant pool" |
|
153 |
^ true. |
|
154 |
||
155 |
"Created: / 08-04-2011 / 16:15:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
771 | 156 |
! |
157 |
||
158 |
isNewJavaRef |
|
159 |
"only temporary, to know if ref is old (claus' version) or new (m version)" |
|
160 |
||
161 |
^ true. |
|
162 |
||
163 |
"Created: / 10-05-2011 / 12:20:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
758 | 164 |
! ! |
165 |
||
752 | 166 |
!JavaRef2 methodsFor:'resolving'! |
167 |
||
168 |
invalidate |
|
758 | 169 |
"Invalidate reference. Cache will be cleared and next call to resolve will cause resolving from scratch." |
170 |
||
171 |
valueCache := nil. |
|
752 | 172 |
|
173 |
"Created: / 08-04-2011 / 11:42:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
758 | 174 |
"Modified: / 08-04-2011 / 17:39:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
175 |
! |
|
176 |
||
177 |
invalidateForClass: internalJavaClassName |
|
178 |
"Invalidate (means call invalidate) reference if it has something to do with given class (e.g Class named internalJavaClassName was unloaded). |
|
179 |
Return true, if reference was invalidated." |
|
180 |
||
181 |
^ self subclassResponsibility. |
|
182 |
||
183 |
"Created: / 08-04-2011 / 15:59:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
752 | 184 |
! |
185 |
||
186 |
resolve |
|
187 |
" |
|
188 |
Do it all method - resolves current reference and returns expected element (JavaMethod, JavaField etc.) |
|
189 |
Hides implementation details of the way of dealing with invalidation etc. User should not need to call anything |
|
190 |
else." |
|
191 |
||
192 |
self isResolved ifFalse: [ self findResolvedValue ]. |
|
193 |
^ valueCache. |
|
194 |
||
195 |
"Created: / 08-04-2011 / 11:30:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
761 | 196 |
! |
197 |
||
198 |
resolveStatic |
|
199 |
" |
|
200 |
Do it all method - resolves current reference and returns expected element (JavaMethod, JavaField etc.) |
|
201 |
Hides implementation details of the way of dealing with invalidation etc. User should not need to call anything |
|
202 |
else." |
|
203 |
||
204 |
self isResolved ifFalse: [ self findResolvedStaticValue ]. |
|
205 |
^ valueCache. |
|
206 |
||
207 |
"Created: / 26-04-2011 / 13:19:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
774 | 208 |
! |
209 |
||
210 |
updateClassRefsFrom: oldOwner to: newOwner |
|
777 | 211 |
self owner = oldOwner ifTrue: [ self owner: newOwner. ]. |
774 | 212 |
self info: 'updating class refs from: ' , oldOwner printString , ' to ' |
213 |
, newOwner printString. |
|
214 |
||
215 |
"Created: / 10-05-2011 / 16:50:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
777 | 216 |
"Modified: / 12-05-2011 / 18:31:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 217 |
! ! |
218 |
||
219 |
!JavaRef2 class methodsFor:'documentation'! |
|
220 |
||
221 |
version_SVN |
|
222 |
^ '$Id$' |
|
223 |
! ! |