- more reflection stuff moved to JavaMirror
- initial support for Java reflection on alien classes
--- a/src/JavaConstants.st Wed Aug 22 08:35:47 2012 +0000
+++ b/src/JavaConstants.st Wed Aug 22 11:30:10 2012 +0000
@@ -25,8 +25,9 @@
classVariableNames:'ACC_PUBLIC ACC_PRIVATE ACC_PROTECTED ACC_STATIC ACC_FINAL
ACC_SYNCHRONIZED ACC_BRIDGE ACC_VARGARS ACC_NATIVE ACC_ABSTRACT
ACC_STRICT ACC_SYNTHETIC ACC_SUPER ACC_INTERFACE ACC_ANNOTATION
- ACC_ENUM ACC_VOLATILE ACC_TRANSIENT ACC_OBSOLETE
- ACX_INITIALIZED ACX_INITIALIZING ACX_BREAKPNT ACX_HASHANDLER ACX_HASFINALLY AXC_RESOLVED'
+ ACC_ENUM ACC_VOLATILE ACC_TRANSIENT ACC_OBSOLETE ACX_INITIALIZED
+ ACX_INITIALIZING ACX_BREAKPNT ACX_HASHANDLER ACX_HASFINALLY
+ AXC_RESOLVED'
poolDictionaries:''
category:'Languages-Java-Support'
!
@@ -102,6 +103,50 @@
"Modified: / 28-03-2012 / 23:06:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!JavaConstants class methodsFor:'constants'!
+
+ACC_ABSTRACT
+
+ ^ACC_ABSTRACT
+
+ "Created: / 22-08-2012 / 10:53:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ACC_FINAL
+
+ ^ACC_FINAL
+
+ "Created: / 22-08-2012 / 10:53:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ACC_PRIVATE
+
+ ^ACC_PRIVATE
+
+ "Created: / 22-08-2012 / 10:54:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ACC_PROTECTED
+
+ ^ACC_PROTECTED
+
+ "Created: / 22-08-2012 / 12:13:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ACC_PUBLIC
+
+ ^ACC_PUBLIC
+
+ "Created: / 22-08-2012 / 10:53:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ACC_SUPER
+
+ ^ACC_SUPER
+
+ "Created: / 22-08-2012 / 10:54:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!JavaConstants class methodsFor:'documentation'!
version_SVN
--- a/src/JavaMirror.st Wed Aug 22 08:35:47 2012 +0000
+++ b/src/JavaMirror.st Wed Aug 22 11:30:10 2012 +0000
@@ -151,20 +151,60 @@
getDeclaredConstructors: publicOnly
"Returns an java.lang.reflect.Constructor[] with all constructors
- declared by this class"
+ declared by this class. "
^self subclassResponsibility
"Created: / 31-07-2012 / 18:39:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+getDeclaredFields: publicOnly
+ "Returns an java.lang.reflect.Field[] with all constructors
+ declared by this class."
+
+ ^self subclassResponsibility
+
+ "Created: / 22-08-2012 / 12:03:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
getDeclaredMethods:publicOnly
"Returns an java.lang.reflect.Method[] with all methods
- declared by this class"
+ declared by this class."
^ self subclassResponsibility
"Created: / 01-08-2012 / 11:07:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getGenericSignature
+ "Returns Java generic signature (if a generic class) or nil"
+
+ ^nil
+
+ "Created: / 22-08-2012 / 11:57:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getInterfaces
+ "Return a list if interfaces"
+
+ ^self subclassResponsibility
+
+ "Created: / 22-08-2012 / 11:05:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getModifiers
+ "Return class modifiers (public/abstract/final...)"
+
+ ^self subclassResponsibility
+
+ "Created: / 22-08-2012 / 10:49:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getName
+ "Returns name of the class"
+ ^klass javaName
+
+ "Created: / 22-08-2012 / 10:46:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaMirror methodsFor:'initialization'!
@@ -196,7 +236,7 @@
ctorOrMethod := ctorOrMethodClass new.
ctorOrMethod
- instVarNamed: #clazz put: (reflection javaClassObjectForClass: method javaClass);
+ instVarNamed: #clazz put: (reflection javaClassObjectForClass: method mclass);
instVarNamed: #slot put: method;
instVarNamed: #modifiers put: modifiers;
instVarNamed: #parameterTypes
@@ -211,7 +251,7 @@
"/instVarNamed: #parameterAnnotations put: annotations ???;
- method signature notNil ifTrue:[
+ (method isJavaMethod and:[method signature notNil]) ifTrue:[
ctorOrMethod
instVarNamed: #signature
put: (reflection javaStringObjectForString: method signature interned: true)
@@ -248,6 +288,40 @@
"Created: / 01-08-2012 / 10:20:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+createFieldFor: javaField
+ "given a java field, return the corresponding java.lang.Field
+ instance for it."
+ "
+ See OpenJDK7 source:
+ jdk7/hotspot/src/share/vm/runtime/reflection.cpp,
+ oop Reflection::new_field"
+
+ | field clazz name slot type modifiers |
+
+ clazz := reflection javaClassObjectForClass: klass.
+ name := JavaVM reflection javaStringObjectForString: javaField name
+ interned: true.
+ slot := javaField index.
+ type := JavaVM javaClassObjectForClass: javaField typeClass.
+ modifiers := javaField accessFlags.
+ field := (JavaVM classForName: 'java.lang.reflect.Field') new.
+ field
+ instVarNamed: #clazz put: clazz;
+ instVarNamed: #name put: name;
+ instVarNamed: #slot put: slot;
+ instVarNamed: #type put: type;
+ instVarNamed: #modifiers put: modifiers;
+ yourself.
+ javaField annotations
+ ifNotNil: [
+ field instVarNamed: #annotations
+ put: javaField annotations runtimeVisible rawAnnotations
+ ].
+ ^ field.
+
+ "Created: / 22-08-2012 / 12:09:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
createMethodFor: class method: method name: name signature: signature modifiers: modifiers parameterTyoes: parameterClasses returnType: returnClass exceptionTypes: exceptionClasses annotations: annotations
"Creates a new java.lang.Constructor. Arguments:
@@ -315,14 +389,183 @@
"Returns an java.lang.reflect.Constructor[] with all constructors
declared by this class"
- ^ self shouldImplement
+ "Here, return onlu default constructor. Later, all methods annotated
+ with <jsignature: #'<init>(...)V'> wil be returned as well"
+
+ | ctors |
+
+ ctors := OrderedCollection new.
+ klass selectorsAndMethodsDo:[:sel :mthd|
+ (self isJavaConstructor: mthd selector: sel) ifTrue:[
+ ctors add: (self getDeclaredConstructorFor: mthd).
+ ].
+ ].
+
+ ctors isEmpty ifTrue:[
+ "/If no constructor is found, fake default one...
+ ctors add: (self getDeclaredConstructorFor: (klass lookupMethodFor: #initialize)).
+ ].
+
+ ^(JavaVM classForName:'java.lang.reflect.Constructor') javaArrayClass withAll: ctors
+
+ "Modified: / 22-08-2012 / 11:37:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getDeclaredFields:publicOnly
+ "Returns an java.lang.reflect.Field[] with all constructors
+ declared by this class."
+
+ | fields |
+
+ fields := OrderedCollection new.
+
+ klass instVarNames withIndexDo:[:nm :index|
+ | field |
+
+ field := JavaField new.
+ field
+ setAccessFlags: JavaConstants ACC_PROTECTED;
+ setClass: klass;
+ setIndex: klass superclass instSize + index;
+ setDescriptor: #'Ljava/lang/Object;';
+ setName: nm.
+
+ fields add: (self createFieldFor: field)
+ ].
+
+ ^ (JavaVM classForName:'java.lang.reflect.Field') javaArrayClass
+ withAll:fields
+
+ "Modified: / 22-08-2012 / 12:19:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
getDeclaredMethods:publicOnly
"Returns an java.lang.reflect.Method[] with all methods
declared by this class"
-
- ^ self shouldImplement
+
+ | methods |
+
+ methods := OrderedCollection new.
+ klass selectorsAndMethodsDo:[:sel :mthd|
+ (self isJavaMethod: mthd selector: sel) ifTrue:[
+ methods add: (self getDeclaredMethodFor: mthd).
+ ].
+ ].
+ ^(JavaVM classForName:'java.lang.reflect.Method') javaArrayClass withAll: methods
+
+ "Modified: / 22-08-2012 / 11:36:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getInterfaces
+ "Return a list if interfaces"
+
+ ^ Array with: (JavaVM classForName: 'java.lang.Cloneable')
+
+ "Modified: / 22-08-2012 / 11:06:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getModifiers
+ "Return class modifiers (public/abstract/final...)"
+
+ ^ JavaConstants ACC_PUBLIC
+
+ "Modified: / 22-08-2012 / 11:01:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getName
+ "Returns name of the class"
+ ^'SMALLTALK.' , klass name
+
+ "Created: / 22-08-2012 / 10:47:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaMirror::AlienClassMirror methodsFor:'accessing-private'!
+
+getDeclaredConstructorFor: method
+ ^ self
+ createConstructorFor: klass
+ method: method
+ signature: (self getSignatureForConstructor: method)
+ modifiers: JavaConstants ACC_PUBLIC
+ parameterTyoes: #()
+ exceptionTypes: #()
+ annotations: JavaMethodAnnotationContainer new
+
+ "Created: / 22-08-2012 / 11:36:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getDeclaredMethodFor:method
+ | signature name |
+
+ signature := self getSignatureForMethod: method short: false.
+ name := signature upTo: $(.
+ ^ self
+ createMethodFor: klass
+ method: method
+ name: name
+ signature: signature
+ modifiers: JavaConstants ACC_PUBLIC
+ parameterTyoes: #()
+ returnType: (JavaVM classNamed: 'java.lang.Object')
+ exceptionTypes: #()
+ annotations: JavaMethodAnnotationContainer new
+
+ "Created: / 22-08-2012 / 11:36:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getSignatureForConstructor: method
+ | signature |
+
+ signature :=
+ (String streamContents:[:s|
+ s nextPutAll: '<init>('.
+ method selector numArgs timesRepeat:[
+ s nextPutAll:'Ljava/lang/Object;'.
+ ].
+ s nextPutAll: ')V'.
+ ]) asSymbol.
+ ^signature
+
+ "Created: / 22-08-2012 / 11:40:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getSignatureForMethod: method short: short
+ | selector signature |
+
+ selector := method selector.
+ signature :=
+ (String streamContents:[:s|
+ short ifTrue:[
+ s nextPutAll: (selector upTo: $:)
+ ] ifFalse:[
+ s nextPutAll: (selector copyReplaceAll: $: with: $_)
+ ].
+ method selector numArgs timesRepeat:[
+ s nextPutAll:'Ljava/lang/Object;'.
+ ].
+ s nextPutAll: ')'.
+ s nextPutAll:'Ljava/lang/Object;'.
+ ]) asSymbol.
+ ^signature
+
+ "Created: / 22-08-2012 / 11:46:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaMirror::AlienClassMirror methodsFor:'testing-private'!
+
+isJavaConstructor: mthd selector: sel
+
+ ^sel startsWith: #initialize
+
+ "Created: / 22-08-2012 / 11:47:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isJavaMethod: mthd selector: sel
+
+ ^sel isBinarySelector not
+ and:[(self isJavaConstructor: mthd selector: sel) not]
+
+ "Created: / 22-08-2012 / 11:47:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaMirror::JavaArrayMirror methodsFor:'accessing'!
@@ -344,6 +587,15 @@
"Modified: / 31-07-2012 / 18:41:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+getDeclaredFields:publicOnly
+ "Returns an java.lang.reflect.Field[] with all constructors
+ declared by this class."
+
+ ^(JavaVM classForName:'java.lang.reflect.Field') javaArrayClass new:0.
+
+ "Modified: / 22-08-2012 / 12:03:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
getDeclaredMethods:publicOnly
"Returns an java.lang.reflect.Method[] with all methods
declared by this class"
@@ -351,6 +603,24 @@
^ (JavaVM classForName:'java.lang.reflect.Method') javaArrayClass new:0.
"Modified: / 01-08-2012 / 11:08:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getInterfaces
+ "Return a list if interfaces"
+
+ ^ Array
+ with: (JavaVM classForName: 'java.lang.Cloneable')
+ with: (JavaVM classForName: 'java.io.Serializable')
+
+ "Modified: / 22-08-2012 / 11:06:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getModifiers
+ "Return class modifiers (public/abstract/final...)"
+
+ ^ JavaConstants ACC_ABSTRACT | JavaConstants ACC_FINAL | JavaConstants ACC_PUBLIC
+
+ "Modified: / 22-08-2012 / 11:02:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaMirror::JavaClassMirror class methodsFor:'documentation'!
@@ -398,21 +668,71 @@
"Modified: / 01-08-2012 / 11:04:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+getDeclaredFields:publicOnly
+ "Returns an java.lang.reflect.Field[] with all constructors
+ declared by this class."
+
+ | fields |
+
+ fields := klass fields , klass staticFields.
+ publicOnly ifTrue:[ fields := fields select:[:f | f isPublic ] ].
+ JavaClassReader classLoaderQuerySignal answer: klass classLoader do:[
+ fields := fields collect:[:f | self createFieldFor:f ].
+ ].
+ ^ (JavaVM classForName:'java.lang.reflect.Field') javaArrayClass
+ withAll:fields
+
+ "Modified: / 22-08-2012 / 12:10:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
getDeclaredMethods:publicOnly
"Returns an java.lang.reflect.Constructor[] with all constructors
declared by this class"
- | ctors |
+ | methods |
- ctors := OrderedCollection new.
+ methods := OrderedCollection new.
klass selectorsAndMethodsDo:[:sel :mthd|
(mthd isJavaConstructor not and:[publicOnly not or:[mthd isPublic]]) ifTrue:[
- ctors add: (self getDeclaredMethodFor: mthd).
+ methods add: (self getDeclaredMethodFor: mthd).
].
].
- ^(JavaVM classForName:'java.lang.reflect.Method') javaArrayClass withAll: ctors
+ ^(JavaVM classForName:'java.lang.reflect.Method') javaArrayClass withAll: methods
"Modified: / 01-08-2012 / 11:10:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getGenericSignature
+ "Returns Java generic signature (if a generic class) or nil"
+
+ ^klass signatureJ
+
+ "Created: / 22-08-2012 / 11:58:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getInterfaces
+ "Return a list if interfaces"
+
+ ^ klass interfaces
+
+ "Modified: / 22-08-2012 / 11:08:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getModifiers
+ "Return class modifiers (public/abstract/final...)"
+
+ | modifiers |
+
+ "According to OpenJDK JVM, strip ACC_SUPER"
+ modifiers := (klass accessFlags & JavaConstants ACC_SUPER bitInvert) & 16r7FFF.
+ "JV@2011-10-30: It seems that private inner classes has no
+ private bit set, sigh"
+ (modifiers & 16r0007) == 0 ifTrue:[
+ modifiers := modifiers | JavaConstants ACC_PRIVATE.
+ ].
+ ^modifiers
+
+ "Modified: / 22-08-2012 / 11:03:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaMirror::JavaClassMirror methodsFor:'accessing-private'!
@@ -464,6 +784,15 @@
"Modified: / 31-07-2012 / 18:41:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+getDeclaredFields:publicOnly
+ "Returns an java.lang.reflect.Field[] with all constructors
+ declared by this class."
+
+ ^(JavaVM classForName:'java.lang.reflect.Field') javaArrayClass new:0.
+
+ "Modified: / 22-08-2012 / 12:03:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
getDeclaredMethods:publicOnly
"Returns an java.lang.reflect.Method[] with all methods
declared by this class"
@@ -471,6 +800,22 @@
^ (JavaVM classForName:'java.lang.reflect.Method') javaArrayClass new:0.
"Modified: / 01-08-2012 / 11:08:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getInterfaces
+ "Return a list if interfaces"
+
+ ^ #()
+
+ "Modified: / 22-08-2012 / 11:07:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getModifiers
+ "Return class modifiers (public/abstract/final...)"
+
+ ^ JavaConstants ACC_ABSTRACT | JavaConstants ACC_FINAL | JavaConstants ACC_PUBLIC
+
+ "Modified: / 22-08-2012 / 11:02:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaMirror class methodsFor:'documentation'!
--- a/src/JavaObject.st Wed Aug 22 08:35:47 2012 +0000
+++ b/src/JavaObject.st Wed Aug 22 11:30:10 2012 +0000
@@ -270,7 +270,7 @@
myClassName == #'java/lang/Class' ifTrue:[
super printOn: aStream.
aStream nextPut: $(.
- (JavaVM reflection classForJavaClassObject:self) javaName printOn: aStream.
+ (JavaVM reflection classForJavaClassObject:self) javaMirror getName printOn: aStream.
aStream nextPut: $).
^self.
].
--- a/src/JavaVM.st Wed Aug 22 08:35:47 2012 +0000
+++ b/src/JavaVM.st Wed Aug 22 11:30:10 2012 +0000
@@ -6966,18 +6966,12 @@
].
publicOnly := (aJavaContext argAt:1) == 1.
- fields := class fields , class staticFields.
- publicOnly ifTrue:[ fields := fields select:[:f | f isPublic ] ].
- JavaClassReader classLoaderQuerySignal answer: class classLoader do:[
- fields := fields
- collect:[:f | self javaFieldObjectForField:f in:javaClassObject ].
- ].
- ^ (self classForName:'java.lang.reflect.Field') javaArrayClass
- withAll:fields
+ fields := class javaMirror getDeclaredFields: publicOnly.
+ ^fields
"Created: / 10-11-2010 / 16:22:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-01-2011 / 15:19:06 / Marcel Hlopko <hlopik@gmail.com>"
- "Modified: / 31-08-2011 / 22:21:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-08-2012 / 12:16:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
_java_lang_Class_getDeclaredMethods0:aJavaContext
@@ -7039,15 +7033,14 @@
|cls sig |
cls := self reflection classForJavaClassObject:(nativeContext receiver).
- (cls isJavaPrimitiveType or:[cls isJavaArrayClass]) ifTrue:[^nil].
- sig := cls signatureJ.
+ sig := cls javaMirror getGenericSignature.
^sig notNil ifTrue:[
Java as_String: sig
] ifFalse:[
nil
]
- "Modified: / 13-08-2011 / 02:19:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-08-2012 / 11:58:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
_java_lang_Class_getInterfaces:nativeContext
@@ -7056,48 +7049,26 @@
jClass := nativeContext receiver.
cls := self reflection classForJavaClassObject:jClass.
- cls isJavaPrimitiveType ifTrue:[
- ^ (self classForName:'java.lang.Class') javaArrayClass new
- ].
- cls isJavaArrayClass ifTrue:[
- ^ (self classForName:'java.lang.Class') javaArrayClass
- with:(self javaClassObjectForClass:(self classForName: 'java.lang.Cloneable'))
- with:(self javaClassObjectForClass:(self classForName: 'java.io.Serializable'))
- ].
- interfaces := cls interfaces.
- interfaces
- ifNil:[ ^ (self classForName:'java.lang.Class') javaArrayClass new ].
- jInterfaces := (self classForName:'java.lang.Class') javaArrayClass
- new:interfaces size.
+ interfaces := cls javaMirror getInterfaces.
+ jInterfaces := (self classForName:'java.lang.Class') javaArrayClass new:interfaces size.
interfaces
withIndexDo:[:iface :idx | jInterfaces at:idx put:(self javaClassObjectForClass:iface) ].
^ jInterfaces
"Modified: / 28-01-2011 / 15:19:11 / Marcel Hlopko <hlopik@gmail.com>"
- "Modified: / 30-10-2011 / 20:04:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-08-2012 / 11:08:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
_java_lang_Class_getModifiers: aJavaContext
<javanative: 'java/lang/Class' name: 'getModifiers'>
- | cls modifiers |
+ | cls |
cls := (self reflection classForJavaClassObject: aJavaContext receiver).
- (cls isJavaPrimitiveType or: [ cls isJavaArrayClass ]) ifTrue: [
- modifiers := ACC_ABSTRACT | ACC_FINAL | ACC_PUBLIC
- ] ifFalse: [
- "According to OpenJDK JVM, strip ACC_SUPER"
- modifiers := (cls accessFlags & ACC_SUPER bitInvert) & 16r7FFF.
- "JV@2011-10-30: It seems that private inner classes has no
- private bit set, sigh"
- (modifiers & 16r0007) == 0 ifTrue:[
- modifiers := modifiers | ACC_PRIVATE.
- ].
- ].
- ^modifiers
+ ^cls javaMirror getModifiers
"Created: / 12-11-1998 / 18:54:53 / cg"
"Modified: / 28-01-2011 / 15:19:14 / Marcel Hlopko <hlopik@gmail.com>"
- "Modified: / 30-10-2011 / 17:26:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-08-2012 / 11:04:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
_java_lang_Class_getName0: aJavaContext
@@ -7109,12 +7080,12 @@
class := aJavaContext receiver.
class := self reflection classForJavaClassObject:aJavaContext receiver.
^ self reflection
- javaStringObjectForString:class javaName
+ javaStringObjectForString:class javaMirror getName
interned:true.
"Created: / 22-11-2010 / 17:50:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 09-02-2011 / 01:06:53 / Marcel Hlopko <hlopik@gmail.com>"
- "Modified: / 25-02-2011 / 19:00:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-08-2012 / 10:47:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
_java_lang_Class_getPrimitiveClass: nativeContext
@@ -17672,18 +17643,19 @@
<javanative: 'sun/reflect/NativeConstructorAccessorImpl' name: 'newInstance0'>
- | ctor args method instance |
+ | ctor args method instance class |
ctor := aJavaContext argAt: 1.
args := aJavaContext argAt: 2.
+ class := self reflection classForJavaConstructorObject: ctor.
method := self reflection methodForJavaConstructorObject: ctor.
- instance := method javaClass new.
+ instance := class new.
self invoke: ctor receiver: instance arguments: args context: aJavaContext constructor: true.
^instance
"Created: / 26-11-2010 / 11:41:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 09-02-2011 / 01:12:10 / Marcel Hlopko <hlopik@gmail.com>"
- "Modified: / 06-07-2012 / 23:55:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-08-2012 / 12:25:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
_sun_reflect_NativeMethodAccessorImpl_invoke0: nativeContext
@@ -19382,6 +19354,16 @@
!JavaVM::Reflection methodsFor:'reflection - methods & ctors'!
+classForJavaConstructorObject:constructor
+ "given a java.lang.reflect.Constructor, return the corresponding class for it."
+
+ | jclass |
+ jclass := constructor instVarNamed: #clazz.
+ ^self classForJavaClassObject: jclass.
+
+ "Created: / 22-08-2012 / 12:23:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
javaConstructorObjectForMethod:method
"given a real method, return the corresponding java.lang.reflect.Constructor
instance for it."
--- a/src/extensions.st Wed Aug 22 08:35:47 2012 +0000
+++ b/src/extensions.st Wed Aug 22 11:30:10 2012 +0000
@@ -933,6 +933,16 @@
"Created: / 24-02-2012 / 19:42:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!Method methodsFor:'queries'!
+
+isStatic
+ "For compatibility with Java methods"
+
+ ^mclass notNil and:[mclass isMetaclass]
+
+ "Created: / 22-08-2012 / 12:27:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!Object methodsFor:'testing'!
isGroovyClass
--- a/src/libjava.rc Wed Aug 22 08:35:47 2012 +0000
+++ b/src/libjava.rc Wed Aug 22 11:30:10 2012 +0000
@@ -25,7 +25,7 @@
VALUE "LegalCopyright", "Copyright Claus Gittinger 1988-2011\nCopyright eXept Software AG 1998-2011\nCopyright Jan Vrany, Jan Kurs and Marcel Hlopko\b SWING Research Group, Czech Technical University In Prague\0"
VALUE "ProductName", "Smalltalk/X\0"
VALUE "ProductVersion", "6.2.3.1\0"
- VALUE "ProductDate", "Wed, 22 Aug 2012 05:52:45 GMT\0"
+ VALUE "ProductDate", "Wed, 22 Aug 2012 11:29:12 GMT\0"
END
END
--- a/src/stx_libjava.st Wed Aug 22 08:35:47 2012 +0000
+++ b/src/stx_libjava.st Wed Aug 22 11:30:10 2012 +0000
@@ -156,16 +156,16 @@
^ #(
#'stx:goodies/sunit' "TestSuite - referenced by stx_libjava class>>testSuite "
- #'stx:libbasic' "Stream - superclass of JavaSocket "
- #'stx:libbasic2' "BitArray - superclass of extended BooleanArray "
- #'stx:libbasic3' "MessageTracer - referenced by JavaMethod>>setBreakPoint "
- #'stx:libcomp' "ReturnNode - referenced by ProxyMethodCompiler>>generate "
+ #'stx:libbasic' "StandaloneStartup - superclass of JavaStartup "
+ #'stx:libbasic2' "UnboxedIntegerArray - superclass of extended SignedIntegerArray "
+ #'stx:libbasic3' "WrappedMethod - extended "
+ #'stx:libcomp' "Parser::ParseError - referenced by GroovyEvaluator>>syntaxError:atLine:from:to: "
#'stx:libhtml' "URL - referenced by JavaEmbeddedFrameView>>setupAppletFrameIn:initializeJava: "
- #'stx:libtool' "DebugView - referenced by Java class>>flushClasses "
- #'stx:libview' "GraphicsContext - superclass of JavaPopUpView "
+ #'stx:libtool' "WorkspaceApplication - referenced by GroovyEvaluator>>evaluate:in:receiver:notifying:logged:ifFail: "
+ #'stx:libview' "SimpleView - superclass of JavaView "
#'stx:libview2' "GIFReader - referenced by JavaVM class>>_GifImageDecoder_parseImage: "
- #'stx:libwidg' "HorizontalScrollBar - referenced by JavaVM class>>_WScrollPanePeer__getHScrollbarHeight: "
- #'stx:libwidg2' "ComboListView - referenced by JavaVM class>>_WChoicePeer_create: "
+ #'stx:libwidg' "SelectionInListView - referenced by JavaVM class>>_WListPeer_create: "
+ #'stx:libwidg2' "MenuPanel - referenced by JavaVM class>>processEvent: "
)
! !
@@ -553,6 +553,7 @@
Object isSocket
Socket isSocket
Socket reOpenIfPossible
+ Method isStatic
)
! !