55use PHPJava \Core \JVM \StaticAccessor ;
66use PHPJava \Exceptions \IllegalJavaClassException ;
77use PHPJava \Kernel \Maps \FieldAccessFlag ;
8+ use PHPJava \Kernel \Maps \MethodAccessFlag ;
89use PHPJava \Kernel \Provider \ProviderInterface ;
910use PHPJava \Kernel \Structures \_FieldInfo ;
1011use PHPJava \Kernel \Structures \_MethodInfo ;
12+ use PHPJava \Utilities \Normalizer ;
1113
1214class JavaClassInvoker
1315{
@@ -17,22 +19,22 @@ class JavaClassInvoker
1719 private $ javaClass ;
1820
1921 /**
20- * @var _MethodInfo
22+ * @var _MethodInfo[]
2123 */
2224 private $ dynamicMethods = [];
2325
2426 /**
25- * @var _MethodInfo
27+ * @var _MethodInfo[]
2628 */
2729 private $ staticMethods = [];
2830
2931 /**
30- * @var _FieldInfo
32+ * @var _FieldInfo[]
3133 */
3234 private $ dynamicFields = [];
3335
3436 /**
35- * @var _FieldInfo
37+ * @var _FieldInfo[]
3638 */
3739 private $ staticFields = [];
3840
@@ -71,34 +73,45 @@ public function __construct(
7173 $ cpInfo = $ javaClass ->getConstantPool ();
7274
7375 foreach ($ javaClass ->getDefinedMethods () as $ methodInfo ) {
76+ /**
77+ * @var _MethodInfo $methodInfo
78+ */
7479 $ methodName = $ cpInfo [$ methodInfo ->getNameIndex ()]->getString ();
7580
76- if (($ methodInfo ->getAccessFlag () & FieldAccessFlag ::ACC_STATIC ) !== 0 ) {
81+ if (($ methodInfo ->getAccessFlag () & MethodAccessFlag ::ACC_STATIC ) !== 0 ) {
7782 $ this ->staticMethods [$ methodName ][] = $ methodInfo ;
78- } elseif ( $ methodInfo -> getAccessFlag () === 0 || ( $ methodInfo -> getAccessFlag () & FieldAccessFlag:: ACC_PUBLIC ) !== 0 ) {
83+ } else {
7984 $ this ->dynamicMethods [$ methodName ][] = $ methodInfo ;
8085 }
8186 }
8287
8388 foreach ($ javaClass ->getDefinedFields () as $ fieldInfo ) {
89+ /**
90+ * @var _FieldInfo $fieldInfo
91+ */
8492 $ fieldName = $ cpInfo [$ fieldInfo ->getNameIndex ()]->getString ();
8593
86- if ($ fieldInfo ->getAccessFlag () === 0 ) {
87- $ this ->dynamicFields [$ fieldName ] = $ fieldInfo ;
88- } elseif (($ fieldInfo ->getAccessFlag () & FieldAccessFlag::ACC_STATIC ) !== 0 ) {
94+ if (($ fieldInfo ->getAccessFlag () & FieldAccessFlag::ACC_STATIC ) !== 0 ) {
8995 $ this ->staticFields [$ fieldName ] = $ fieldInfo ;
96+ } else {
97+ $ this ->dynamicFields [$ fieldName ] = $ fieldInfo ;
9098 }
9199 }
92100
93101 $ this ->dynamicAccessor = new DynamicAccessor (
94102 $ this ,
95103 $ this ->dynamicMethods ,
104+ [],
96105 $ this ->options
97106 );
98107
99108 $ this ->staticAccessor = new StaticAccessor (
100109 $ this ,
101110 $ this ->staticMethods ,
111+ Normalizer::normalizeFields (
112+ $ this ->staticFields ,
113+ $ this ->javaClass
114+ ),
102115 $ this ->options
103116 );
104117 }
@@ -111,15 +124,17 @@ public function construct(...$arguments): self
111124 $ this ->dynamicAccessor = new DynamicAccessor (
112125 $ this ,
113126 $ this ->dynamicMethods ,
127+ Normalizer::normalizeFields (
128+ $ this ->dynamicFields ,
129+ $ this ->javaClass
130+ ),
114131 $ this ->options
115132 );
116133
117- if (isset ($ this ->dynamicMethods ['<init> ' ])) {
118- $ this ->getDynamic ()->getMethods ()->call (
119- '<init> ' ,
120- ...$ arguments
121- );
122- }
134+ $ this ->getDynamic ()->getMethods ()->call (
135+ '<init> ' ,
136+ ...$ arguments
137+ );
123138
124139 return $ this ;
125140 }
@@ -136,18 +151,11 @@ public function getDynamic(): DynamicAccessor
136151
137152 public function getStatic (): StaticAccessor
138153 {
139- return $ this ->staticAccessor ;
140- }
141-
142- public function isInvoked (string $ name , string $ signature ): bool
143- {
144- return in_array ($ signature , $ this ->specialInvoked [$ name ] ?? [], true );
145- }
154+ $ this ->staticAccessor
155+ ->getMethods ()
156+ ->callStaticInitializerIfNotInstantiated ();
146157
147- public function addToSpecialInvokedList (string $ name , string $ signature ): self
148- {
149- $ this ->specialInvoked [$ name ][] = $ signature ;
150- return $ this ;
158+ return $ this ->staticAccessor ;
151159 }
152160
153161 /**
0 commit comments