44use PHPJava \Exceptions \IllegalJavaClassException ;
55use PHPJava \Exceptions \RuntimeException ;
66use PHPJava \Exceptions \UndefinedOpCodeException ;
7+ use PHPJava \Kernel \Resolvers \MethodNameResolver ;
78
89trait PHPMethodCallable
910{
@@ -24,12 +25,21 @@ public function call(string $name, ...$arguments)
2425 ->getMethods ()
2526 ->callStaticInitializerIfNotInstantiated ();
2627
28+ $ realPHPMethodName = MethodNameResolver::resolve ($ name );
29+
30+ /**
31+ * @var \ReflectionMethod $method
32+ */
2733 $ method = $ this ->findMethod ($ name );
2834
29- $ this ->debugTool ->getLogger ()->debug ('Call method: ' . $ name );
35+ $ suffix = ($ realPHPMethodName !== $ name ? ' (Actual calling is the ' . $ realPHPMethodName . ' method) ' : '' );
36+ $ this ->debugTool ->getLogger ()->debug (
37+ 'Call method: ' . $ name . $ suffix
38+ );
3039
31- if ($ this ->isDynamic () && $ this ->javaClassInvoker ->getClassObject () === null ) {
32- $ this ->javaClassInvoker ->construct ();
40+ if ($ this ->isDynamic () && MethodNameResolver::isConstructorMethod ($ name )) {
41+ $ this ->javaClassInvoker ->construct (...$ arguments );
42+ return $ this ->javaClassInvoker ->getJavaClass ();
3343 }
3444
3545 $ executed = $ method
@@ -38,7 +48,9 @@ public function call(string $name, ...$arguments)
3848 $ arguments
3949 );
4050
41- $ this ->debugTool ->getLogger ()->debug ('Finish operation: ' . $ name );
51+ $ this ->debugTool ->getLogger ()->debug (
52+ 'Finish operation: ' . $ name . $ suffix
53+ );
4254
4355 return $ executed ;
4456 }
0 commit comments