author | Claus Gittinger <cg@exept.de> |
Fri, 01 Nov 2019 13:44:29 +0100 | |
branch | cvs_MAIN |
changeset 3973 | ee0b2d717637 |
parent 3668 | be42ff080cb6 |
permissions | -rw-r--r-- |
749 | 1 |
" |
3324
a58245c0e83a
Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3196
diff
changeset
|
2 |
COPYRIGHT (c) 1996-2015 by Claus Gittinger |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
3 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
4 |
New code and modifications done at SWING Research Group [1]: |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
5 |
|
3324
a58245c0e83a
Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3196
diff
changeset
|
6 |
COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko |
749 | 7 |
SWING Research Group, Czech Technical University in Prague |
8 |
||
9 |
This software is furnished under a license and may be used |
|
10 |
only in accordance with the terms of that license and with the |
|
11 |
inclusion of the above copyright notice. This software may not |
|
12 |
be provided or otherwise made available to, or used by, any |
|
13 |
other person. No title to or ownership of the software is |
|
14 |
hereby transferred. |
|
15 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
16 |
[1] Code written at SWING Research Group contains a signature |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
17 |
of one of the above copright owners. For exact set of such code, |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
18 |
see the differences between this version and version stx:libjava |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
19 |
as of 1.9.2010 |
749 | 20 |
" |
21 |
"{ Package: 'stx:libjava' }" |
|
22 |
||
3668 | 23 |
"{ NameSpace: Smalltalk }" |
24 |
||
749 | 25 |
Object subclass:#JavaResolver |
26 |
instanceVariableNames:'exceptionThrower' |
|
27 |
classVariableNames:'uniqueInstance' |
|
28 |
poolDictionaries:'' |
|
29 |
category:'Languages-Java-Reader-Support-new' |
|
30 |
! |
|
31 |
||
32 |
!JavaResolver class methodsFor:'documentation'! |
|
33 |
||
34 |
copyright |
|
35 |
" |
|
3324
a58245c0e83a
Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3196
diff
changeset
|
36 |
COPYRIGHT (c) 1996-2015 by Claus Gittinger |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
37 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
38 |
New code and modifications done at SWING Research Group [1]: |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
39 |
|
3324
a58245c0e83a
Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3196
diff
changeset
|
40 |
COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko |
749 | 41 |
SWING Research Group, Czech Technical University in Prague |
42 |
||
43 |
This software is furnished under a license and may be used |
|
44 |
only in accordance with the terms of that license and with the |
|
45 |
inclusion of the above copyright notice. This software may not |
|
46 |
be provided or otherwise made available to, or used by, any |
|
47 |
other person. No title to or ownership of the software is |
|
48 |
hereby transferred. |
|
49 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
50 |
[1] Code written at SWING Research Group contains a signature |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
51 |
of one of the above copright owners. For exact set of such code, |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
52 |
see the differences between this version and version stx:libjava |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
53 |
as of 1.9.2010 |
749 | 54 |
|
55 |
" |
|
56 |
! ! |
|
57 |
||
58 |
!JavaResolver class methodsFor:'initialization'! |
|
59 |
||
60 |
initialize |
|
61 |
uniqueInstance := JavaResolver new. |
|
62 |
uniqueInstance exceptionThrower: JavaVM. |
|
63 |
||
64 |
"/has methods at: and at: put: |
|
65 |
"/uniqueInstance resolvedClasses: Java. |
|
66 |
||
67 |
"Modified: / 10-04-2011 / 10:23:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
68 |
"Modified: / 13-04-2011 / 14:07:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
69 |
! ! |
|
70 |
||
71 |
!JavaResolver class methodsFor:'instance creation'! |
|
72 |
||
73 |
uniqueInstance |
|
74 |
^uniqueInstance. |
|
75 |
||
76 |
"Created: / 08-04-2011 / 17:36:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
77 |
"Modified: / 11-04-2011 / 19:06:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
78 |
! ! |
|
79 |
||
80 |
!JavaResolver methodsFor:'accessing'! |
|
81 |
||
82 |
exceptionThrower |
|
83 |
^ exceptionThrower |
|
84 |
! |
|
85 |
||
86 |
exceptionThrower:something |
|
87 |
exceptionThrower := something. |
|
88 |
! ! |
|
89 |
||
90 |
!JavaResolver methodsFor:'class resolving'! |
|
91 |
||
92 |
checkIfPrimitiveArrayRef: aJavaClassRef andWrap: result |
|
93 |
||
94 |
^ (JavaDescriptor readFromString: aJavaClassRef name) javaClass. |
|
95 |
||
96 |
"Created: / 23-05-2011 / 21:12:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
97 |
! |
|
98 |
||
99 |
resolveClassIndentifiedByRef: aJavaClassRef init: doInit |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
100 |
"marcel is back working harder then ever :)" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
101 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
102 |
| result | |
749 | 103 |
self validateClassRef: aJavaClassRef. |
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
104 |
result := self |
2794
cec025d0f359
Oops, fix for resolving.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2732
diff
changeset
|
105 |
lookupClassIfAlreadyResolved: aJavaClassRef javaClassNameOrPrimitiveTypeId |
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
106 |
definedBy: aJavaClassRef classLoader. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
107 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
108 |
"/ result notNil ifTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
109 |
"/ "/wrap result with array(s) if needed and return it |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
110 |
"/ "/FIXME: Marcel, can you have a look? Is that correct? |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
111 |
"/ ^self checkIfArrayRef: aJavaClassRef andWrap: result. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
112 |
"/ ]. |
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
113 |
" |
749 | 114 |
To resolve an unresolved symbolic reference from D to a class or interface C denoted by N, |
115 |
the following steps are performed: |
|
116 |
The defining class loader of D is used to create a class or interface denoted by N. |
|
117 |
This class or interface is C. Any exception that can be thrown as a result of failure |
|
118 |
of class or interface creation can thus be thrown as a result of failure of class and |
|
119 |
interface resolution. The details of the process are given in Section 5.3. |
|
120 |
" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
121 |
result isNil ifTrue: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
122 |
JavaClassReader classLoaderQuerySignal answer: (aJavaClassRef classLoader) |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
123 |
do: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
124 |
"#loadUnresolvedClass: wraps the class!!!!!!" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
125 |
result := self loadUnresolvedClass: aJavaClassRef. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
126 |
((aJavaClassRef name first == $[) and: [ result isJavaArrayClass not ]) ifTrue: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
127 |
self breakPoint: #jv. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
128 |
] |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
129 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
130 |
] ifFalse: [ result := self checkIfArrayRef: aJavaClassRef andWrap: result. ]. |
3668 | 131 |
result isNil ifTrue: [ self breakPoint: #mh. ^ nil ]. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
132 |
result isJavaPrimitiveType ifTrue: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
133 |
^ self checkIfPrimitiveArrayRef: aJavaClassRef andWrap: result |
749 | 134 |
]. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
135 |
(doInit and: [ result isJavaClass and: [ result isJavaArrayClass not ] ]) ifTrue: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
136 |
result classInit |
749 | 137 |
]. |
138 |
" |
|
139 |
If C is an array class and its element type is a reference type, then the symbolic reference |
|
140 |
to the class or interface representing the element type is resolved by invoking the algorithm |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
141 |
in Section 5.4.3.1 recursively.""Finally, access permissions to C are checked: |
749 | 142 |
If C is not accessible (5.4.4) to D, class or interface resolution throws an IllegalAccessError. |
143 |
This condition can occur, for example, if C is a class that was originally declared to be |
|
144 |
public but was changed to be non-public after D was compiled. |
|
145 |
||
146 |
If steps 1 and 2 succeed but step 3 fails, C is still valid and usable. Nevertheless, resolution |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
147 |
fails, and D is prohibited from accessing C." |
749 | 148 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
149 |
(self checkPermissionsFrom: aJavaClassRef owner to: result) ifFalse: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
150 |
self throwIllegalAccessError. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
151 |
^nil. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
152 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
153 |
^result |
749 | 154 |
|
155 |
"Created: / 11-04-2011 / 19:07:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
156 |
"Created: / 12-08-2011 / 22:19:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
157 |
"Modified (comment): / 03-10-2011 / 23:03:01 / m" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
158 |
"Modified: / 01-12-2012 / 13:44:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
2794
cec025d0f359
Oops, fix for resolving.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2732
diff
changeset
|
159 |
"Modified: / 05-10-2013 / 01:05:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 160 |
! ! |
161 |
||
162 |
!JavaResolver methodsFor:'class resolving helpers'! |
|
163 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
164 |
checkIfArrayRef: aJavaClassRef andWrap: nonArrayClass |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
165 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
166 |
"/wrap result with array(s) if needed and return it |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
167 |
| class| |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
168 |
class := nonArrayClass. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
169 |
aJavaClassRef name do:[:c| |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
170 |
c ~~ $[ ifTrue:[ ^ class ]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
171 |
class := class javaArrayClass. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
172 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
173 |
^class |
749 | 174 |
|
175 |
"Modified: / 11-04-2011 / 19:31:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
176 |
"Modified: / 23-10-2011 / 23:46:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 177 |
! |
178 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
179 |
checkPermissionsFrom: refOwner to: resolvedClass |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
180 |
refOwner hasMagicAccessRights ifTrue: [ ^ true ]. |
2942
c39cbf09ea3d
Fixes for Java reflection on Smalltalk classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2908
diff
changeset
|
181 |
resolvedClass isJavaClass ifFalse:[ ^ true ]. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
182 |
(JavaDescriptor isJavaPrimitiveArrayName: resolvedClass javaName) ifTrue: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
183 |
^ true |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
184 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
185 |
resolvedClass isPublic ifTrue: [ ^ true ]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
186 |
resolvedClass classLoader = refOwner classLoader ifFalse: [ ^ false. ]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
187 |
refOwner javaPackage = resolvedClass javaPackage ifTrue: [ ^ true ]. |
749 | 188 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
189 |
"/a little bit too verbose here just so it's clear what's in query |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
190 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
191 |
JavaVM privilegedAccessQuery query ifTrue: [ ^ true ] ifFalse: [ ^ false ]. |
749 | 192 |
|
193 |
"Created: / 11-04-2011 / 19:35:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
194 |
"Modified (comment): / 09-10-2011 / 23:11:54 / Marcel Hlopko <hlopik@gmail.com>" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
195 |
"Modified: / 23-08-2012 / 20:21:40 / m" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
196 |
"Modified: / 30-11-2012 / 20:34:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
2942
c39cbf09ea3d
Fixes for Java reflection on Smalltalk classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2908
diff
changeset
|
197 |
"Modified: / 20-11-2013 / 16:07:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 198 |
! |
199 |
||
200 |
loadUnresolvedClass: aJavaClassRef |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
201 |
| nm cls i | |
749 | 202 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
203 |
nm := aJavaClassRef name. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
204 |
nm size == 1 ifTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
205 |
JavaDescriptor baseTypes at: nm first ifPresent: [:cls | ^ cls ] |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
206 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
207 |
"Note, that JavaVM>>classForName: itself deals with class loaders. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
208 |
The caller of me should set one using code like: |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
209 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
210 |
JavaClassReader classLoaderQuerySignal answer: loader do:[call me] |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
211 |
" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
212 |
cls := JavaVM classForName: nm. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
213 |
(nm startsWith:$[) ifTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
214 |
i := 1. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
215 |
[ (nm at:i) == $[ ] whileTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
216 |
cls := cls javaArrayClass. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
217 |
i := i + 1. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
218 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
219 |
self assert: (nm at:i) == $L. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
220 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
221 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
222 |
^cls. |
749 | 223 |
|
224 |
"Created: / 11-04-2011 / 19:27:10 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
225 |
"Modified: / 23-05-2011 / 21:06:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
226 |
"Modified: / 29-02-2012 / 09:20:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 227 |
! |
228 |
||
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
229 |
lookupClassIfAlreadyResolved: javaClassName definedBy: classLoader |
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
230 |
^ JavaVM classNamed: javaClassName definedBy: classLoader |
749 | 231 |
|
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
232 |
"Created: / 02-05-2013 / 01:20:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 233 |
! |
234 |
||
235 |
validateClassRef: aJavaClassRef |
|
236 |
self assert: aJavaClassRef isJavaRef. |
|
237 |
self assert: aJavaClassRef isJavaClassRef . |
|
238 |
||
239 |
"Modified: / 23-05-2011 / 21:04:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
240 |
! ! |
|
241 |
||
242 |
!JavaResolver methodsFor:'common helpers'! |
|
243 |
||
244 |
checkPermissionsForMethodOrField: aJavaMethodOrField from: accessingJavaClass to: resolvedJavaClass |
|
245 |
"A class or interface C is accessible to a class or interface D if |
|
246 |
and only if either of the following conditions are true: |
|
247 |
C is public. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
248 |
C and D are members of the same runtime package (§5.3). |
749 | 249 |
A field or method R is accessible to a class or interface D if and only |
250 |
if any of the following conditions is true: |
|
251 |
R is public. |
|
252 |
R is protected and is declared in a class C, and D is either a subclass |
|
253 |
of C or C itself. |
|
254 |
R is either protected or package private (that is, neither public nor |
|
255 |
protected nor private), and is declared by a class in the same runtime |
|
256 |
package as D. |
|
257 |
R is private and is declared in D. |
|
258 |
This discussion of access control omits a related restriction on the target |
|
259 |
of a protected field access or method invocation (the target must be of class |
|
260 |
D or a subtype of D). That requirement is checked as part of the verification |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
261 |
process (§5.4.1); it is not part of link-time access control." |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
262 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
263 |
accessingJavaClass hasMagicAccessRights ifTrue: [ ^true ]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
264 |
|
749 | 265 |
(self checkPermissionsFrom: accessingJavaClass to: resolvedJavaClass) ifFalse: [ |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
266 |
JavaVM privilegedAccessQuery query ifTrue: [ ^ true ]. |
749 | 267 |
^ false |
268 |
]. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
269 |
aJavaMethodOrField isPublic ifTrue: [ ^ true ]. |
749 | 270 |
((aJavaMethodOrField isProtected |
271 |
and: [ |
|
272 |
resolvedJavaClass javaComponentClass |
|
273 |
equalsOrIsSubclassOf: aJavaMethodOrField javaClass |
|
274 |
]) |
|
275 |
and: [ |
|
276 |
accessingJavaClass javaComponentClass |
|
277 |
equalsOrIsSubclassOf: aJavaMethodOrField javaClass |
|
278 |
]) |
|
279 |
ifTrue: [ ^ true ]. |
|
2730
272689c14005
Fixed removing of Java classes (issue #40)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2578
diff
changeset
|
280 |
(( |
272689c14005
Fixed removing of Java classes (issue #40)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2578
diff
changeset
|
281 |
aJavaMethodOrField isPrivate not |
749 | 282 |
and: [ resolvedJavaClass javaPackage = accessingJavaClass javaPackage ]) |
283 |
and: [ resolvedJavaClass classLoader = accessingJavaClass classLoader ]) |
|
284 |
ifTrue: [ ^ true ]. |
|
285 |
(aJavaMethodOrField isPrivate |
|
286 |
and: [ aJavaMethodOrField javaClass name = accessingJavaClass name ]) |
|
287 |
ifTrue: [ ^ true ]. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
288 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
289 |
"/a little bit too verbose here just so it's clear what's in query |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
290 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
291 |
JavaVM privilegedAccessQuery query ifTrue: [ ^ true ] ifFalse: [ ^ false ]. |
749 | 292 |
|
293 |
"Created: / 14-04-2011 / 14:19:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
294 |
"Modified (comment): / 09-10-2011 / 23:12:48 / Marcel Hlopko <hlopik@gmail.com>" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
295 |
"Modified: / 18-11-2012 / 16:24:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
2730
272689c14005
Fixed removing of Java classes (issue #40)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2578
diff
changeset
|
296 |
"Modified (format): / 15-09-2013 / 00:09:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 297 |
! ! |
298 |
||
299 |
!JavaResolver methodsFor:'exceptions'! |
|
300 |
||
301 |
throwAbstractMethodError |
|
302 |
exceptionThrower throwAbstractMethodError. |
|
303 |
||
304 |
"Created: / 11-04-2011 / 20:19:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
305 |
"Modified: / 13-04-2011 / 14:07:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
306 |
! |
|
307 |
||
308 |
throwIllegalAccessError |
|
309 |
exceptionThrower throwIllegalAccessError. |
|
310 |
||
311 |
"Created: / 11-04-2011 / 19:39:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
312 |
"Modified: / 13-04-2011 / 23:06:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
313 |
! |
|
314 |
||
315 |
throwIncompatibleClassChangeError |
|
316 |
exceptionThrower throwIncompatibleClassChangeError. |
|
317 |
||
318 |
"Created: / 11-04-2011 / 20:02:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
319 |
"Modified: / 13-04-2011 / 14:07:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
320 |
! |
|
321 |
||
322 |
throwNoSuchFieldException |
|
323 |
exceptionThrower throwNoSuchFieldException. |
|
324 |
||
325 |
"Created: / 11-04-2011 / 21:35:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
326 |
"Modified: / 13-04-2011 / 14:07:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
327 |
! |
|
328 |
||
329 |
throwNoSuchMethodError |
|
330 |
exceptionThrower throwNoSuchMethodError. |
|
331 |
||
332 |
"Created: / 11-04-2011 / 20:19:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
333 |
"Modified: / 13-04-2011 / 14:08:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
334 |
! ! |
|
335 |
||
336 |
!JavaResolver methodsFor:'field resolving'! |
|
337 |
||
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
338 |
resolveFieldIndentifiedByRef:aJavaFieldRef |
749 | 339 |
| result class | |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
340 |
|
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
341 |
self validateFieldRef:aJavaFieldRef. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
342 |
result := self lookupFieldIfAlreadyResolved:aJavaFieldRef. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
343 |
result notNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
344 |
^ result |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
345 |
]. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
346 |
class := aJavaFieldRef classRef resolve:false. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
347 |
class isNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
348 |
self error:'should not happen - tell mh' |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
349 |
]. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
350 |
result := class lookupFieldByNameAndType:aJavaFieldRef nameAndType. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
351 |
result isNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
352 |
self throwNoSuchFieldException |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
353 |
]. |
749 | 354 |
(self |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
355 |
checkPermissionsForField:result |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
356 |
from:aJavaFieldRef classRef owner |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
357 |
to:class) ifFalse:[ self throwIllegalAccessError ]. |
749 | 358 |
^ result. |
359 |
||
360 |
" |
|
361 |
To resolve an unresolved symbolic reference from D to a field in a class |
|
362 |
or interface C, the symbolic reference to C given by the field reference |
|
363 |
must first be resolved (§5.4.3.1). Therefore, any exception that can be |
|
364 |
thrown as a result of failure of resolution of a class or interface reference |
|
365 |
can be thrown as a result of failure of field resolution. If the reference |
|
366 |
to C can be successfully resolved, an exception relating to the failure of |
|
367 |
resolution of the field reference itself can be thrown. |
|
368 |
When resolving a field reference, field resolution first attempts to look |
|
369 |
up the referenced field in C and its superclasses: |
|
370 |
||
371 |
If C declares a field with the name and descriptor specified by the field |
|
372 |
reference, field lookup succeeds. The declared field is the result of the |
|
373 |
field lookup. |
|
374 |
||
375 |
Otherwise, field lookup is applied recursively to the direct superinterfaces |
|
376 |
of the specified class or interface C. |
|
377 |
||
378 |
Otherwise, if C has a superclass S, field lookup is applied recursively to S. |
|
379 |
||
380 |
Otherwise, field lookup fails. |
|
381 |
If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise, |
|
382 |
if field lookup succeeds but the referenced field is not accessible (§5.4.4) |
|
383 |
to D, field resolution throws an IllegalAccessError. |
|
384 |
Otherwise, let <E, L1> be the class or interface in which the referenced |
|
385 |
field is actually declared and let L2 be the defining loader of D. Let T be |
|
386 |
the name of the type of the referenced field. The Java virtual machine must |
|
387 |
impose the loading constraint that TL1=TL2(§5.3.4)." |
|
388 |
||
389 |
"Created: / 11-04-2011 / 21:15:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
390 |
"Modified: / 01-12-2012 / 13:45:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
391 |
"Modified: / 04-08-2014 / 15:52:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 392 |
! |
393 |
||
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
394 |
resolveStaticFieldIndentifiedByRef:aJavaFieldRef |
749 | 395 |
| result class | |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
396 |
|
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
397 |
self validateFieldRef:aJavaFieldRef. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
398 |
result := self lookupFieldIfAlreadyResolved:aJavaFieldRef. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
399 |
result notNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
400 |
^ result |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
401 |
]. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
402 |
class := aJavaFieldRef classRef resolve:false. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
403 |
class isNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
404 |
self error:'should not happen - tell mh' |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
405 |
]. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
406 |
result := class lookupStaticFieldByNameAndType:aJavaFieldRef nameAndType. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
407 |
result isNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
408 |
self throwNoSuchFieldException |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
409 |
]. |
749 | 410 |
(self |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
411 |
checkPermissionsForField:result |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
412 |
from:aJavaFieldRef classRef owner |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
413 |
to:class) ifFalse:[ self throwIllegalAccessError ]. |
749 | 414 |
^ result. |
415 |
||
416 |
" |
|
417 |
To resolve an unresolved symbolic reference from D to a field in a class |
|
418 |
or interface C, the symbolic reference to C given by the field reference |
|
419 |
must first be resolved (§5.4.3.1). Therefore, any exception that can be |
|
420 |
thrown as a result of failure of resolution of a class or interface reference |
|
421 |
can be thrown as a result of failure of field resolution. If the reference |
|
422 |
to C can be successfully resolved, an exception relating to the failure of |
|
423 |
resolution of the field reference itself can be thrown. |
|
424 |
When resolving a field reference, field resolution first attempts to look |
|
425 |
up the referenced field in C and its superclasses: |
|
426 |
||
427 |
If C declares a field with the name and descriptor specified by the field |
|
428 |
reference, field lookup succeeds. The declared field is the result of the |
|
429 |
field lookup. |
|
430 |
||
431 |
Otherwise, field lookup is applied recursively to the direct superinterfaces |
|
432 |
of the specified class or interface C. |
|
433 |
||
434 |
Otherwise, if C has a superclass S, field lookup is applied recursively to S. |
|
435 |
||
436 |
Otherwise, field lookup fails. |
|
437 |
If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise, |
|
438 |
if field lookup succeeds but the referenced field is not accessible (§5.4.4) |
|
439 |
to D, field resolution throws an IllegalAccessError. |
|
440 |
Otherwise, let <E, L1> be the class or interface in which the referenced |
|
441 |
field is actually declared and let L2 be the defining loader of D. Let T be |
|
442 |
the name of the type of the referenced field. The Java virtual machine must |
|
443 |
impose the loading constraint that TL1=TL2(§5.3.4)." |
|
444 |
||
445 |
"Created: / 28-04-2011 / 22:31:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
446 |
"Modified: / 01-12-2012 / 13:45:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
447 |
"Modified: / 04-08-2014 / 15:52:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 448 |
! ! |
449 |
||
450 |
!JavaResolver methodsFor:'field resolving helpers'! |
|
451 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
452 |
checkPermissionsForField: aJavaField from: accessingJavaClass to: resolvedJavaClass |
749 | 453 |
^ self |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
454 |
checkPermissionsForMethodOrField: aJavaField |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
455 |
from: accessingJavaClass |
749 | 456 |
to: resolvedJavaClass. |
457 |
||
458 |
"Created: / 11-04-2011 / 21:46:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
459 |
"Modified: / 01-12-2012 / 13:45:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
749 | 460 |
! |
461 |
||
462 |
lookupFieldIfAlreadyResolved: aJavaFieldRef |
|
463 |
^ nil. |
|
464 |
||
465 |
"Created: / 11-04-2011 / 21:16:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
466 |
"Modified: / 13-04-2011 / 11:57:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
467 |
! |
|
468 |
||
469 |
validateFieldRef: aJavaFieldRef |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
470 |
aJavaFieldRef isJavaRef ifFalse: [ self halt: 'I expected Java Ref' ]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
471 |
aJavaFieldRef isJavaFieldRef ifFalse: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
472 |
self error: 'I expected Java Field Ref' |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
473 |
]. |
749 | 474 |
|
475 |
"Created: / 11-04-2011 / 21:16:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
476 |
"Modified: / 01-12-2012 / 13:46:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
749 | 477 |
! ! |
478 |
||
479 |
!JavaResolver methodsFor:'interface method resolving'! |
|
480 |
||
481 |
resolveInterfaceMethodIdentifiedByRef: aJavaInterfaceMethodRef |
|
482 |
| result class | |
|
483 |
self validateInterfaceMethodRef: aJavaInterfaceMethodRef. |
|
484 |
result := self |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
485 |
lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef. |
2908
064418faa2e3
Another pass over Mauve tests.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2794
diff
changeset
|
486 |
result notNil ifTrue: [ ^ result ]. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
487 |
class := aJavaInterfaceMethodRef classRef resolve: false. |
2908
064418faa2e3
Another pass over Mauve tests.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2794
diff
changeset
|
488 |
class isNil ifTrue: [ self error: 'should not happen - tell mh' ]. |
749 | 489 |
class isInterface ifFalse: [ self throwIncompatibleClassChangeError ]. |
490 |
result := class |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
491 |
lookupMethodByNameAndType: aJavaInterfaceMethodRef nameAndType. |
2908
064418faa2e3
Another pass over Mauve tests.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2794
diff
changeset
|
492 |
result isNil ifTrue: [ self throwNoSuchMethodError ]. |
749 | 493 |
(self |
494 |
checkPermissionsForMethod: result |
|
495 |
from: aJavaInterfaceMethodRef classRef owner |
|
496 |
to: class) ifFalse: [ self throwIllegalAccessError ]. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
497 |
^ result. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
498 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
499 |
" |
749 | 500 |
To resolve an unresolved symbolic reference from D to an interface method in an |
501 |
interface C, the symbolic reference to C given by the interface method reference is |
|
502 |
first resolved (§5.4.3.1). Therefore, any exceptions that can be thrown as a result |
|
503 |
of failure of resolution of an interface reference can be thrown as a result of |
|
504 |
failure of interface method resolution. If the reference to C can be successfully |
|
505 |
resolved, exceptions relating to the resolution of the interface method reference |
|
506 |
itself can be thrown. |
|
507 |
When resolving an interface method reference: |
|
508 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
509 |
If C is not an interface, interface method resolution throws an IncompatibleClassChangeError." |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
510 |
"Otherwise, if the referenced method does not have the same name and descriptor as |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
511 |
a method in C or in one of the superinterfaces of C, or in class Object, interface |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
512 |
method resolution throws a NoSuchMethodError. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
513 |
Otherwise, let <E, L1> be the interface in which the referenced interface method is |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
514 |
actually declared and let L2 be the defining loader of D. Let T0 be the name of |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
515 |
the type returned by the referenced method, and let T1, ..., Tn be the names of the |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
516 |
argument types of the referenced method. The Java virtual machine must impose the |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
517 |
loading constraints TiL1 = TiL2 for i = 0 to n (§5.3.4)." |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
518 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
519 |
"Modified: / 01-12-2012 / 13:46:09 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
2908
064418faa2e3
Another pass over Mauve tests.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2794
diff
changeset
|
520 |
"Modified: / 09-11-2013 / 00:12:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 521 |
! ! |
522 |
||
523 |
!JavaResolver methodsFor:'interface method resolving helpers'! |
|
524 |
||
525 |
lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef |
|
526 |
^ nil. |
|
527 |
||
528 |
"Created: / 13-04-2011 / 11:53:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
529 |
! |
|
530 |
||
531 |
validateInterfaceMethodRef: aJavaInterfaceMethodRef |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
532 |
aJavaInterfaceMethodRef isJavaRef ifFalse: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
533 |
self error: 'I expected JavaRef instance as an argument' |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
534 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
535 |
aJavaInterfaceMethodRef isJavaInterfaceMethodRef ifFalse: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
536 |
self error: 'I expected JavaMethodRef instance as an argument' |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
537 |
]. |
749 | 538 |
|
539 |
"Created: / 13-04-2011 / 11:53:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
540 |
"Modified: / 01-12-2012 / 13:46:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
749 | 541 |
! ! |
542 |
||
543 |
!JavaResolver methodsFor:'method resolving'! |
|
544 |
||
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
545 |
resolveMethodIndentifiedByRef:aJavaMethodRef |
749 | 546 |
| result class | |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
547 |
|
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
548 |
self validateMethodRef:aJavaMethodRef. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
549 |
result := self lookupMethodIfAlreadyResolved:aJavaMethodRef. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
550 |
result notNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
551 |
^ result |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
552 |
]. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
553 |
class := aJavaMethodRef classRef resolve:false. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
554 |
class isNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
555 |
self error:'should not happen - tell mh' |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
556 |
]. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
557 |
"Array types responds to all method of class java.lang.Object" |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
558 |
class isJavaArrayClass ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
559 |
class := JavaVM classForName:'java.lang.Object'. |
749 | 560 |
]. |
561 |
" |
|
562 |
To resolve an unresolved symbolic reference from D to a method in |
|
563 |
a class C, the symbolic reference to C given by the method reference |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
564 |
is first resolved (§5.4.3.1). Therefore, any exceptions that can be |
749 | 565 |
thrown due to resolution of a class reference can be thrown as a result |
566 |
of method resolution. If the reference to C can be successfully resolved, |
|
567 |
exceptions relating to the resolution of the method reference itself |
|
568 |
can be thrown. |
|
569 |
When resolving a method reference: |
|
570 |
||
571 |
Method resolution checks whether C is a class or an interface. |
|
572 |
If C is an interface, method resolution throws an IncompatibleClassChangeError." |
|
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
573 |
class isInterface ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
574 |
self throwIncompatibleClassChangeError |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
575 |
]. |
749 | 576 |
"Method resolution attempts to look up the referenced method in C and its |
577 |
superclasses: |
|
578 |
If C declares a method with the name and descriptor specified by the method |
|
579 |
reference, method lookup succeeds. |
|
580 |
Otherwise, if C has a superclass, step 2 of method lookup is recursively |
|
581 |
invoked on the direct superclass of C. |
|
582 |
||
583 |
Otherwise, method lookup attempts to locate the referenced method in any of |
|
584 |
the superinterfaces of the specified class C. |
|
585 |
If any superinterface of C declares a method with the name and descriptor |
|
586 |
specified by the method reference, method lookup succeeds. |
|
587 |
Otherwise, method lookup fails. |
|
588 |
If method lookup fails, method resolution throws a NoSuchMethodError. If method |
|
589 |
lookup succeeds and the method is abstract, but C is not abstract, method resolution |
|
590 |
throws an AbstractMethodError. Otherwise, if the referenced method is not accessible |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
591 |
(§5.4.4) to D, method resolution throws an IllegalAccessError." |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
592 |
result := class lookupMethodByNameAndType:aJavaMethodRef nameAndType. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
593 |
result isNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
594 |
self throwNoSuchMethodError |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
595 |
]. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
596 |
(result isAbstract |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
597 |
and:[ result javaClass isInterface not and:[ class isAbstract not ] ]) |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
598 |
ifTrue:[ self throwAbstractMethodError ]. |
749 | 599 |
(self |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
600 |
checkPermissionsForMethod:result |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
601 |
from:aJavaMethodRef classRef owner |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
602 |
to:class) ifFalse:[ self throwIllegalAccessError ]. |
749 | 603 |
^ result. |
604 |
||
605 |
"Otherwise, let <E, L1> be the class or interface in which the referenced method is |
|
606 |
actually declared and let L2 be the defining loader of D. Let T0 be the name of |
|
607 |
the type returned by the referenced method, and let T1, ..., Tn be the names of |
|
608 |
the argument types of the referenced method. The Java virtual machine must impose |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
609 |
the loading constraints TiL1=TiL2 for i = 0 to n (§5.3.4)." |
749 | 610 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
611 |
"Created: / 11-04-2011 / 19:45:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
612 |
"Modified: / 14-04-2011 / 00:01:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
613 |
"Modified (format): / 01-12-2012 / 13:46:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
614 |
"Modified: / 04-08-2014 / 15:55:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 615 |
! ! |
616 |
||
617 |
!JavaResolver methodsFor:'method resolving helpers'! |
|
618 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
619 |
checkPermissionsForMethod: aJavaMethod from: accessingJavaClass to: resolvedJavaClass |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
620 |
^ self |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
621 |
checkPermissionsForMethodOrField: aJavaMethod |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
622 |
from: accessingJavaClass |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
623 |
to: resolvedJavaClass. |
749 | 624 |
|
625 |
"Created: / 11-04-2011 / 20:20:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
626 |
"Modified: / 24-05-2011 / 14:06:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
627 |
"Modified: / 09-02-2012 / 23:15:48 / mh <hlopik@gmail.com>" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
628 |
"Modified: / 01-12-2012 / 13:46:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
749 | 629 |
! |
630 |
||
631 |
lookupMethodIfAlreadyResolved: aJavaMethodRef |
|
632 |
^ nil. |
|
633 |
||
634 |
"Created: / 11-04-2011 / 19:50:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
635 |
"Modified: / 13-04-2011 / 11:57:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
636 |
! |
|
637 |
||
638 |
validateMethodRef: aJavaMethodRef |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
639 |
aJavaMethodRef isJavaRef ifFalse: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
640 |
self error: 'I expected JavaRef instance as an argument' |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
641 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
642 |
aJavaMethodRef isJavaMethodRef ifFalse: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
643 |
self error: 'I expected JavaMethodRef instance as an argument' |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
644 |
]. |
749 | 645 |
|
646 |
"Created: / 11-04-2011 / 19:47:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
647 |
"Modified: / 01-12-2012 / 13:47:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
749 | 648 |
! ! |
649 |
||
650 |
!JavaResolver class methodsFor:'documentation'! |
|
651 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
652 |
version_CVS |
3668 | 653 |
^ '$Header$' |
2156
a8c5720d1d05
changed: #resolveMethodIndentifiedByRef:
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
654 |
! |
a8c5720d1d05
changed: #resolveMethodIndentifiedByRef:
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
655 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
656 |
version_HG |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
657 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
658 |
^ '$Changeset: <not expanded> $' |
2156
a8c5720d1d05
changed: #resolveMethodIndentifiedByRef:
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
659 |
! |
a8c5720d1d05
changed: #resolveMethodIndentifiedByRef:
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
660 |
|
749 | 661 |
version_SVN |
3668 | 662 |
^ '$Id$' |
749 | 663 |
! ! |
664 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
665 |
|
2152 | 666 |
JavaResolver initialize! |