JavaResolver.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 30 Jan 2013 13:27:16 +0000
branchrefactoring-vmdata
changeset 2008 c348b894fbfe
parent 1989 131b7459fdab
child 2069 75d40b7b986f
permissions -rw-r--r--
Merged ef3da336a6c9 and 6eac81f7f606 (branch development.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
877
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
     1
"
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
     2
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1062
diff changeset
     3
1155
vranyj1
parents: 1152
diff changeset
     4
 New code and modifications done at SWING Research Group [1]:
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1062
diff changeset
     5
877
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
     6
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
     7
                            SWING Research Group, Czech Technical University in Prague
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
     8
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
     9
 This software is furnished under a license and may be used
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    10
 only in accordance with the terms of that license and with the
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    11
 inclusion of the above copyright notice.   This software may not
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    12
 be provided or otherwise made available to, or used by, any
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    13
 other person.  No title to or ownership of the software is
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    14
 hereby transferred.
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    15
1155
vranyj1
parents: 1152
diff changeset
    16
 [1] Code written at SWING Research Group contains a signature
vranyj1
parents: 1152
diff changeset
    17
     of one of the above copright owners. For exact set of such code,
vranyj1
parents: 1152
diff changeset
    18
     see the differences between this version and version stx:libjava
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1062
diff changeset
    19
     as of 1.9.2010
877
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    20
"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    21
"{ Package: 'stx:libjava' }"
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    22
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    23
Object subclass:#JavaResolver
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    24
	instanceVariableNames:'exceptionThrower'
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    25
	classVariableNames:'uniqueInstance'
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    26
	poolDictionaries:''
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    27
	category:'Languages-Java-Reader-Support-new'
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    28
!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    29
877
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    30
!JavaResolver class methodsFor:'documentation'!
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    31
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    32
copyright
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    33
"
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    34
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1062
diff changeset
    35
1155
vranyj1
parents: 1152
diff changeset
    36
 New code and modifications done at SWING Research Group [1]:
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1062
diff changeset
    37
877
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    38
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    39
                            SWING Research Group, Czech Technical University in Prague
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    40
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    41
 This software is furnished under a license and may be used
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    42
 only in accordance with the terms of that license and with the
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    43
 inclusion of the above copyright notice.   This software may not
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    44
 be provided or otherwise made available to, or used by, any
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    45
 other person.  No title to or ownership of the software is
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    46
 hereby transferred.
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    47
1155
vranyj1
parents: 1152
diff changeset
    48
 [1] Code written at SWING Research Group contains a signature
vranyj1
parents: 1152
diff changeset
    49
     of one of the above copright owners. For exact set of such code,
vranyj1
parents: 1152
diff changeset
    50
     see the differences between this version and version stx:libjava
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1062
diff changeset
    51
     as of 1.9.2010
877
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    52
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    53
"
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    54
! !
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    55
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    56
!JavaResolver class methodsFor:'initialization'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    57
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    58
initialize
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    59
    uniqueInstance := JavaResolver new.
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    60
    uniqueInstance exceptionThrower: JavaVM.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    61
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    62
    "/has methods at: and at: put: 
759
66d28d2fa62e JavaResolver: fixed bug in JavaResolver class>>#initialize
vranyj1
parents: 758
diff changeset
    63
    "/uniqueInstance resolvedClasses: Java.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    64
759
66d28d2fa62e JavaResolver: fixed bug in JavaResolver class>>#initialize
vranyj1
parents: 758
diff changeset
    65
    "Modified: / 10-04-2011 / 10:23:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    66
    "Modified: / 13-04-2011 / 14:07:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    67
! !
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    68
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    69
!JavaResolver class methodsFor:'instance creation'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    70
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    71
uniqueInstance
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    72
    ^uniqueInstance.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    73
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    74
    "Created: / 08-04-2011 / 17:36:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    75
    "Modified: / 11-04-2011 / 19:06:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    76
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    77
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    78
!JavaResolver methodsFor:'accessing'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    79
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    80
exceptionThrower
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    81
    ^ exceptionThrower
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    82
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    83
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    84
exceptionThrower:something
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    85
    exceptionThrower := something.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    86
! !
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    87
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    88
!JavaResolver methodsFor:'class resolving'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    89
817
3f2405c6ef88 its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents: 816
diff changeset
    90
checkIfPrimitiveArrayRef: aJavaClassRef andWrap: result 
3f2405c6ef88 its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents: 816
diff changeset
    91
3f2405c6ef88 its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents: 816
diff changeset
    92
    ^ (JavaDescriptor readFromString: aJavaClassRef name) javaClass.
3f2405c6ef88 its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents: 816
diff changeset
    93
3f2405c6ef88 its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents: 816
diff changeset
    94
    "Created: / 23-05-2011 / 21:12:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
3f2405c6ef88 its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents: 816
diff changeset
    95
!
3f2405c6ef88 its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents: 816
diff changeset
    96
912
e651488f5741 Many fixes in reflection, expecially for generic types support
vranyj1
parents: 908
diff changeset
    97
resolveClassIndentifiedByRef: aJavaClassRef init: doInit 
1014
c8007906749d marcel back in service :)
hlopkmar
parents: 992
diff changeset
    98
    "marcel is back working harder then ever :)"
