src/JavaResolver.st
author hlopkmar
Wed, 19 Oct 2011 16:18:27 +0000
branchjk_new_structure
changeset 1026 5badd1d31864
parent 1021 8ae6c261878a
child 1027 43dc608e14aa
permissions -rw-r--r--
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
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
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
     3
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
     4
                            SWING Research Group, Czech Technical University in Prague
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
     5
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
     6
 Parts of the code written by Claus Gittinger are under following
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
     7
 license:
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
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    16
 Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    17
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    18
 Permission is hereby granted, free of charge, to any person
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    19
 obtaining a copy of this software and associated documentation
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    20
 files (the 'Software'), to deal in the Software without
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    21
 restriction, including without limitation the rights to use,
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    22
 copy, modify, merge, publish, distribute, sublicense, and/or sell
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    23
 copies of the Software, and to permit persons to whom the
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    24
 Software is furnished to do so, subject to the following
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    25
 conditions:
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    26
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    27
 The above copyright notice and this permission notice shall be
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    28
 included in all copies or substantial portions of the Software.
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    29
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    30
 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    31
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    32
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    33
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    34
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    35
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    36
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    37
 OTHER DEALINGS IN THE SOFTWARE.
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    38
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    39
 [1] Code written at SWING Research Group contain a signature
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    40
     of one of the above copright owners.
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    41
"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    42
"{ Package: 'stx:libjava' }"
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    43
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    44
Object subclass:#JavaResolver
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
    45
	instanceVariableNames:'exceptionThrower'
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    46
	classVariableNames:'uniqueInstance'
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    47
	poolDictionaries:''
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    48
	category:'Languages-Java-Reader-Support-new'
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    49
!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    50
877
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    51
!JavaResolver class methodsFor:'documentation'!
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    52
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    53
copyright
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    54
"
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    55
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    56
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    57
                            SWING Research Group, Czech Technical University in Prague
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    58
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    59
 Parts of the code written by Claus Gittinger are under following
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    60
 license:
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    61
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    62
 This software is furnished under a license and may be used
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    63
 only in accordance with the terms of that license and with the
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    64
 inclusion of the above copyright notice.   This software may not
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    65
 be provided or otherwise made available to, or used by, any
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    66
 other person.  No title to or ownership of the software is
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    67
 hereby transferred.
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    68
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    69
 Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    70
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    71
 Permission is hereby granted, free of charge, to any person
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    72
 obtaining a copy of this software and associated documentation
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    73
 files (the 'Software'), to deal in the Software without
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    74
 restriction, including without limitation the rights to use,
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    75
 copy, modify, merge, publish, distribute, sublicense, and/or sell
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    76
 copies of the Software, and to permit persons to whom the
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    77
 Software is furnished to do so, subject to the following
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    78
 conditions:
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    79
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    80
 The above copyright notice and this permission notice shall be
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    81
 included in all copies or substantial portions of the Software.
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    82
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    83
 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    84
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    85
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    86
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    87
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    88
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    89
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    90
 OTHER DEALINGS IN THE SOFTWARE.
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    91
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    92
 [1] Code written at SWING Research Group contain a signature
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    93
     of one of the above copright owners.
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    94
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    95
"
f5a5b93e1c78 Cleanup phase 1
vranyj1
parents: 851
diff changeset
    96
! !
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    97
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    98
!JavaResolver class methodsFor:'initialization'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
    99
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   100
initialize
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   101
    uniqueInstance := JavaResolver new.
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   102
    uniqueInstance exceptionThrower: JavaVM.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   103
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   104
    "/has methods at: and at: put: 
759
66d28d2fa62e JavaResolver: fixed bug in JavaResolver class>>#initialize
vranyj1
parents: 758
diff changeset
   105
    "/uniqueInstance resolvedClasses: Java.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   106
759
66d28d2fa62e JavaResolver: fixed bug in JavaResolver class>>#initialize
vranyj1
parents: 758
diff changeset
   107
    "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
   108
    "Modified: / 13-04-2011 / 14:07:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   109
! !
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   110
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   111
!JavaResolver class methodsFor:'instance creation'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   112
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   113
uniqueInstance
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   114
    ^uniqueInstance.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   115
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   116
    "Created: / 08-04-2011 / 17:36:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   117
    "Modified: / 11-04-2011 / 19:06:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   118
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   119
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   120
!JavaResolver methodsFor:'accessing'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   121
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   122
exceptionThrower
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   123
    ^ exceptionThrower
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   124
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   125
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   126
exceptionThrower:something
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   127
    exceptionThrower := something.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   128
! !
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   129
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   130
!JavaResolver methodsFor:'class resolving'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   131
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
   132
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
   133
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
   134
    ^ (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
   135
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
   136
    "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
   137
!
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
   138
912
e651488f5741 Many fixes in reflection, expecially for generic types support
vranyj1
parents: 908
diff changeset
   139
resolveClassIndentifiedByRef: aJavaClassRef init: doInit 
1014
c8007906749d marcel back in service :)
hlopkmar
parents: 992
diff changeset
   140
