File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,6 +105,26 @@ public function __construct(JavaClass $javaClass)
105105 }
106106 }
107107
108+ public function construct (): self
109+ {
110+ if (isset ($ this ->staticMethods ['<init> ' ])) {
111+ $ this ->getStaticMethods ()->call ('<init> ' );
112+ }
113+
114+ // reset dynamic fields
115+ $ this ->dynamicFieldAccessor = new JVM \Field \DynamicField (
116+ $ this ,
117+ []
118+ );
119+
120+ $ this ->dynamicMethodAccessor = new JVM \Invoker \DynamicMethodInvoker (
121+ $ this ,
122+ $ this ->dynamicMethods
123+ );
124+
125+ return $ this ;
126+ }
127+
108128 public function getJavaClass (): JavaClass
109129 {
110130 return $ this ->javaClass ;
Original file line number Diff line number Diff line change 22namespace PHPJava \Core \JVM \Field ;
33
44use PHPJava \Core \JavaClassInvoker ;
5+ use PHPJava \Imitation \java \lang \_String ;
6+ use PHPJava \Imitation \java \lang \NoSuchFieldException ;
57
68trait FieldGettable
79{
10+ /**
11+ * @param $name
12+ * @return mixed
13+ * @throws NoSuchFieldException
14+ */
815 public function get (string $ name )
916 {
17+ if (!isset ($ this ->fields [$ name ])) {
18+ throw new NoSuchFieldException ('Get to undefined field ' . $ name );
19+ }
20+ if ($ this ->fields [$ name ] instanceof _String) {
21+ return (string ) $ this ->fields [$ name ];
22+ }
1023 return $ this ->fields [$ name ];
1124 }
1225}
Original file line number Diff line number Diff line change @@ -8,5 +8,6 @@ trait FieldSettable
88 public function set (string $ name , $ value )
99 {
1010 $ this ->fields [$ name ] = $ value ;
11+ return $ this ;
1112 }
1213}
Original file line number Diff line number Diff line change 33
44use PHPJava \Core \JavaClassInvoker ;
55use PHPJava \Imitation \java \lang \_String ;
6- use PHPJava \Imitation \java \lang \NoSuchFieldException ;
76
87class StaticField
98{
10- public $ fields = [];
9+ use FieldGettable;
10+ use FieldSettable;
1111
1212 private $ javaClassInvoker ;
13+ public $ fields = [];
1314
1415 public function __construct (JavaClassInvoker $ javaClassInvoker )
1516 {
1617 $ this ->javaClassInvoker = $ javaClassInvoker ;
1718 }
18-
19- /**
20- * @param $name
21- * @return mixed
22- * @throws NoSuchFieldException
23- */
24- public function get (string $ name )
25- {
26- if (!isset ($ this ->fields [$ name ])) {
27- throw new NoSuchFieldException ('Get to undefined static field ' . $ name );
28- }
29- if ($ this ->fields [$ name ] instanceof _String) {
30- return (string ) $ this ->fields [$ name ];
31- }
32- return $ this ->fields [$ name ];
33- }
34-
35- public function set (string $ name , $ value )
36- {
37- $ this ->fields [$ name ] = $ value ;
38- return $ this ;
39- }
4019}
Original file line number Diff line number Diff line change @@ -5,6 +5,11 @@ class Throwable extends \Exception
55{
66 use \PHPJava \Imitation \PHPJava \Extended \_Object;
77
8+ public function __construct ($ message = "" , $ code = 0 , Throwable $ previous = null )
9+ {
10+ parent ::__construct ($ message , $ code , $ previous );
11+ }
12+
813 public function __toString (): string
914 {
1015 return $ this ->getMessage ();
Original file line number Diff line number Diff line change 99 new \PHPJava \Core \JavaClassReader (__DIR__ . '/Test.class ' )
1010);
1111
12+
13+ var_dump (
14+ $ javaClass ->getInvoker ()
15+ ->construct ()
16+ ->getDynamicFields ()
17+ ->get ('z ' )
18+ );
19+
1220$ javaClass ->getInvoker ()->getStaticFields ()
1321 ->set ('c ' , 100 )
1422 ->set ('b ' , 'New String ' );
You can’t perform that action at this time.
0 commit comments