22namespace PHPJava \Utilities ;
33
44use PHPJava \Core \JavaClass ;
5+ use PHPJava \Core \JVM \Parameters \Runtime ;
56use PHPJava \Exceptions \TypeException ;
6- use PHPJava \Imitation \java \lang \_String ;
7+ use PHPJava \Imitation \java \lang \_Object ;
78use PHPJava \Kernel \Types \Type ;
89
910class TypeResolver
@@ -108,10 +109,10 @@ public static function convertPHPtoJava($arguments, $defaultJavaArgumentType = '
108109 'deep_array ' => $ deepArray ,
109110 ];
110111 }
111- if ($ arguments instanceof _String ) {
112+ if ($ arguments instanceof _Object ) {
112113 return [
113114 'type ' => 'class ' ,
114- 'class_name ' => ' java.lang.String ' ,
115+ 'class_name ' => ClassResolver:: resolveNameByPath ( $ arguments ) ,
115116 'deep_array ' => $ deepArray ,
116117 ];
117118 }
@@ -130,4 +131,46 @@ public static function convertPHPtoJava($arguments, $defaultJavaArgumentType = '
130131 'deep_array ' => $ deepArray ,
131132 ];
132133 }
134+
135+ public static function compare (string $ a , string $ b ): bool
136+ {
137+ if ($ a === $ b ) {
138+ return true ;
139+ }
140+
141+ return Formatter::buildArgumentsSignature (static ::getRootClasses ($ a )) === Formatter::buildArgumentsSignature (static ::getRootClasses ($ b ));
142+ }
143+
144+ public static function getRootClasses ($ class )
145+ {
146+ $ result = [];
147+ foreach (Formatter::parseSignature ($ class ) as $ signature ) {
148+ if ($ signature ['type ' ] !== 'class ' ) {
149+ $ result [] = $ signature ;
150+ continue ;
151+ }
152+ $ path = [];
153+ foreach (explode ('. ' , $ signature ['class_name ' ]) as $ name ) {
154+ $ path [] = Runtime::PHP_IMITATION_MAPS [$ name ] ?? $ name ;
155+ }
156+ $ classPath = Runtime::PHP_IMITATION_DIRECTORY . '\\' . implode ('\\' , $ path );
157+
158+ $ rootClass = $ classPath ;
159+ while (($ getRootClass = get_parent_class ($ rootClass )) !== false ) {
160+ $ rootClass = $ getRootClass ;
161+ }
162+ $ newClassName = explode ('. ' , str_replace ([Runtime::PHP_IMITATION_DIRECTORY . '\\' , '\\' ], ['' , '. ' ], $ rootClass ));
163+ foreach ($ newClassName as $ key => $ value ) {
164+ $ newClassName [$ key ] = array_flip (Runtime::PHP_IMITATION_MAPS )[$ value ] ?? $ value ;
165+ }
166+
167+ $ newClassName = implode ('. ' , $ newClassName );
168+ $ result [] = [
169+ 'class_name ' => $ newClassName ,
170+ 'deep_array ' => 0 ,
171+ ] + $ signature ;
172+ }
173+
174+ return $ result ;
175+ }
133176}
0 commit comments