JavaClass.st
branchcvs_MAIN
changeset 3699 da7d1fe7fc6a
parent 3696 28fd35857eb9
child 3704 20e66c34df2a
equal deleted inserted replaced
3698:6b3b66d7a2d8 3699:da7d1fe7fc6a
   387 !
   387 !
   388 
   388 
   389 lookupMethod:selector numArgs:nargs in:aClass static:staticMethod
   389 lookupMethod:selector numArgs:nargs in:aClass static:staticMethod
   390     "lookup a method"
   390     "lookup a method"
   391 
   391 
   392     |method cls sel|
   392     |cls sel|
   393 
   393 
   394     sel := selector.
   394     sel := selector.
   395     (sel includes:$:) ifTrue:[
   395     (sel includes:$:) ifTrue:[
   396 	sel := sel copyTo:(sel indexOf:$:)-1
   396         sel := sel copyTo:(sel indexOf:$:)-1
   397     ].
   397     ].
   398 
   398 
   399     sel := sel asSymbolIfInterned.
   399     sel := sel asSymbolIfInterned.
   400     sel notNil ifTrue:[
   400     sel notNil ifTrue:[
   401 	cls := aClass.
   401         cls := aClass.
   402 
   402 
   403 	[cls notNil
   403         [cls notNil
   404 	and:[cls ~~ JavaObject
   404         and:[cls ~~ JavaObject
   405 	and:[cls ~~ JavaClass]]] whileTrue:[
   405         and:[cls ~~ JavaClass]]] whileTrue:[
   406 	    cls methodDictionary keysAndValuesDo:[:jSel :m |
   406             cls methodDictionary keysAndValuesDo:[:jSel :m |
   407 		|aMethod|
   407                 |aMethod|
   408 
   408 
   409 		aMethod := m.
   409                 aMethod := m.
   410 		aMethod isWrapped ifTrue:[
   410                 aMethod isWrapped ifTrue:[
   411 		    aMethod := aMethod originalMethod
   411                     aMethod := aMethod originalMethod
   412 		].
   412                 ].
   413 
   413 
   414 		((jSel == sel)
   414                 ((jSel == sel)
   415 		or:[aMethod name = sel
   415                 or:[aMethod name = sel
   416 		or:[aMethod signatureNameWithoutReturnType = sel]])
   416                 or:[aMethod signatureNameWithoutReturnType = sel]])
   417 		ifTrue:[
   417                 ifTrue:[
   418 		    aMethod numArgs == nargs ifTrue:[
   418                     aMethod numArgs == nargs ifTrue:[
   419 			staticMethod == (aMethod isStatic) ifTrue:[
   419                         staticMethod == (aMethod isStatic) ifTrue:[
   420 			    ^ m
   420                             ^ m
   421 			]
   421                         ]
   422 		    ]
   422                     ]
   423 		]
   423                 ]
   424 	    ].
   424             ].
   425 
   425 
   426 	    cls := cls superclass.
   426             cls := cls superclass.
   427 	].
   427         ].
   428     ].
   428     ].
   429 "/ self halt.
   429 "/ self halt.
   430     ^ nil
   430     ^ nil
   431 
   431 
   432     "Created: / 17.8.1997 / 18:25:47 / cg"
   432     "Created: / 17-08-1997 / 18:25:47 / cg"
   433     "Modified: / 16.11.1998 / 16:46:48 / cg"
   433     "Modified: / 16-11-1998 / 16:46:48 / cg"
       
   434     "Modified (format): / 14-02-2017 / 10:13:43 / stefan"
   434 !
   435 !
   435 
   436 
   436 lookupMethods:selector numArgs:nargs in:aClass static:staticMethod
   437 lookupMethods:selector numArgs:nargs in:aClass static:staticMethod
   437     "lookup methods matching a selector.
   438     "lookup methods matching a selector.
   438      This is a special entry for doesNotUnderstand redirection
   439      This is a special entry for doesNotUnderstand redirection
   664     ^ nil
   665     ^ nil
   665 
   666 
   666     "Created: 1.8.1997 / 00:01:58 / cg"
   667     "Created: 1.8.1997 / 00:01:58 / cg"
   667 !
   668 !
   668 
   669 
   669 constantPool
       
   670     ^ constantPool
       
   671 !
       
   672 
       
   673 declaringClass
   670 declaringClass
   674     | innerClassesAttr |
   671     | innerClassesAttr |
   675 
   672 
   676     innerClassesAttr := self getAttribute: #InnerClasses.
   673     innerClassesAttr := self getAttribute: #InnerClasses.
   677     innerClassesAttr notNil ifTrue:[
   674     innerClassesAttr notNil ifTrue:[
   973 staticFields
   970 staticFields
   974     ^ staticFields
   971     ^ staticFields
   975 !
   972 !
   976 
   973 
   977 superinterface
   974 superinterface
   978 
       
   979     | ifaces |
   975     | ifaces |
   980 
   976 
   981     self assert: self isInterface message: 'Type must be an interface'.
   977     self assert: self isInterface message: 'Type must be an interface'.
   982     (ifaces := self interfaces) size == 0 ifTrue:[^nil].
   978     ifaces := self interfaces.
   983     ifaces size = 1 ifTrue:[^ifaces first].
   979     ifaces size == 0 ifTrue:[^ nil].
   984 
   980     ifaces size == 1 ifTrue:[^ ifaces first].
   985     self error: 'Should not happen!!'.
   981 
   986     ^nil
   982     self error:'Should not happen!!'.
       
   983     ^ nil
   987 
   984 
   988     "Created: / 04-02-2011 / 12:35:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   985     "Created: / 04-02-2011 / 12:35:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   986     "Modified: / 14-02-2017 / 10:13:07 / stefan"
   989 !
   987 !
   990 
   988 
   991 theClass
   989 theClass
   992 
   990 
   993     ^ self
   991     ^ self
  1071     "Modified: / 07-12-2014 / 01:37:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1069     "Modified: / 07-12-2014 / 01:37:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1072 ! !
  1070 ! !
  1073 
  1071 
  1074 !JavaClass methodsFor:'accessing - java'!
  1072 !JavaClass methodsFor:'accessing - java'!
  1075 
  1073 
  1076 javaMirror
       
  1077     ^self javaMirrorClass forClass: self.
       
  1078 
       
  1079     "Created: / 01-08-2012 / 00:18:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1080 !
       
  1081 
       
  1082 javaMirrorClass
  1074 javaMirrorClass
  1083     ^JavaMirror mirrorClassForJavaClass
  1075     ^JavaMirror mirrorClassForJavaClass
  1084 
  1076 
  1085     "Created: / 31-07-2012 / 17:39:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1077     "Created: / 31-07-2012 / 17:39:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1086 ! !
  1078 ! !
  1092 
  1084 
  1093     "Created: 12.8.1997 / 02:46:51 / cg"
  1085     "Created: 12.8.1997 / 02:46:51 / cg"
  1094 ! !
  1086 ! !
  1095 
  1087 
  1096 !JavaClass methodsFor:'autoboxing'!
  1088 !JavaClass methodsFor:'autoboxing'!
  1097 
       
  1098 javaBox:anObject
       
  1099     ^ anObject
       
  1100 
       
  1101     "Created: / 14-08-2011 / 22:58:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1102 !
       
  1103 
  1089 
  1104 javaUnwrap: object
  1090 javaUnwrap: object
  1105 
  1091 
  1106     | nm |
  1092     | nm |
  1107 
  1093 
  2355 
  2341 
  2356     "Created: / 20-01-1997 / 13:00:48 / cg"
  2342     "Created: / 20-01-1997 / 13:00:48 / cg"
  2357     "Modified: / 20-04-2012 / 20:27:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2343     "Modified: / 20-04-2012 / 20:27:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2358 !
  2344 !
  2359 
  2345 
  2360 setAccessFlags:flags
       
  2361     accessFlags := flags.
       
  2362 
       
  2363     "Created: 15.4.1996 / 16:42:52 / cg"
       
  2364 !
       
  2365 
       
  2366 setAttributes: aSequenceableCollection
  2346 setAttributes: aSequenceableCollection
  2367     aSequenceableCollection isNil ifTrue:[
  2347     aSequenceableCollection isNil ifTrue:[
  2368         attributes := Attributes empty.
  2348         attributes := Attributes empty.
  2369     ] ifFalse:[
  2349     ] ifFalse:[
  2370         aSequenceableCollection class == Attributes ifTrue:[
  2350         aSequenceableCollection class == Attributes ifTrue:[
  2652     ^ (accessFlags bitAnd:ACX_HASFINALIZE) ~~ 0
  2632     ^ (accessFlags bitAnd:ACX_HASFINALIZE) ~~ 0
  2653 
  2633 
  2654     "Created: / 02-11-2012 / 18:50:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2634     "Created: / 02-11-2012 / 18:50:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2655 !
  2635 !
  2656 
  2636 
  2657 hasInterface:aJavaInterface
       
  2658     "return true, if I respond to all methods as
       
  2659      required by the argument, an aJavaInterface"
       
  2660 
       
  2661     interfaces size > 0 ifTrue:[
       
  2662 	self interfaces do:[:if |
       
  2663 	    aJavaInterface == if ifTrue:[
       
  2664 		^ true
       
  2665 	    ].
       
  2666 	]
       
  2667     ].
       
  2668     superclass isJavaClass ifTrue:[
       
  2669 	^ superclass hasInterface:aJavaInterface
       
  2670     ].
       
  2671     ^ false.
       
  2672 
       
  2673 "/    aJavaInterface methodDictionary keysAndValuesDo:[:sel :mthd |
       
  2674 "/        (self canUnderstand:sel) ifFalse:[
       
  2675 "/            ^ false.
       
  2676 "/        ]
       
  2677 "/    ].
       
  2678     ^ true
       
  2679 
       
  2680     "Modified: / 28.1.1998 / 01:46:16 / cg"
       
  2681 
       
  2682 !
       
  2683 
       
  2684 hasMagicAccessRights
  2637 hasMagicAccessRights
  2685     "Classes subclassing from sun.reflect.MagicAccessorImpl are not subject to access rights checks. Another non-documented gem found in openjdk sources :)"
  2638     "Classes subclassing from sun.reflect.MagicAccessorImpl are not subject to access rights checks. Another non-documented gem found in openjdk sources :)"
  2686 
  2639 
  2687     | magicAccessor |
  2640     | magicAccessor |
  2688     magicAccessor := JavaVM classNamed: 'sun.reflect.MagicAccessorImpl' definedBy: nil.
  2641     magicAccessor := JavaVM classNamed: 'sun.reflect.MagicAccessorImpl' definedBy: nil.
  2824     "Created: / 12-11-2013 / 00:33:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2777     "Created: / 12-11-2013 / 00:33:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2825     "Modified: / 12-11-2013 / 11:06:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2778     "Modified: / 12-11-2013 / 11:06:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2826 !
  2779 !
  2827 
  2780 
  2828 isFullyResolved
  2781 isFullyResolved
  2829     constantPool do: [:each | (each isJavaRef and: [each isResolved not]) ifTrue: [^false]].
  2782     ^ constantPool conform:[:eachConst | eachConst isJavaRef not or:[eachConst isResolved]].
  2830     ^ true.
       
  2831 
  2783 
  2832     "Created: / 08-12-2011 / 20:44:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
  2784     "Created: / 08-12-2011 / 20:44:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
  2833     "Modified (format): / 02-10-2013 / 21:29:57 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
  2785     "Modified (format): / 02-10-2013 / 21:29:57 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
       
  2786     "Modified: / 14-02-2017 / 10:11:23 / stefan"
  2834 !
  2787 !
  2835 
  2788 
  2836 isJavaArrayClass
  2789 isJavaArrayClass
  2837 
  2790 
  2838     ^false
  2791     ^false
  2870 
  2823 
  2871 isJavaMethodRef
  2824 isJavaMethodRef
  2872     ^ false
  2825     ^ false
  2873 
  2826 
  2874     "Created: / 9.11.1999 / 15:42:10 / cg"
  2827     "Created: / 9.11.1999 / 15:42:10 / cg"
  2875 !
       
  2876 
       
  2877 isJavaPrimitiveType
       
  2878 
       
  2879     ^false
       
  2880 
       
  2881     "
       
  2882         (Java classForName:'java.lang.Class') isJavaPrimitiveType
       
  2883         ByteArray isJavaPrimitiveType
       
  2884     "
       
  2885 
       
  2886     "Created: / 21-12-2010 / 23:03:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  2887 !
  2828 !
  2888 
  2829 
  2889 isJavaReferenceType
  2830 isJavaReferenceType
  2890 
  2831 
  2891     ^true
  2832     ^true
  3104     "Created: / 07-12-2011 / 23:05:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
  3045     "Created: / 07-12-2011 / 23:05:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
  3105 !
  3046 !
  3106 
  3047 
  3107 findInterfaceFieldByName: fieldName
  3048 findInterfaceFieldByName: fieldName
  3108     | result  seenIfaces  ifaces |
  3049     | result  seenIfaces  ifaces |
       
  3050 
  3109     ifaces := OrderedCollection withAll: self interfaces.
  3051     ifaces := OrderedCollection withAll: self interfaces.
  3110     seenIfaces := Set new.
  3052     seenIfaces := Set new.
  3111     [ ifaces notEmpty ] whileTrue: [
  3053     [ ifaces notEmpty ] whileTrue: [
  3112         | iface |
  3054         | iface |
  3113         iface := ifaces removeFirst.
  3055         iface := ifaces removeFirst.
  3114         result := iface staticFields
  3056         result := iface staticFields
  3115                     detect: [:each | each name = fieldName ]
  3057                     detect: [:each | each name = fieldName ]
  3116                     ifNone: [ nil ].
  3058                     ifNone: [ nil ].
  3117         result notNil ifTrue: [ ^ result ].
  3059         result notNil ifTrue: [ ^ result ].
  3118         seenIfaces add: iface.
  3060         seenIfaces add: iface.
  3119         iface interfaces do: [
  3061         iface interfaces do: [:each |
  3120             :each |
  3062             (seenIfaces includes:each) ifFalse:[
  3121             (seenIfaces includes: each) not ifTrue: [ ifaces add: each ]
  3063                 ifaces add:each.
  3122         ]
  3064             ]
       
  3065         ].
  3123     ].
  3066     ].
  3124     ^ nil.
  3067     ^ nil.
  3125 
  3068 
  3126     "Created: / 07-12-2011 / 23:05:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
  3069     "Created: / 07-12-2011 / 23:05:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
       
  3070     "Modified (format): / 14-02-2017 / 10:15:44 / stefan"
  3127 !
  3071 !
  3128 
  3072 
  3129 findStaticFieldByName: fieldName
  3073 findStaticFieldByName: fieldName
  3130     "tries to find a field in current class (not superclasses)"
  3074     "tries to find a field in current class (not superclasses)"
  3131 
  3075