Skip to content

Commit a9beda6

Browse files
committed
if included native annotation then dependency inject with Constant Pool and JavaClass to method.
1 parent aba49a3 commit a9beda6

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"php-java/java-net-package": "*",
2323
"php-java/java-nio-package": "*",
2424
"gabrielelana/byte-units": "dev-master",
25-
"symfony/console": "4.2"
25+
"symfony/console": "4.2",
26+
"phpdocumentor/reflection-docblock": "4.3"
2627
},
2728
"autoload": {
2829
"psr-4": {

src/Kernel/Mnemonics/_invokevirtual.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,24 @@ public function execute(): void
4848
...$arguments
4949
);
5050
} else {
51-
$result = call_user_func_array(
52-
[
53-
TypeResolver::convertPHPTypeToJavaType($invokerClass),
54-
$methodName
55-
],
51+
$reflectionClass = new \ReflectionClass($invokerClass);
52+
$methodAccessor = $reflectionClass->getMethod($methodName);
53+
54+
// parse PHPDoc
55+
$documentBlock = \phpDocumentor\Reflection\DocBlockFactory::createInstance()
56+
->create($methodAccessor->getDocComment());
57+
58+
// Native annotation will dependency inject.
59+
if (!empty($documentBlock->getTagsByName('native'))) {
60+
array_unshift(
61+
$arguments,
62+
$this->getConstantPool(),
63+
$this->javaClass
64+
);
65+
}
66+
67+
$result = $methodAccessor->invokeArgs(
68+
$invokerClass,
5669
$arguments
5770
);
5871
}

0 commit comments

Comments
 (0)