c8007906749d marcel back in service :)
hlopkmar
parents: 992
diff changeset
   141
    "marcel is back working harder then ever :)"
c8007906749d marcel back in service :)
hlopkmar
parents: 992
diff changeset
   142
992
6d3e3d937fda Class loader mess cleanup, more will come later...
vranyj1
parents: 960
diff changeset
   143
    | result |
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   144
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   145
    self validateClassRef: aJavaClassRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   146
    result := self lookupClassIfAlreadyResolved: aJavaClassRef javaClassName.
883
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   147
"/    result notNil ifTrue:[ 
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   148
"/        "/wrap result with array(s) if needed and return it
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   149
"/        "/FIXME: Marcel, can you have a look? Is that correct?
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   150
"/        ^self checkIfArrayRef: aJavaClassRef andWrap: result 
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   151
"/    ].
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   152
     "
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   153
     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
   154
     the following steps are performed:
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   155
     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
   156
     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
   157
     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
   158
     interface resolution. The details of the process are given in Section 5.3.
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   159
    "
883
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   160
    result isNil ifTrue:[
992
6d3e3d937fda Class loader mess cleanup, more will come later...
vranyj1
parents: 960
diff changeset
   161
        JavaClassReader classLoaderQuerySignal answer: (aJavaClassRef classLoader) do:[
883
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   162
            result := self loadUnresolvedClass: aJavaClassRef
992
6d3e3d937fda Class loader mess cleanup, more will come later...
vranyj1
parents: 960
diff changeset
   163
        ]            
883
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   164
    ].
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   165
    result ifNil: [ self breakPoint: #mh ].
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   166
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   167
    result isJavaPrimitiveType ifTrue: [ 
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   168
        ^ self checkIfPrimitiveArrayRef: aJavaClassRef andWrap: result 
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   169
    ].
912
e651488f5741 Many fixes in reflection, expecially for generic types support
vranyj1
parents: 908
diff changeset
   170
    doInit ifTrue:[result classInit].
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   171
     "
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   172
     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
   173
     to the class or interface representing the element type is resolved by invoking the algorithm
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   174
     in Section 5.4.3.1 recursively."
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   175
    result := self checkIfArrayRef: aJavaClassRef andWrap: result.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   176
     "Finally, access permissions to C are checked:
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   177
     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
   178
     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
   179
     public but was changed to be non-public after D was compiled.
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   180
     
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   181
     If steps 1 and 2 succeed but step 3 fails, C is still valid and usable. Nevertheless, resolution
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   182
     fails, and D is prohibited from accessing C."
906
fea23aa2b228 Few more fixes and workarounds for Saxon 6.5.5: the Othello example works fine...
vranyj1
parents: 905
diff changeset
   183
fea23aa2b228 Few more fixes and workarounds for Saxon 6.5.5: the Othello example works fine...
vranyj1
parents: 905
diff changeset
   184
fea23aa2b228 Few more fixes and workarounds for Saxon 6.5.5: the Othello example works fine...
vranyj1
parents: 905
diff changeset
   185
     "JV@2011-08-10: HACK FOR SAXON DEMO!!!!!!"
fea23aa2b228 Few more fixes and workarounds for Saxon 6.5.5: the Othello example works fine...
vranyj1
parents: 905
diff changeset
   186
    "(self checkPermissionsFrom: aJavaClassRef owner to: result)"true
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   187
        ifTrue: [ ^ result ]
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   188
        ifFalse: [ self throwIllegalAccessError ].
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   189
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   190
    "Created: / 11-04-2011 / 19:07:19 / 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
   191
    "Modified: / 23-05-2011 / 21:11:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
912
e651488f5741 Many fixes in reflection, expecially for generic types support
vranyj1
parents: 908
diff changeset
   192
    "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
   193
    "Modified (comment): / 03-10-2011 / 23:03:01 / m"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   194
! !
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   195
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   196
!JavaResolver methodsFor:'class resolving helpers'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   197
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   198
checkIfArrayRef: aJavaClassRef andWrap: result 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   199
 "/wrap result with array(s) if needed and return it
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   200
    ^ aJavaClassRef isJavaArrayClassRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   201
        ifFalse: [ result ]
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   202
        ifTrue: [ self wrapJavaClass: result withArrayAsSpecifiedIn: aJavaClassRef ]
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   203
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   204
    "Modified: / 11-04-2011 / 19:31:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   205
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   206
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   207
checkPermissionsFrom: refOwner to: resolvedClass 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   208
    "
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   209
     A class or interface C is accessible to a class or interface D if and only if either of the following conditions are true:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   210
            C is public.
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   211
            C and D are members of the same runtime package (§5.3).
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   212
     Finally, access permissions to C are checked:
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   213
     If C is not accessible (§5.4.4) to D, class or interface resolution throws an IllegalAccessError.
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   214
     This condition can occur, for example, if C is a class that was originally declared to be
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   215
     public but was changed to be non-public after D was compiled.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   216
     At run time, a class or interface is determined not by its name alone,
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   217
     but by a pair: its fully qualified name and its defining class loader.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   218
     Each such class or interface belongs to a single runtime package. The runtime
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   219
     package of a class or interface is determined by the package name and
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   220
     defining class loader of the class or interface."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   221
    
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   222
    resolvedClass isPublic ifTrue: [ ^ true ].
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   223
    resolvedClass classLoader = refOwner classLoader ifFalse: [
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   224
        "we should return false, however I'll return true here since our classloader implementation
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   225
         is not perfect and we know it :) mh"
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   226
        self breakPoint: #knownBug
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   227
    ].
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   228
    refOwner javaPackage = resolvedClass javaPackage ifTrue: [ ^ true ].
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   229
    "/a little bit too verbose here just so it's clear what's in query
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   230
    JavaVM privilegedAccessQuery query ifTrue: [ ^ true ] ifFalse: [ ^ false ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   231
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   232
    "Created: / 11-04-2011 / 19:35:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   233
    "Modified: / 13-04-2011 / 23:13:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   234
    "Modified (format): / 09-10-2011 / 17:27:30 / m"
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   235
    "Modified (comment): / 09-10-2011 / 23:11:54 / Marcel Hlopko <hlopik@gmail.com>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   236
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   237
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   238
loadUnresolvedClass: 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
   239
    | nm |
812
62e917825364 - JavaDescriptor, JavaResolver, JavaArray: fixes for primitive and array types
vranyj1
parents: 809
diff changeset
   240
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
   241
    nm := aJavaClassRef name.
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
   242
    nm size == 1 
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
   243
        and: [ JavaDescriptor baseTypes at: nm first ifPresent: [:cls | ^ cls ] ].
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
   244
     "Note, that loadClass itself deals with class loaders.
992
6d3e3d937fda Class loader mess cleanup, more will come later...
vranyj1
parents: 960
diff changeset
   245
     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
   246
     
5badd1d31864 introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents: 1021
diff changeset
   247
     JavaClassReader classLoaderQuerySignal answer: loader do:[call me]
5badd1d31864 introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents: 1021
diff changeset
   248
     
992
6d3e3d937fda Class loader mess cleanup, more will come later...
vranyj1
parents: 960
diff changeset
   249
    "
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
   250
    ^ Java javaRegistry classForName: nm definedBy: JavaClassReader classLoaderQuerySignal query.
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   251
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   252
    "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
   253
    "Modified: / 23-05-2011 / 21:06:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
992
6d3e3d937fda Class loader mess cleanup, more will come later...
vranyj1
parents: 960
diff changeset
   254
    "Modified: / 08-09-2011 / 08:33:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   255
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   256
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   257
lookupClassIfAlreadyResolved: javaClassName 
882
f41881c0c866 JavaResolver: fixes in #resolveClass...
vranyj1
parents: 877
diff changeset
   258
f41881c0c866 JavaResolver: fixes in #resolveClass...
vranyj1
parents: 877
diff changeset
   259
    ^Java at: javaClassName
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   260
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   261
    "Modified: / 13-04-2011 / 14:05:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
883
b0eecab8d572 - JavaResolver: fixes in class resolving
vranyj1
parents: 882
diff changeset
   262
    "Modified: / 06-08-2011 / 16:44:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   263
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   264
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   265
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
   266
    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
   267
    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
   268
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
   269
    "Modified: / 23-05-2011 / 21:04:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   270
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   271
1021
8ae6c261878a changed class loaders order, loading of primitive arrays, refactoring coming soon..
hlopkmar
parents: 1016
diff changeset
   272
wrapJavaClass: aJavaClass withArrayAsSpecifiedIn: aJavaClassRef 
8ae6c261878a changed class loaders order, loading of primitive arrays, refactoring coming soon..
hlopkmar
parents: 1016
diff changeset
   273
    "wraps aJavaClass with as many array dimensions as needed (zero means no array)"    
8ae6c261878a changed class loaders order, loading of primitive arrays, refactoring coming soon..
hlopkmar
parents: 1016
diff changeset
   274
    ^ JavaClassReader makeArrayOf:aJavaClass withDimensions: aJavaClassRef arrayDimensions.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   275
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   276
    "Created: / 08-04-2011 / 18:40:00 / 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
   277
    "Modified: / 23-05-2011 / 21:06:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
960
1c7fd32d1f26 Few fixes
vranyj1
parents: 957
diff changeset
   278
    "Modified: / 01-09-2011 / 09:25:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   279
! !
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   280
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   281
!JavaResolver methodsFor:'common helpers'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   282
796
9b3e00dd3196 Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents: 784
diff changeset
   283
checkPermissionsForMethodOrField: aJavaMethodOrField from: accessingJavaClass to: resolvedJavaClass 
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   284
    "A class or interface C is accessible to a class or interface D if 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   285
     and only if either of the following conditions are true:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   286
     C is public.
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   287
     C and D are members of the same runtime package (§5.3).
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   288
     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
   289
     if any of the following conditions is true:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   290
     R is public.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   291
     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
   292
     of C or C itself.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   293
     R is either protected or package private (that is, neither public nor
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   294
     protected nor private), and is declared by a class in the same runtime
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   295
     package as D.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   296
     R is private and is declared in D.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   297
     This discussion of access control omits a related restriction on the target
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   298
     of a protected field access or method invocation (the target must be of class
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   299
     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
   300
     process (§5.4.1); it is not part of link-time access control."
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   301
    
846
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   302
    (self checkPermissionsFrom: accessingJavaClass to: resolvedJavaClass) ifFalse: [
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   303
        JavaVM privilegedAccessQuery query ifTrue: [ ^ true ].
846
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   304
        ^ false
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   305
    ].
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   306
    aJavaMethodOrField isPublic ifTrue: [ ^ true ].
846
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   307
    ((aJavaMethodOrField isProtected 
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   308
        and: [
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   309
            resolvedJavaClass javaComponentClass 
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   310
                equalsOrIsSubclassOf: aJavaMethodOrField javaClass
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   311
        ]) 
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   312
            and: [
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   313
                accessingJavaClass javaComponentClass 
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   314
                    equalsOrIsSubclassOf: aJavaMethodOrField javaClass
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   315
            ]) 
821
560f60ad3a2a fixed (hopefully:) bug in permissions (new resolving)
hlopkmar
parents: 819
diff changeset
   316
            ifTrue: [ ^ true ].
796
9b3e00dd3196 Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents: 784
diff changeset
   317
    ((aJavaMethodOrField isPrivate not 
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   318
        and: [ resolvedJavaClass javaPackage = accessingJavaClass javaPackage ]) 
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   319
            and: [
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   320
                "resolvedJavaClass classLoader = accessingJavaClass classLoader"
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   321
                "for explanation check comment in checkPermissionsFrom:to:"
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   322
                self breakPoint: #knownBugs.
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   323
                true
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   324
            ]) 
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   325
            ifTrue: [ ^ true ].
796
9b3e00dd3196 Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents: 784
diff changeset
   326
    (aJavaMethodOrField isPrivate 
846
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   327
        and: [ aJavaMethodOrField javaClass name = accessingJavaClass name ]) 
821
560f60ad3a2a fixed (hopefully:) bug in permissions (new resolving)
hlopkmar
parents: 819
diff changeset
   328
            ifTrue: [ ^ true ].
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   329
            "/a little bit too verbose here just so it's clear what's in query
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   330
    JavaVM privilegedAccessQuery query ifTrue: [ ^ true ] ifFalse: [ ^ false ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   331
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   332
    "Created: / 14-04-2011 / 14:19:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
846
cec92244091c fixed bug in resolving
hlopkmar
parents: 822
diff changeset
   333
    "Modified: / 04-06-2011 / 20:49:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1016
2b20730b8717 work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents: 1014
diff changeset
   334
    "Modified (comment): / 09-10-2011 / 23:12:48 / Marcel Hlopko <hlopik@gmail.com>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   335
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   336
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   337
!JavaResolver methodsFor:'exceptions'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   338
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   339
throwAbstractMethodError
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   340
    exceptionThrower throwAbstractMethodError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   341
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   342
    "Created: / 11-04-2011 / 20:19:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   343
    "Modified: / 13-04-2011 / 14:07:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   344
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   345
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   346
throwIllegalAccessError
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   347
    exceptionThrower throwIllegalAccessError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   348
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   349
    "Created: / 11-04-2011 / 19:39:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   350
    "Modified: / 13-04-2011 / 23:06:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   351
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   352
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   353
throwIncompatibleClassChangeError
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   354
    exceptionThrower throwIncompatibleClassChangeError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   355
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   356
    "Created: / 11-04-2011 / 20:02:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   357
    "Modified: / 13-04-2011 / 14:07:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   358
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   359
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   360
throwNoSuchFieldException
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   361
    exceptionThrower throwNoSuchFieldException.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   362
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   363
    "Created: / 11-04-2011 / 21:35:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   364
    "Modified: / 13-04-2011 / 14:07:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   365
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   366
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   367
throwNoSuchMethodError
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   368
    exceptionThrower throwNoSuchMethodError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   369
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   370
    "Created: / 11-04-2011 / 20:19:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   371
    "Modified: / 13-04-2011 / 14:08:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   372
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   373
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   374
!JavaResolver methodsFor:'field resolving'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   375
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   376
resolveFieldIndentifiedByRef: aJavaFieldRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   377
    | result  class |
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   378
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   379
    self validateFieldRef: aJavaFieldRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   380
    result := self lookupFieldIfAlreadyResolved: aJavaFieldRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   381
    result ifNotNil: [ ^ result ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   382
    class := aJavaFieldRef classRef resolve.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   383
    class ifNil: [ self halt: 'should not happen - tell mh' ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   384
    result := class lookupFieldByNameAndType: aJavaFieldRef nameAndType.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   385
    result ifNil: [ self throwNoSuchFieldException ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   386
    (self 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   387
        checkPermissionsForField: result
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   388
        from: aJavaFieldRef classRef owner
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   389
        to: class) ifFalse: [ self throwIllegalAccessError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   390
    ^ result.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   391
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   392
    "
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   393
     To resolve an unresolved symbolic reference from D to a field in a class
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   394
     or interface C, the symbolic reference to C given by the field reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   395
     must first be resolved (§5.4.3.1). Therefore, any exception that can be
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   396
     thrown as a result of failure of resolution of a class or interface reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   397
     can be thrown as a result of failure of field resolution. If the reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   398
     to C can be successfully resolved, an exception relating to the failure of
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   399
     resolution of the field reference itself can be thrown.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   400
     When resolving a field reference, field resolution first attempts to look
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   401
     up the referenced field in C and its superclasses:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   402
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   403
     If C declares a field with the name and descriptor specified by the field
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   404
     reference, field lookup succeeds. The declared field is the result of the
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   405
     field lookup.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   406
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   407
     Otherwise, field lookup is applied recursively to the direct superinterfaces
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   408
     of the specified class or interface C.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   409
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   410
     Otherwise, if C has a superclass S, field lookup is applied recursively to S.
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 fails.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   413
     If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise,
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   414
     if field lookup succeeds but the referenced field is not accessible (§5.4.4)
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   415
     to D, field resolution throws an IllegalAccessError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   416
     Otherwise, let <E, L1> be the class or interface in which the referenced
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   417
     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
   418
     the name of the type of the referenced field. The Java virtual machine must
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   419
     impose the loading constraint that TL1=TL2(§5.3.4)."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   420
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   421
    "Created: / 11-04-2011 / 21:15:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   422
    "Modified: / 13-04-2011 / 11:57:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   423
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   424
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   425
resolveStaticFieldIndentifiedByRef: aJavaFieldRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   426
    | result  class |
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   427
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   428
    self validateFieldRef: aJavaFieldRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   429
    result := self lookupFieldIfAlreadyResolved: aJavaFieldRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   430
    result ifNotNil: [ ^ result ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   431
    class := aJavaFieldRef classRef resolve.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   432
    class ifNil: [ self halt: 'should not happen - tell mh' ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   433
    result := class lookupStaticFieldByNameAndType: aJavaFieldRef nameAndType.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   434
    result ifNil: [ self throwNoSuchFieldException ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   435
    (self 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   436
        checkPermissionsForField: result
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   437
        from: aJavaFieldRef classRef owner
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   438
        to: class) ifFalse: [ self throwIllegalAccessError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   439
    ^ result.
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
     To resolve an unresolved symbolic reference from D to a field in a class
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   443
     or interface C, the symbolic reference to C given by the field reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   444
     must first be resolved (§5.4.3.1). Therefore, any exception that can be
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   445
     thrown as a result of failure of resolution of a class or interface reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   446
     can be thrown as a result of failure of field resolution. If the reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   447
     to C can be successfully resolved, an exception relating to the failure of
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   448
     resolution of the field reference itself can be thrown.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   449
     When resolving a field reference, field resolution first attempts to look
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   450
     up the referenced field in C and its superclasses:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   451
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   452
     If C declares a field with the name and descriptor specified by the field
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   453
     reference, field lookup succeeds. The declared field is the result of the
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   454
     field lookup.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   455
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   456
     Otherwise, field lookup is applied recursively to the direct superinterfaces
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   457
     of the specified class or interface C.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   458
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   459
     Otherwise, if C has a superclass S, field lookup is applied recursively to S.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   460
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   461
     Otherwise, field lookup fails.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   462
     If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise,
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   463
     if field lookup succeeds but the referenced field is not accessible (§5.4.4)
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   464
     to D, field resolution throws an IllegalAccessError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   465
     Otherwise, let <E, L1> be the class or interface in which the referenced
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   466
     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
   467
     the name of the type of the referenced field. The Java virtual machine must
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   468
     impose the loading constraint that TL1=TL2(§5.3.4)."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   469
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   470
    "Created: / 28-04-2011 / 22:31:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   471
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   472
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   473
!JavaResolver methodsFor:'field resolving helpers'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   474
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   475
checkPermissionsForField: aJavaField from: accessingJavaClass to: resolvedJavaClass 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   476
    "A class or interface C is accessible to a class or interface D if and only 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   477
     if either of the following conditions are true:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   478
     C is public.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   479
     C and D are members of the same runtime package (5.3).
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   480
     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
   481
     if any of the following conditions is true:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   482
     R is public.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   483
     R is protected and is declared in a class C, and D is either a subclass of
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   484
     C or C itself.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   485
     R is either protected or package private (that is, neither public nor protected
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   486
     nor private), and is declared by a class in the same runtime package as D.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   487
     R is private and is declared in D.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   488
     This discussion of access control omits a related restriction on the target of
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   489
     a protected field access or method invocation (the target must be of class D or
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   490
     a subtype of D). That requirement is checked as part of the verification process
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   491
     (5.4.1); it is not part of link-time access control."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   492
    
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   493
    ^ self 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   494
        checkPermissionsForMethodOrField: aJavaField from: accessingJavaClass
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   495
        to: resolvedJavaClass.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   496
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   497
    "Created: / 11-04-2011 / 21:46:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   498
    "Modified: / 14-04-2011 / 14:21:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   499
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   500
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   501
lookupFieldIfAlreadyResolved: aJavaFieldRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   502
    ^ nil.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   503
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   504
    "Created: / 11-04-2011 / 21:16:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   505
    "Modified: / 13-04-2011 / 11:57:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   506
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   507
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   508
validateFieldRef: aJavaFieldRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   509
    aJavaFieldRef isJavaRef ifFalse:[self halt:'I expected Java Ref'].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   510
    aJavaFieldRef isJavaFieldRef ifFalse:[self halt:'I expected Java Field Ref'].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   511
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   512
    "Created: / 11-04-2011 / 21:16:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   513
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   514
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   515
!JavaResolver methodsFor:'interface method resolving'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   516
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   517
resolveInterfaceMethodIdentifiedByRef: aJavaInterfaceMethodRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   518
    | result  class |
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   519
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   520
    self validateInterfaceMethodRef: aJavaInterfaceMethodRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   521
    result := self 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   522
                lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   523
    result ifNotNil: [ ^ result ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   524
    class := aJavaInterfaceMethodRef classRef resolve.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   525
    class ifNil: [ self halt: '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
   526
    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
   527
    result := class 
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   528
                lookupMethodByNameAndType: aJavaInterfaceMethodRef nameAndType.
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   529
    result ifNil: [ self throwNoSuchMethodError ].
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   530
    (self 
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   531
        checkPermissionsForMethod: result
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   532
        from: aJavaInterfaceMethodRef classRef owner
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   533
        to: class) ifFalse: [ self throwIllegalAccessError ].
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   534
^ result.
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   535
     "
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   536
     To resolve an unresolved symbolic reference from D to an interface method in an
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   537
     interface C, the symbolic reference to C given by the interface method reference is
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   538
     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
   539
     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
   540
     failure of interface method resolution. If the reference to C can be successfully
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   541
     resolved, exceptions relating to the resolution of the interface method reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   542
     itself can be thrown.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   543
     When resolving an interface method reference:
816
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   544
     
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   545
     If C is not an interface, interface method resolution throws an IncompatibleClassChangeError.""Otherwise, if the referenced method does not have the same name and descriptor as
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   546
     a method in C or in one of the superinterfaces of C, or in class Object, interface
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   547
     method resolution throws a NoSuchMethodError.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   548
     Otherwise, let <E, L1> be the interface in which the referenced interface method is
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   549
     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
   550
     the type returned by the referenced method, and let T1, ..., Tn be the names of the
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   551
     argument types of the referenced method. The Java virtual machine must impose the
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   552
     loading constraints TiL1 = TiL2 for i = 0 to n (§5.3.4)."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   553
816
4e3072021201 all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents: 814
diff changeset
   554
    "Modified: / 23-05-2011 / 17:56:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   555
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   556
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   557
!JavaResolver methodsFor:'interface method resolving helpers'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   558
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   559
lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   560
    ^  nil.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   561
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   562
    "Created: / 13-04-2011 / 11:53:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   563
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   564
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   565
validateInterfaceMethodRef: aJavaInterfaceMethodRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   566
        aJavaInterfaceMethodRef isJavaRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   567
        ifFalse: [ self halt: 'I expected JavaRef instance as an argument' ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   568
    aJavaInterfaceMethodRef isJavaInterfaceMethodRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   569
                ifFalse: [ self halt: 'I expected JavaMethodRef instance as an argument' ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   570
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   571
    "Created: / 13-04-2011 / 11:53:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   572
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   573
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   574
!JavaResolver methodsFor:'method resolving'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   575
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   576
resolveMethodIndentifiedByRef: aJavaMethodRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   577
    | result  class |
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   578
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   579
    self validateMethodRef: aJavaMethodRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   580
    result := self lookupMethodIfAlreadyResolved: aJavaMethodRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   581
    result ifNotNil: [ ^ result ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   582
    class := aJavaMethodRef classRef resolve.
850
160c389771a6 Fixes in resolving methodrefs for array methods
vranyj1
parents: 846
diff changeset
   583
    class ifNil: [ self error: 'should not happen - tell mh' ].
160c389771a6 Fixes in resolving methodrefs for array methods
vranyj1
parents: 846
diff changeset
   584
    "Array types responds to all method of class java.lang.Object"
160c389771a6 Fixes in resolving methodrefs for array methods
vranyj1
parents: 846
diff changeset
   585
    class isJavaArrayClass ifTrue:[
160c389771a6 Fixes in resolving methodrefs for array methods
vranyj1
parents: 846
diff changeset
   586
        class := Java classForName:'java.lang.Object'.
160c389771a6 Fixes in resolving methodrefs for array methods
vranyj1
parents: 846
diff changeset
   587
    ].
160c389771a6 Fixes in resolving methodrefs for array methods
vranyj1
parents: 846
diff changeset
   588
160c389771a6 Fixes in resolving methodrefs for array methods
vranyj1
parents: 846
diff changeset
   589
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   590
     "
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   591
     To resolve an unresolved symbolic reference from D to a method in
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   592
     a class C, the symbolic reference to C given by the method reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   593
     is first resolved (§5.4.3.1). Therefore, any exceptions that can be
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   594
     thrown due to resolution of a class reference can be thrown as a result
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   595
     of method resolution. If the reference to C can be successfully resolved,
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   596
     exceptions relating to the resolution of the method reference itself
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   597
     can be thrown.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   598
     When resolving a method reference:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   599
     
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   600
     Method resolution checks whether C is a class or an interface.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   601
     If C is an interface, method resolution throws an IncompatibleClassChangeError."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   602
    class isInterface ifTrue: [ self throwIncompatibleClassChangeError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   603
     "Method resolution attempts to look up the referenced method in C and its
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   604
     superclasses:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   605
     If C declares a method with the name and descriptor specified by the method
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   606
     reference, method lookup succeeds.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   607
     Otherwise, if C has a superclass, step 2 of method lookup is recursively
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   608
     invoked on the direct superclass of C.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   609
     
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   610
     Otherwise, method lookup attempts to locate the referenced method in any of
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   611
     the superinterfaces of the specified class C.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   612
     If any superinterface of C declares a method with the name and descriptor
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   613
     specified by the method reference, method lookup succeeds.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   614
     Otherwise, method lookup fails.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   615
     If method lookup fails, method resolution throws a NoSuchMethodError. If method
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   616
     lookup succeeds and the method is abstract, but C is not abstract, method resolution
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   617
     throws an AbstractMethodError. Otherwise, if the referenced method is not accessible
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   618
     (§5.4.4) to D, method resolution throws an IllegalAccessError."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   619
    result := class lookupMethodByNameAndType: aJavaMethodRef nameAndType.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   620
    result ifNil: [ self throwNoSuchMethodError ].
905
d03d9e05c581 Temporary commit. method resolving fixed
vranyj1
parents: 883
diff changeset
   621
    (result isAbstract and:[result javaClass isInterface not and:[ class isAbstract not ]]) 
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   622
        ifTrue: [ self throwAbstractMethodError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   623
    (self 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   624
        checkPermissionsForMethod: result
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   625
        from: aJavaMethodRef classRef owner
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   626
        to: class) ifFalse: [ self throwIllegalAccessError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   627
    ^ result.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   628
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   629
    "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
   630
     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
   631
     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
   632
     the argument types of the referenced method. The Java virtual machine must impose
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   633
     the loading constraints TiL1=TiL2 for i = 0 to n (§5.3.4)."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   634
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   635
    "Created: / 11-04-2011 / 19:45:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   636
    "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
   637
    "Modified: / 10-08-2011 / 22:44:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   638
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   639
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   640
resolveStaticMethodIndentifiedByRef: aJavaMethodRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   641
    | result  class |
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   642
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   643
    self validateMethodRef: aJavaMethodRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   644
    result := self lookupMethodIfAlreadyResolved: aJavaMethodRef.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   645
    result ifNotNil: [ ^ result ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   646
    class := aJavaMethodRef classRef resolve.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   647
    class ifNil: [ self halt: 'should not happen - tell mh' ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   648
     "
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   649
     To resolve an unresolved symbolic reference from D to a method in
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   650
     a class C, the symbolic reference to C given by the method reference
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   651
     is first resolved (§5.4.3.1). Therefore, any exceptions that can be
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   652
     thrown due to resolution of a class reference can be thrown as a result
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   653
     of method resolution. If the reference to C can be successfully resolved,
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   654
     exceptions relating to the resolution of the method reference itself
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   655
     can be thrown.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   656
     When resolving a method reference:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   657
     
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   658
     Method resolution checks whether C is a class or an interface.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   659
     If C is an interface, method resolution throws an IncompatibleClassChangeError."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   660
    class isInterface ifTrue: [ self throwIncompatibleClassChangeError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   661
     "Method resolution attempts to look up the referenced method in C and its
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   662
     superclasses:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   663
     If C declares a method with the name and descriptor specified by the method
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   664
     reference, method lookup succeeds.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   665
     Otherwise, if C has a superclass, step 2 of method lookup is recursively
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   666
     invoked on the direct superclass of C.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   667
     
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   668
     Otherwise, method lookup attempts to locate the referenced method in any of
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   669
     the superinterfaces of the specified class C.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   670
     If any superinterface of C declares a method with the name and descriptor
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   671
     specified by the method reference, method lookup succeeds.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   672
     Otherwise, method lookup fails.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   673
     If method lookup fails, method resolution throws a NoSuchMethodError. If method
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   674
     lookup succeeds and the method is abstract, but C is not abstract, method resolution
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   675
     throws an AbstractMethodError. Otherwise, if the referenced method is not accessible
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   676
     (§5.4.4) to D, method resolution throws an IllegalAccessError."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   677
    result := class lookupStaticMethodByNameAndType: aJavaMethodRef nameAndType.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   678
    result ifNil: [ self throwNoSuchMethodError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   679
    (result isAbstract and: [ class isAbstract not ]) 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   680
        ifTrue: [ self throwAbstractMethodError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   681
    (self 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   682
        checkPermissionsForMethod: result
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   683
        from: aJavaMethodRef classRef owner
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   684
        to: class) ifFalse: [ self throwIllegalAccessError ].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   685
    ^ result.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   686
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   687
    "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
   688
     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
   689
     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
   690
     the argument types of the referenced method. The Java virtual machine must impose
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   691
     the loading constraints TiL1=TiL2 for i = 0 to n (§5.3.4)."
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   692
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   693
    "Created: / 28-04-2011 / 22:50:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   694
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   695
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   696
!JavaResolver methodsFor:'method resolving helpers'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   697
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   698
checkPermissionsForMethod: aJavaMethod from: accessingJavaClass to: resolvedJavaClass 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   699
    "A class or interface C is accessible to a class or interface D if 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   700
     and only if either of the following conditions are true:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   701
     C is public.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   702
     C and D are members of the same runtime package (§5.3).
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   703
     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
   704
     if any of the following conditions is true:
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   705
     R is public.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   706
     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
   707
     of C or C itself.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   708
     R is either protected or package private (that is, neither public nor
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   709
     protected nor private), and is declared by a class in the same runtime
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   710
     package as D.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   711
     R is private and is declared in D.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   712
     This discussion of access control omits a related restriction on the target
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   713
     of a protected field access or method invocation (the target must be of class
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   714
     D or a subtype of D). That requirement is checked as part of the verification
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   715
     process (§5.4.1); it is not part of link-time access control."
819
d95b67600835 Static field resolving fixed
vranyj1
parents: 817
diff changeset
   716
d95b67600835 Static field resolving fixed
vranyj1
parents: 817
diff changeset
   717
    "JV@2011-05-24: Temporary hack, since access checking
d95b67600835 Static field resolving fixed
vranyj1
parents: 817
diff changeset
   718
     is somewhat broken. Marcle should fix it :-)"
d95b67600835 Static field resolving fixed
vranyj1
parents: 817
diff changeset
   719
    OperatingSystem getLoginName = 'jv' ifTrue:[^true].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   720
    
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   721
  ^ self checkPermissionsForMethodOrField: aJavaMethod from: accessingJavaClass to: resolvedJavaClass.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   722
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   723
    "Created: / 11-04-2011 / 20:20:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   724
    "Modified: / 14-04-2011 / 14:20:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
819
d95b67600835 Static field resolving fixed
vranyj1
parents: 817
diff changeset
   725
    "Modified: / 24-05-2011 / 14:06:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   726
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   727
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   728
lookupMethodIfAlreadyResolved: aJavaMethodRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   729
    ^ nil.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   730
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   731
    "Created: / 11-04-2011 / 19:50:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   732
    "Modified: / 13-04-2011 / 11:57:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   733
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   734
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   735
validateMethodRef: aJavaMethodRef 
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   736
    aJavaMethodRef isJavaRef ifFalse:[self halt: 'I expected JavaRef instance as an argument'].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   737
    aJavaMethodRef isJavaMethodRef ifFalse: [self halt: 'I expected JavaMethodRef instance as an argument'].
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   738
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   739
    "Created: / 11-04-2011 / 19:47:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   740
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 759
diff changeset
   741
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   742
!JavaResolver class methodsFor:'documentation'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   743
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   744
version_SVN
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   745
    ^ '$Id$'
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   746
! !
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   747
be8e84381ce0 Merged with /branches/jk
vranyj1
parents:
diff changeset
   748
JavaResolver initialize!