1225
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
    99
    
992
6d3e3d937fda Class loader mess cleanup, more will come later...
vranyj1
parents: 960
diff changeset
   100
    | result |
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   101
    self validateClassRef: aJavaClassRef.
1225
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   102
    JavaClassReader classLoaderQuerySignal answer: (aJavaClassRef classLoader)
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   103
        do: [
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   104
            result := self lookupClassIfAlreadyResolved: aJavaClassRef javaClassName.
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   105
            
1041
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   106
"/        result notNil ifTrue:[ 
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   107
"/            "/wrap result with array(s) if needed and return it
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   108
"/            "/FIXME: Marcel, can you have a look? Is that correct?
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   109
"/            ^self checkIfArrayRef: aJavaClassRef andWrap: result.
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   110
"/        ].
1225
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   111
        ].
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   112
     "
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   113
     To resolve an unresolved symbolic reference from D to a class or interface C denoted by N,
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   114
     the following steps are performed:
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   115
     The defining class loader of D is used to create a class or interface denoted by N.
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   116
     This class or interface is C. Any exception that can be thrown as a result of failure
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   117
     of class or interface creation can thus be thrown as a result of failure of class and
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   118
     interface resolution. The details of the process are given in Section 5.3.
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   119
    "
1225
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   120
    result isNil ifTrue: [
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   121
        JavaClassReader classLoaderQuerySignal answer: (aJavaClassRef classLoader)
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   122
            do: [
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   123
                "#loadUnresolvedClass: wraps the class!!!!!!"
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   124
                result := self loadUnresolvedClass: aJavaClassRef.
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   125
                ((aJavaClassRef name first == $[) and: [ result isJavaArrayClass not ]) ifTrue: [
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   126
                    self breakPoint: #jv.
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   127
                ]
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   128
            ].
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   129
    ] ifFalse: [ result := self checkIfArrayRef: aJavaClassRef andWrap: result. ].
1225
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   130
    result isNil ifTrue: [ self breakPoint: #mh ].
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   131
    result isJavaPrimitiveType ifTrue: [
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   132
        ^ self checkIfPrimitiveArrayRef: aJavaClassRef andWrap: result
883
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   133
    ].
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   134
    (doInit and: [ result isJavaClass and: [ result isJavaArrayClass not ] ]) ifTrue: [
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   135
        result classInit
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   136
    ].
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   137
     "
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   138
     If C is an array class and its element type is a reference type, then the symbolic reference
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   139
     to the class or interface representing the element type is resolved by invoking the algorithm
1225
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   140
     in Section 5.4.3.1 recursively.""Finally, access permissions to C are checked:
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   141
     If C is not accessible (5.4.4) to D, class or interface resolution throws an IllegalAccessError.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   142
     This condition can occur, for example, if C is a class that was originally declared to be
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   143
     public but was changed to be non-public after D was compiled.
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   144
     
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   145
     If steps 1 and 2 succeed but step 3 fails, C is still valid and usable. Nevertheless, resolution
1989
131b7459fdab Value of class.path and sun.misc.boot.path refactored to match values used in Oracle JVM.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1864
diff changeset
   146
     fails, and D is prohibited from accessing C." 
131b7459fdab Value of class.path and sun.misc.boot.path refactored to match values used in Oracle JVM.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1864
diff changeset
   147
131b7459fdab Value of class.path and sun.misc.boot.path refactored to match values used in Oracle JVM.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1864
diff changeset
   148
    (self checkPermissionsFrom: aJavaClassRef owner to: result) ifFalse: [
131b7459fdab Value of class.path and sun.misc.boot.path refactored to match values used in Oracle JVM.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1864
diff changeset
   149
        self throwIllegalAccessError. 
131b7459fdab Value of class.path and sun.misc.boot.path refactored to match values used in Oracle JVM.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1864
diff changeset
   150
        ^nil.
131b7459fdab Value of class.path and sun.misc.boot.path refactored to match values used in Oracle JVM.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1864
diff changeset
   151
    ].
131b7459fdab Value of class.path and sun.misc.boot.path refactored to match values used in Oracle JVM.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1864
diff changeset
   152
    ^result
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   153
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   154
    "Created: / 11-04-2011 / 19:07:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
912
e651488f5741 Many fixes in reflection, expecially for generic types support
vranyj1
parents: 908
diff changeset
   155
    "Created: / 12-08-2011 / 22:19:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1014
c8007906749d marcel back in service :)
hlopkmar
parents: 992
diff changeset
   156
    "Modified (comment): / 03-10-2011 / 23:03:01 / m"
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   157
    "Modified: / 01-12-2012 / 13:44:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1989
131b7459fdab Value of class.path and sun.misc.boot.path refactored to match values used in Oracle JVM.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1864
diff changeset
   158
    "Modified: / 23-01-2013 / 15:29:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   159
! !
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   160
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   161
!JavaResolver methodsFor:'class resolving helpers'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   162
1041
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   163
checkIfArrayRef: aJavaClassRef andWrap: nonArrayClass 
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   164
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   165
    "/wrap result with array(s) if needed and return it
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   166
    | class|    
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   167
    class := nonArrayClass.
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   168
    aJavaClassRef name do:[:c|
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   169
        c ~~ $[ ifTrue:[ ^ class ].
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   170
        class := class javaArrayClass.
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   171
    ].
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   172
    ^class
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   173
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   174
    "Modified: / 11-04-2011 / 19:31:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1041
d5ff8885b19f ClassLoader refactoring - loads groovy but funny
vranyj1
parents: 1036
diff changeset
   175
    "Modified: / 23-10-2011 / 23:46:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   176
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   177
1843
eff50e345dff enabling permission checking for everybody.. expect some code to start crashing
hlopkmar
parents: 1831
diff changeset
   178
checkPermissionsFrom: refOwner to: resolvedClass    
1830
ef4a91a5d32c MagicAccessorImpl has his magic now (permissions not checked for subclasses)
hlopkmar
parents: 1829
diff changeset
   179
    refOwner hasMagicAccessRights ifTrue: [ ^ true ].
1275
8cad19554d21 fixes to make tomcat work for mh
hlopkmar
parents: 1238
diff changeset
   180
    (JavaDescriptor isJavaPrimitiveArrayName: resolvedClass javaName) ifTrue: [
8cad19554d21 fixes to make tomcat work for mh
hlopkmar
parents: 1238
diff changeset
   181
        ^ true
8cad19554d21 fixes to make tomcat work for mh
hlopkmar
parents: 1238
diff changeset
   182
    ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   183
    resolvedClass isPublic ifTrue: [ ^ true ].
1225
30600ca8173c ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents: 1224
diff changeset
   184
    resolvedClass classLoader = refOwner classLoader ifFalse: [ ^ false. ].
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   185
    refOwner javaPackage = resolvedClass javaPackage ifTrue: [ ^ true ].
1224
b8a0cc35baaa permission testing enabled again, groovy works => we are awesome
hlopkmar
parents: 1155
diff changeset
   186
    
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   187
    "/a little bit too verbose here just so it's clear what's in query
1224
b8a0cc35baaa permission testing enabled again, groovy works => we are awesome
hlopkmar
parents: 1155
diff changeset
   188
    
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   189
    JavaVM privilegedAccessQuery query ifTrue: [ ^ true ] ifFalse: [ ^ false ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   190
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   191
    "Created: / 11-04-2011 / 19:35:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   192
    "Modified (comment): / 09-10-2011 / 23:11:54 / Marcel Hlopko <hlopik@gmail.com>"
1674
f7e00de5caae commented out permission checking even for mh :)
hlopkmar
parents: 1649
diff changeset
   193
    "Modified: / 23-08-2012 / 20:21:40 / m"
1843
eff50e345dff enabling permission checking for everybody.. expect some code to start crashing
hlopkmar
parents: 1831
diff changeset
   194
    "Modified: / 30-11-2012 / 20:34:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   195
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   196
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   197
loadUnresolvedClass: aJavaClassRef 
1393
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   198
    | nm cls i |
812
62e917825364 - JavaDescriptor, JavaResolver, JavaArray: fixes for primitive and array types
vranyj1
parents: 809
diff changeset
   199
1026
5badd1d31864 introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents: 1021
diff changeset
   200
    nm := aJavaClassRef name.
1393
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   201
    nm size == 1 ifTrue:[ 
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   202
        JavaDescriptor baseTypes at: nm first ifPresent: [:cls | ^ cls ] 
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   203
    ].
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   204
    "Note, that JavaVM>>classForName: itself deals with class loaders.
992
6d3e3d937fda Class loader mess cleanup, more will come later...
vranyj1
parents: 960
diff changeset
   205
     The caller of me should set one using code like:
1026
5badd1d31864 introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents: 1021
diff changeset
   206
     
1393
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   207
     JavaClassReader classLoaderQuerySignal answer: loader do:[call me]     
992
6d3e3d937fda Class loader mess cleanup, more will come later...
vranyj1
parents: 960
diff changeset
   208
    "
1393
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   209
    cls := JavaVM classForName: nm.
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   210
    (nm startsWith:$[) ifTrue:[
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   211
        i := 1.
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   212
        [ (nm at:i) == $[ ] whileTrue:[
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   213
            cls := cls javaArrayClass.
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   214
            i := i + 1.                                        
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   215
        ].
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   216
        self assert: (nm at:i) == $L.
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   217
    ].
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   218
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   219
    ^cls.
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   220
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   221
    "Created: / 11-04-2011 / 19:27:10 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
817
3f2405c6ef88 its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents: 816
diff changeset
   222
    "Modified: / 23-05-2011 / 21:06:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1393
dc859d4870f1 Fixes in resolving + preresolver
vranyj1
parents: 1392
diff changeset
   223
    "Modified: / 29-02-2012 / 09:20:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   224
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   225
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   226
lookupClassIfAlreadyResolved: javaClassName 
1036
4ff03464c3b3 refactored registry..
hlopkmar
parents: 1035
diff changeset
   227
    ^ JavaVM classNamed: javaClassName
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   228
883
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   229
    "Modified: / 06-08-2011 / 16:44:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1036
4ff03464c3b3 refactored registry..
hlopkmar
parents: 1035
diff changeset
   230
    "Modified: / 21-10-2011 / 13:40:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   231
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   232
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   233
validateClassRef: aJavaClassRef 
817
3f2405c6ef88 its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents: 816
diff changeset
   234
    self assert: aJavaClassRef isJavaRef.
3f2405c6ef88 its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents: 816
diff changeset
   235
    self assert: aJavaClassRef isJavaClassRef .
3f2405c6ef88 its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents: 816
diff changeset
   236
3f2405c6ef88 its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents: 816
diff changeset
   237
    "Modified: / 23-05-2011 / 21:04:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   238
! !
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   239
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   240
!JavaResolver methodsFor:'common helpers'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   241
796
9b3e00dd3196 Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents: 784
diff changeset
   242
checkPermissionsForMethodOrField: aJavaMethodOrField from: accessingJavaClass to: resolvedJavaClass 
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   243
    "A class or interface C is accessible to a class or interface D if 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   244
     and only if either of the following conditions are true:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   245
     C is public.
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   246
     C and D are members of the same runtime package (§5.3).
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   247
     A field or method R is accessible to a class or interface D if and only
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   248
     if any of the following conditions is true:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   249
     R is public.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   250
     R is protected and is declared in a class C, and D is either a subclass
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   251
     of C or C itself.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   252
     R is either protected or package private (that is, neither public nor
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   253
     protected nor private), and is declared by a class in the same runtime
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   254
     package as D.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   255
     R is private and is declared in D.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   256
     This discussion of access control omits a related restriction on the target
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   257
     of a protected field access or method invocation (the target must be of class
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   258
     D or a subtype of D). That requirement is checked as part of the verification
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   259
     process (§5.4.1); it is not part of link-time access control."
1831
40e9cfb269d4 magic accessor enabled for fields and methods as well..
hlopkmar
parents: 1830
diff changeset
   260
40e9cfb269d4 magic accessor enabled for fields and methods as well..
hlopkmar
parents: 1830
diff changeset
   261
    accessingJavaClass hasMagicAccessRights ifTrue: [ ^true ].
40e9cfb269d4 magic accessor enabled for fields and methods as well..
hlopkmar
parents: 1830
diff changeset
   262
846
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   263
    (self checkPermissionsFrom: accessingJavaClass to: resolvedJavaClass) ifFalse: [
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   264
        JavaVM privilegedAccessQuery query ifTrue: [ ^ true ].
846
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   265
        ^ false
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   266
    ].
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   267
    aJavaMethodOrField isPublic ifTrue: [ ^ true ].
846
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   268
    ((aJavaMethodOrField isProtected 
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   269
        and: [
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   270
            resolvedJavaClass javaComponentClass 
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   271
                equalsOrIsSubclassOf: aJavaMethodOrField javaClass
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   272
        ]) 
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   273
            and: [
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   274
                accessingJavaClass javaComponentClass 
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   275
                    equalsOrIsSubclassOf: aJavaMethodOrField javaClass
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   276
            ]) 
821
560f60ad3a2a fixed (hopefully:) bug in permissions (new resolving)
hlopkmar
parents: 819
diff changeset
   277
            ifTrue: [ ^ true ].
796
9b3e00dd3196 Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents: 784
diff changeset
   278
    ((aJavaMethodOrField isPrivate not 
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   279
        and: [ resolvedJavaClass javaPackage = accessingJavaClass javaPackage ]) 
1831
40e9cfb269d4 magic accessor enabled for fields and methods as well..
hlopkmar
parents: 1830
diff changeset
   280
            and: [ resolvedJavaClass classLoader = accessingJavaClass classLoader ]) 
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   281
            ifTrue: [ ^ true ].
796
9b3e00dd3196 Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents: 784
diff changeset
   282
    (aJavaMethodOrField isPrivate 
846
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   283
        and: [ aJavaMethodOrField javaClass name = accessingJavaClass name ]) 
821
560f60ad3a2a fixed (hopefully:) bug in permissions (new resolving)
hlopkmar
parents: 819
diff changeset
   284
            ifTrue: [ ^ true ].
1224
b8a0cc35baaa permission testing enabled again, groovy works => we are awesome
hlopkmar
parents: 1155
diff changeset
   285
    
b8a0cc35baaa permission testing enabled again, groovy works => we are awesome
hlopkmar
parents: 1155
diff changeset
   286
    "/a little bit too verbose here just so it's clear what's in query
b8a0cc35baaa permission testing enabled again, groovy works => we are awesome
hlopkmar
parents: 1155
diff changeset
   287
    
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   288
    JavaVM privilegedAccessQuery query ifTrue: [ ^ true ] ifFalse: [ ^ false ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   289
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   290
    "Created: / 14-04-2011 / 14:19:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   291
    "Modified (comment): / 09-10-2011 / 23:12:48 / Marcel Hlopko <hlopik@gmail.com>"
1831
40e9cfb269d4 magic accessor enabled for fields and methods as well..
hlopkmar
parents: 1830
diff changeset
   292
    "Modified: / 18-11-2012 / 16:24:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   293
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   294
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   295
!JavaResolver methodsFor:'exceptions'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   296
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   297
throwAbstractMethodError
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   298
    exceptionThrower throwAbstractMethodError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   299
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   300
    "Created: / 11-04-2011 / 20:19:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   301
    "Modified: / 13-04-2011 / 14:07:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   302
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   303
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   304
throwIllegalAccessError
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   305
    exceptionThrower throwIllegalAccessError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   306
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   307
    "Created: / 11-04-2011 / 19:39:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   308
    "Modified: / 13-04-2011 / 23:06:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   309
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   310
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   311
throwIncompatibleClassChangeError
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   312
    exceptionThrower throwIncompatibleClassChangeError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   313
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   314
    "Created: / 11-04-2011 / 20:02:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   315
    "Modified: / 13-04-2011 / 14:07:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   316
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   317
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   318
throwNoSuchFieldException
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   319
    exceptionThrower throwNoSuchFieldException.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   320
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   321
    "Created: / 11-04-2011 / 21:35:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   322
    "Modified: / 13-04-2011 / 14:07:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   323
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   324
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   325
throwNoSuchMethodError
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   326
    exceptionThrower throwNoSuchMethodError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   327
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   328
    "Created: / 11-04-2011 / 20:19:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   329
    "Modified: / 13-04-2011 / 14:08:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   330
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   331
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   332
!JavaResolver methodsFor:'field resolving'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   333
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   334
resolveFieldIndentifiedByRef: aJavaFieldRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   335
    | result  class |
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   336
    self validateFieldRef: aJavaFieldRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   337
    result := self lookupFieldIfAlreadyResolved: aJavaFieldRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   338
    result ifNotNil: [ ^ result ].
1392
b8cd2c9cf1ef Fixes for eager resolving
vranyj1
parents: 1368
diff changeset
   339
    class := aJavaFieldRef classRef resolve: false.
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   340
    class ifNil: [ self error: 'should not happen - tell mh' ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   341
    result := class lookupFieldByNameAndType: aJavaFieldRef nameAndType.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   342
    result ifNil: [ self throwNoSuchFieldException ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   343
    (self 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   344
        checkPermissionsForField: result
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   345
        from: aJavaFieldRef classRef owner
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   346
        to: class) ifFalse: [ self throwIllegalAccessError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   347
    ^ result.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   348
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   349
    "
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   350
     To resolve an unresolved symbolic reference from D to a field in a class
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   351
     or interface C, the symbolic reference to C given by the field reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   352
     must first be resolved (§5.4.3.1). Therefore, any exception that can be
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   353
     thrown as a result of failure of resolution of a class or interface reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   354
     can be thrown as a result of failure of field resolution. If the reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   355
     to C can be successfully resolved, an exception relating to the failure of
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   356
     resolution of the field reference itself can be thrown.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   357
     When resolving a field reference, field resolution first attempts to look
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   358
     up the referenced field in C and its superclasses:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   359
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   360
     If C declares a field with the name and descriptor specified by the field
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   361
     reference, field lookup succeeds. The declared field is the result of the
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   362
     field lookup.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   363
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   364
     Otherwise, field lookup is applied recursively to the direct superinterfaces
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   365
     of the specified class or interface C.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   366
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   367
     Otherwise, if C has a superclass S, field lookup is applied recursively to S.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   368
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   369
     Otherwise, field lookup fails.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   370
     If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise,
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   371
     if field lookup succeeds but the referenced field is not accessible (§5.4.4)
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   372
     to D, field resolution throws an IllegalAccessError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   373
     Otherwise, let <E, L1> be the class or interface in which the referenced
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   374
     field is actually declared and let L2 be the defining loader of D. Let T be
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   375
     the name of the type of the referenced field. The Java virtual machine must
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   376
     impose the loading constraint that TL1=TL2(§5.3.4)."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   377
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   378
    "Created: / 11-04-2011 / 21:15:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   379
    "Modified: / 01-12-2012 / 13:45:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   380
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   381
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   382
resolveStaticFieldIndentifiedByRef: aJavaFieldRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   383
    | result  class |
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   384
    self validateFieldRef: aJavaFieldRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   385
    result := self lookupFieldIfAlreadyResolved: aJavaFieldRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   386
    result ifNotNil: [ ^ result ].
1392
b8cd2c9cf1ef Fixes for eager resolving
vranyj1
parents: 1368
diff changeset
   387
    class := aJavaFieldRef classRef resolve: false.
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   388
    class ifNil: [ self error: 'should not happen - tell mh' ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   389
    result := class lookupStaticFieldByNameAndType: aJavaFieldRef nameAndType.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   390
    result ifNil: [ self throwNoSuchFieldException ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   391
    (self 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   392
        checkPermissionsForField: result
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   393
        from: aJavaFieldRef classRef owner
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   394
        to: class) ifFalse: [ self throwIllegalAccessError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   395
    ^ result.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   396
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   397
    "
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   398
     To resolve an unresolved symbolic reference from D to a field in a class
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   399
     or interface C, the symbolic reference to C given by the field reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   400
     must first be resolved (§5.4.3.1). Therefore, any exception that can be
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   401
     thrown as a result of failure of resolution of a class or interface reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   402
     can be thrown as a result of failure of field resolution. If the reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   403
     to C can be successfully resolved, an exception relating to the failure of
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   404
     resolution of the field reference itself can be thrown.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   405
     When resolving a field reference, field resolution first attempts to look
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   406
     up the referenced field in C and its superclasses:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   407
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   408
     If C declares a field with the name and descriptor specified by the field
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   409
     reference, field lookup succeeds. The declared field is the result of the
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   410
     field lookup.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   411
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   412
     Otherwise, field lookup is applied recursively to the direct superinterfaces
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   413
     of the specified class or interface C.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   414
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   415
     Otherwise, if C has a superclass S, field lookup is applied recursively to S.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   416
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   417
     Otherwise, field lookup fails.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   418
     If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise,
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   419
     if field lookup succeeds but the referenced field is not accessible (§5.4.4)
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   420
     to D, field resolution throws an IllegalAccessError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   421
     Otherwise, let <E, L1> be the class or interface in which the referenced
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   422
     field is actually declared and let L2 be the defining loader of D. Let T be
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   423
     the name of the type of the referenced field. The Java virtual machine must
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   424
     impose the loading constraint that TL1=TL2(§5.3.4)."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   425
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   426
    "Created: / 28-04-2011 / 22:31:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   427
    "Modified: / 01-12-2012 / 13:45:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   428
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   429
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   430
!JavaResolver methodsFor:'field resolving helpers'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   431
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   432
checkPermissionsForField: aJavaField from: accessingJavaClass to: resolvedJavaClass     
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   433
    ^ self 
1469
7ff01bef4a36 started tests cleanup
hlopkmar
parents: 1393
diff changeset
   434
        checkPermissionsForMethodOrField: aJavaField
7ff01bef4a36 started tests cleanup
hlopkmar
parents: 1393
diff changeset
   435
        from: accessingJavaClass
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   436
        to: resolvedJavaClass.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   437
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   438
    "Created: / 11-04-2011 / 21:46:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   439
    "Modified: / 01-12-2012 / 13:45:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   440
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   441
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   442
lookupFieldIfAlreadyResolved: aJavaFieldRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   443
    ^ nil.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   444
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   445
    "Created: / 11-04-2011 / 21:16:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   446
    "Modified: / 13-04-2011 / 11:57:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   447
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   448
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   449
validateFieldRef: aJavaFieldRef 
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   450
    aJavaFieldRef isJavaRef ifFalse: [ self halt: 'I expected Java Ref' ].
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   451
    aJavaFieldRef isJavaFieldRef ifFalse: [
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   452
        self error: 'I expected Java Field Ref'
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   453
    ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   454
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   455
    "Created: / 11-04-2011 / 21:16:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   456
    "Modified: / 01-12-2012 / 13:46:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   457
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   458
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   459
!JavaResolver methodsFor:'interface method resolving'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   460
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   461
resolveInterfaceMethodIdentifiedByRef: aJavaInterfaceMethodRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   462
    | result  class |
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   463
    self validateInterfaceMethodRef: aJavaInterfaceMethodRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   464
    result := self 
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   465
            lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef.
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   466
    result ifNotNil: [ ^ result ].
1392
b8cd2c9cf1ef Fixes for eager resolving
vranyj1
parents: 1368
diff changeset
   467
    class := aJavaInterfaceMethodRef classRef resolve: false.
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   468
    class ifNil: [ self error: 'should not happen - tell mh' ].
816
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   469
    class isInterface ifFalse: [ self throwIncompatibleClassChangeError ].
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   470
    result := class 
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   471
            lookupMethodByNameAndType: aJavaInterfaceMethodRef nameAndType.
816
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   472
    result ifNil: [ self throwNoSuchMethodError ].
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   473
    (self 
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   474
        checkPermissionsForMethod: result
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   475
        from: aJavaInterfaceMethodRef classRef owner
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   476
        to: class) ifFalse: [ self throwIllegalAccessError ].
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   477
    ^ result.
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   478
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   479
    "
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   480
     To resolve an unresolved symbolic reference from D to an interface method in an
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   481
     interface C, the symbolic reference to C given by the interface method reference is
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   482
     first resolved (§5.4.3.1). Therefore, any exceptions that can be thrown as a result
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   483
     of failure of resolution of an interface reference can be thrown as a result of
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   484
     failure of interface method resolution. If the reference to C can be successfully
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   485
     resolved, exceptions relating to the resolution of the interface method reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   486
     itself can be thrown.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   487
     When resolving an interface method reference:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   488
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   489
     If C is not an interface, interface method resolution throws an IncompatibleClassChangeError."
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   490
    "Otherwise, if the referenced method does not have the same name and descriptor as
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   491
a method in C or in one of the superinterfaces of C, or in class Object, interface
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   492
method resolution throws a NoSuchMethodError.
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   493
Otherwise, let <E, L1> be the interface in which the referenced interface method is
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   494
actually declared and let L2 be the defining loader of D. Let T0 be the name of
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   495
the type returned by the referenced method, and let T1, ..., Tn be the names of the
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   496
argument types of the referenced method. The Java virtual machine must impose the
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   497
loading constraints TiL1 = TiL2 for i = 0 to n (§5.3.4)."
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   498
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   499
    "Modified: / 01-12-2012 / 13:46:09 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   500
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   501
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   502
!JavaResolver methodsFor:'interface method resolving helpers'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   503
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   504
lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   505
    ^  nil.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   506
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   507
    "Created: / 13-04-2011 / 11:53:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   508
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   509
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   510
validateInterfaceMethodRef: aJavaInterfaceMethodRef 
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   511
    aJavaInterfaceMethodRef isJavaRef ifFalse: [
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   512
        self error: 'I expected JavaRef instance as an argument'
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   513
    ].
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   514
    aJavaInterfaceMethodRef isJavaInterfaceMethodRef ifFalse: [
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   515
        self error: 'I expected JavaMethodRef instance as an argument'
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   516
    ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   517
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   518
    "Created: / 13-04-2011 / 11:53:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   519
    "Modified: / 01-12-2012 / 13:46:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   520
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   521
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   522
!JavaResolver methodsFor:'method resolving'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   523
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   524
resolveMethodIndentifiedByRef: aJavaMethodRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   525
    | result  class |
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   526
    self validateMethodRef: aJavaMethodRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   527
    result := self lookupMethodIfAlreadyResolved: aJavaMethodRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   528
    result ifNotNil: [ ^ result ].
1392
b8cd2c9cf1ef Fixes for eager resolving
vranyj1
parents: 1368
diff changeset
   529
    class := aJavaMethodRef classRef resolve: false.
850
160c389771a6 Fixes in resolving methodrefs for array methods
vranyj1
parents: 846
diff changeset
   530
    class ifNil: [ self error: 'should not happen - tell mh' ].
1033
a31de6a4cfa4 refactoringl, moved registry to JavaVM
hlopkmar
parents: 1028
diff changeset
   531
     "Array types responds to all method of class java.lang.Object"
a31de6a4cfa4 refactoringl, moved registry to JavaVM
hlopkmar
parents: 1028
diff changeset
   532
    class isJavaArrayClass ifTrue: [
a31de6a4cfa4 refactoringl, moved registry to JavaVM
hlopkmar
parents: 1028
diff changeset
   533
        class := JavaVM classForName: 'java.lang.Object'.
850
160c389771a6 Fixes in resolving methodrefs for array methods
vranyj1
parents: 846
diff changeset
   534
    ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   535
     "
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   536
     To resolve an unresolved symbolic reference from D to a method in
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   537
     a class C, the symbolic reference to C given by the method reference
1033
a31de6a4cfa4 refactoringl, moved registry to JavaVM
hlopkmar
parents: 1028
diff changeset
   538
     is first resolved (§5.4.3.1). Therefore, any exceptions that can be
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   539
     thrown due to resolution of a class reference can be thrown as a result
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   540
     of method resolution. If the reference to C can be successfully resolved,
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   541
     exceptions relating to the resolution of the method reference itself
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   542
     can be thrown.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   543
     When resolving a method reference:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   544
     
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   545
     Method resolution checks whether C is a class or an interface.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   546
     If C is an interface, method resolution throws an IncompatibleClassChangeError."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   547
    class isInterface ifTrue: [ self throwIncompatibleClassChangeError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   548
     "Method resolution attempts to look up the referenced method in C and its
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   549
     superclasses:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   550
     If C declares a method with the name and descriptor specified by the method
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   551
     reference, method lookup succeeds.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   552
     Otherwise, if C has a superclass, step 2 of method lookup is recursively
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   553
     invoked on the direct superclass of C.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   554
     
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   555
     Otherwise, method lookup attempts to locate the referenced method in any of
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   556
     the superinterfaces of the specified class C.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   557
     If any superinterface of C declares a method with the name and descriptor
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   558
     specified by the method reference, method lookup succeeds.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   559
     Otherwise, method lookup fails.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   560
     If method lookup fails, method resolution throws a NoSuchMethodError. If method
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   561
     lookup succeeds and the method is abstract, but C is not abstract, method resolution
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   562
     throws an AbstractMethodError. Otherwise, if the referenced method is not accessible
1033
a31de6a4cfa4 refactoringl, moved registry to JavaVM
hlopkmar
parents: 1028
diff changeset
   563
     (§5.4.4) to D, method resolution throws an IllegalAccessError."
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   564
    result := class lookupMethodByNameAndType: aJavaMethodRef nameAndType.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   565
    result ifNil: [ self throwNoSuchMethodError ].
1033
a31de6a4cfa4 refactoringl, moved registry to JavaVM
hlopkmar
parents: 1028
diff changeset
   566
    (result isAbstract 
a31de6a4cfa4 refactoringl, moved registry to JavaVM
hlopkmar
parents: 1028
diff changeset
   567
        and: [ result javaClass isInterface not and: [ class isAbstract not ] ]) 
a31de6a4cfa4 refactoringl, moved registry to JavaVM
hlopkmar
parents: 1028
diff changeset
   568
            ifTrue: [ self throwAbstractMethodError ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   569
    (self 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   570
        checkPermissionsForMethod: result
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   571
        from: aJavaMethodRef classRef owner
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   572
        to: class) ifFalse: [ self throwIllegalAccessError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   573
    ^ result.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   574
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   575
    "Otherwise, let <E, L1> be the class or interface in which the referenced method is
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   576
     actually declared and let L2 be the defining loader of D. Let T0 be the name of
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   577
     the type returned by the referenced method, and let T1, ..., Tn be the names of
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   578
     the argument types of the referenced method. The Java virtual machine must impose
1033
a31de6a4cfa4 refactoringl, moved registry to JavaVM
hlopkmar
parents: 1028
diff changeset
   579
     the loading constraints TiL1=TiL2 for i = 0 to n (§5.3.4)."
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   580
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   581
    "Created: / 11-04-2011 / 19:45:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   582
    "Modified: / 14-04-2011 / 00:01:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
905
d03d9e05c581 Temporary commit. method resolving fixed
vranyj1
parents: 883
diff changeset
   583
    "Modified: / 10-08-2011 / 22:44:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   584
    "Modified (format): / 01-12-2012 / 13:46:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   585
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   586
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   587
!JavaResolver methodsFor:'method resolving helpers'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   588
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   589
checkPermissionsForMethod: aJavaMethod from: accessingJavaClass to: resolvedJavaClass    
1469
7ff01bef4a36 started tests cleanup
hlopkmar
parents: 1393
diff changeset
   590
    ^ self 
1353
2968f8acb434 one step closer to eager method resolving
hlopkmar
parents: 1275
diff changeset
   591
        checkPermissionsForMethodOrField: aJavaMethod
2968f8acb434 one step closer to eager method resolving
hlopkmar
parents: 1275
diff changeset
   592
        from: accessingJavaClass
1469
7ff01bef4a36 started tests cleanup
hlopkmar
parents: 1393
diff changeset
   593
        to: resolvedJavaClass.
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   594
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   595
    "Created: / 11-04-2011 / 20:20:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
819
d95b67600835 Static field resolving fixed
vranyj1
parents: 817
diff changeset
   596
    "Modified: / 24-05-2011 / 14:06:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1353
2968f8acb434 one step closer to eager method resolving
hlopkmar
parents: 1275
diff changeset
   597
    "Modified: / 09-02-2012 / 23:15:48 / mh <hlopik@gmail.com>"
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   598
    "Modified: / 01-12-2012 / 13:46:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   599
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   600
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   601
lookupMethodIfAlreadyResolved: aJavaMethodRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   602
    ^ nil.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   603
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   604
    "Created: / 11-04-2011 / 19:50:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   605
    "Modified: / 13-04-2011 / 11:57:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   606
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   607
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   608
validateMethodRef: aJavaMethodRef 
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   609
    aJavaMethodRef isJavaRef ifFalse: [
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   610
        self error: 'I expected JavaRef instance as an argument'
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   611
    ].
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   612
    aJavaMethodRef isJavaMethodRef ifFalse: [
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   613
        self error: 'I expected JavaMethodRef instance as an argument'
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   614
    ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   615
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   616
    "Created: / 11-04-2011 / 19:47:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1846
7819e76e5b48 enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents: 1843
diff changeset
   617
    "Modified: / 01-12-2012 / 13:47:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   618
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   619
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   620
!JavaResolver class methodsFor:'documentation'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   621
1864
60a8dc26c8c6 Updated from HG
vranyj1
parents: 1846
diff changeset
   622
version_HG
60a8dc26c8c6 Updated from HG
vranyj1
parents: 1846
diff changeset
   623
60a8dc26c8c6 Updated from HG
vranyj1
parents: 1846
diff changeset
   624
    ^ '$Changeset: <not expanded> $'
60a8dc26c8c6 Updated from HG
vranyj1
parents: 1846
diff changeset
   625
!
60a8dc26c8c6 Updated from HG
vranyj1
parents: 1846
diff changeset
   626
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   627
version_SVN
1864
60a8dc26c8c6 Updated from HG
vranyj1
parents: 1846
diff changeset
   628
    ^ '§Id§'
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   629
! !
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   630
1989
131b7459fdab Value of class.path and sun.misc.boot.path refactored to match values used in Oracle JVM.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1864
diff changeset
   631
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   632
JavaResolver initialize!