src/JavaClass.st
branchjk_new_structure
changeset 761 43e017ec7958
parent 758 be8e84381ce0
child 763 1e82b558abd3
--- a/src/JavaClass.st	Mon Apr 25 19:32:44 2011 +0000
+++ b/src/JavaClass.st	Sun May 01 12:52:23 2011 +0000
@@ -1907,6 +1907,60 @@
 
     "Created: / 05-02-2011 / 23:44:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 11-02-2011 / 09:12:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isSubclassOf:  aJavaClass
+|tmpClass|
+
+tmpClass := self superclass.
+[tmpClass isJavaClass] whileTrue: [tmpClass = aJavaClass ifTrue:[^true]. tmpClass := tmpClass superclass].
+^false.
+
+    "Created: / 13-04-2011 / 23:18:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
+!JavaClass methodsFor:'reflection'!
+
+lookupFieldByNameAndType: aJavaNameAndType 
+    | result |
+
+    result := fields detect: 
+                    [:each | 
+                    (each name = aJavaNameAndType name 
+                        and: [ each signature = aJavaNameAndType descriptor ]) ].
+    result ifNotNil: [ ^ result ].
+    self superclass ~= JavaObject 
+        ifTrue: [ ^ self superclass lookupFieldByNameAndType: aJavaNameAndType ]
+            ifFalse: [ ^ nil ].
+
+    "Created: / 11-04-2011 / 21:27:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 28-04-2011 / 22:31:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+lookupMethodByNameAndType: aJavaNameAndType 
+    ^ self lookupMethodFor: aJavaNameAndType selector.
+
+    "Created: / 11-04-2011 / 21:28:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+lookupStaticFieldByNameAndType: aJavaNameAndType 
+    | result |
+
+    result := staticFields detect: 
+                    [:each | 
+                    (each name = aJavaNameAndType name 
+                        and: [ each signature = aJavaNameAndType descriptor ]) ].
+    result ifNotNil: [ ^ result ].
+    self superclass ~= JavaObject ifTrue: [^ self superclass lookupStaticFieldByNameAndType: aJavaNameAndType]
+    ifFalse: [^nil].
+
+    "Created: / 28-04-2011 / 22:25:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+lookupStaticMethodByNameAndType: aJavaNameAndType 
+    ^ self lookupMethodFor: aJavaNameAndType selector.
+
+    "Created: / 28-04-2011 / 22:50:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 ! !
 
 !JavaClass methodsFor:'special'!
@@ -1985,34 +2039,46 @@
 !JavaClass methodsFor:'support - sUnit'!
 
 asTestCase
-
-    ^JUnitTestCaseProxy for: self
+    self halt.
+    self isTestletLike 
+        ifTrue: 
+            [ self halt.
+            ^ TestletTestCaseProxy for: self ].
+    ^ JUnitTestCaseProxy for: self.
 
     "Created: / 04-03-2011 / 08:20:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 29-04-2011 / 17:52:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+asTestlet
+    ^ TestletTestCaseProxy for: self
+
+    "Created: / 29-04-2011 / 16:53:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 !
 
 isTestCaseLike
-    | junit_framework_TestCase org_junit_Test |
+    | junit_framework_TestCase  org_junit_Test |
 
     "try JUnit 4.x"
-
-    [ org_junit_Test := 
-        JavaVM classForName:'org.junit.Test' 
-    ] on:Error do:[ "nothing" ].
-    (org_junit_Test notNil and:[self containsMethodsAnnotatedWith:org_junit_Test typeName ])
-        ifTrue:[^true].
-
-    "Try jUnit 3.x"
-    [ junit_framework_TestCase := 
-        JavaVM classForName:'junit.framework.TestCase' 
-    ] on:Error do:[ "nothing" ].
-
-    junit_framework_TestCase ifNotNil:
-        [self == org_junit_Test ifTrue:[ ^ false ].
-        (self includesBehavior:junit_framework_TestCase)
-            ifTrue:[^true]].
-
-    ^false
+    [ org_junit_Test := JavaVM classForName: 'org.junit.Test' ] on: Error
+        do: 
+            [ "nothing"
+             ].
+    (org_junit_Test notNil 
+        and: [ self containsMethodsAnnotatedWith: org_junit_Test typeName ]) 
+            ifTrue: [ ^ true ].
+     "Try jUnit 3.x"
+    
+    [ junit_framework_TestCase := JavaVM 
+                classForName: 'junit.framework.TestCase' ] on: Error
+            do: 
+                [ "nothing"
+                 ].
+    junit_framework_TestCase ifNotNil: 
+            [ self == org_junit_Test ifTrue: [ ^ false ].
+            (self includesBehavior: junit_framework_TestCase) ifTrue: [ ^ true ] ].
+    ^ self isTestletLike.
+
     "
         JAVA::java::lang::Object isTestCaseLike
         JAVA::stx::libjava::tests::junit::JUnit3Tests isTestCaseLike"
@@ -2020,6 +2086,7 @@
     "Created: / 28-02-2011 / 21:31:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 02-03-2011 / 23:08:02 / Marcel Hlopko <hlopik@gmail.com>"
     "Modified: / 06-03-2011 / 14:27:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 29-04-2011 / 17:52:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 !
 
 isTestSelector: selector
@@ -2038,6 +2105,24 @@
 
     "Modified: / 02-03-2011 / 23:08:02 / Marcel Hlopko <hlopik@gmail.com>"
     "Created: / 04-03-2011 / 07:07:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isTestletLike
+    | testlet   |
+
+   
+    [ testlet := JavaVM classForName: 'gnu.testlet.Testlet' ] on: Error
+        do: 
+            [ "nothing"
+             ].
+    testlet ifNil:[^ false].
+    self == testlet ifTrue: [ ^ false ].
+            (self includesBehavior: testlet) ifTrue: [ ^ true ].
+    ^ false.
+
+    "Modified: / 02-03-2011 / 23:08:02 / Marcel Hlopko <hlopik@gmail.com>"
+    "Modified: / 06-03-2011 / 14:27:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 29-04-2011 / 17:02:22 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 ! !
 
 !JavaClass class methodsFor:'documentation'!
@@ -2052,3 +2137,4 @@
 
 JavaClass initialize!
 
+