Skip to content

Commit 5d404e1

Browse files
committed
WIP
1 parent f8c6719 commit 5d404e1

5 files changed

Lines changed: 52 additions & 6 deletions

File tree

src/core/JavaClassInvoker.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function __construct(JavaClass $javaClass)
3939
$methodName = $cpInfo[$methodInfo->getNameIndex()]->getString();
4040

4141
if (($methodInfo->getAccessFlag() & AccessFlag::_Static) !== 0) {
42-
$this->staticMethods[$methodName] = $methodInfo;
42+
$this->staticMethods[$methodName][] = $methodInfo;
4343
} elseif ($methodInfo->getAccessFlag() === 0 || ($methodInfo->getAccessFlag() & AccessFlag::_Public) !== 0) {
44-
$this->dynamicMethods[$methodName] = $methodInfo;
44+
$this->dynamicMethods[$methodName][] = $methodInfo;
4545
}
4646
}
4747

@@ -88,13 +88,16 @@ public function getStaticMethods(): InvokerInterface
8888
public function getDynamicFields(): FieldInterface
8989
{
9090
return new JVM\Field\DynamicField(
91-
$this
91+
$this,
92+
[]
9293
);
9394
}
9495

9596
public function getStaticFields(): JVM\Field\StaticField
9697
{
97-
return new JVM\Field\StaticField();
98+
return new JVM\Field\StaticField(
99+
$this
100+
);
98101
}
99102

100103
}

src/core/jvm/field/StaticField.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ class StaticField
99
{
1010
private static $fields = [];
1111

12+
private $javaClassInvoker;
13+
14+
public function __construct(JavaClassInvoker $javaClassInvoker)
15+
{
16+
$this->javaClassInvoker = $javaClassInvoker;
17+
}
18+
1219
/**
1320
* @param $name
1421
* @return mixed

src/core/jvm/invoker/Invokable.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPJava\Kernel\Maps\OpCode;
1717
use PHPJava\Kernel\Mnemonics\OperationInterface;
1818
use PHPJava\Kernel\Structures\_MethodInfo;
19+
use PHPJava\Utilities\Formatter;
1920

2021
trait Invokable
2122
{
@@ -50,14 +51,45 @@ public function call(string $name, ...$arguments)
5051
}
5152
return null;
5253
};
54+
5355
/**
5456
* @var _MethodInfo|null $method
5557
*/
56-
$method = $this->methods[$name] ?? null;
57-
if ($method === null) {
58+
$methods = $this->methods[$name] ?? null;
59+
if ($methods === null) {
5860
throw new UndefinedMethodException('Call to undefined ' . $name . ' method.');
5961
}
6062

63+
$constantPool = $this->javaClassInvoker
64+
->getJavaClass()
65+
->getConstantPool()
66+
->getEntries();
67+
68+
$method = $methods[0];
69+
70+
// TODO: Refactor find to valid method.
71+
// will implement to be compatible to multiple variable arguments size.
72+
// And will be applied NoSuchMethodException when cannot find method.
73+
if ($name === 'main') {
74+
// Find same method
75+
foreach ($methods as $method) {
76+
$signature = Formatter::parseSignature($constantPool[$method->getDescriptorIndex()]->getString());
77+
78+
// compare passed arguments
79+
foreach ($signature['arguments'] as $signatureArgument) {
80+
foreach ($arguments as $argument) {
81+
var_dump(gettype($argument), $signatureArgument);
82+
if ($argument === $signatureArgument) {
83+
84+
}
85+
}
86+
}
87+
var_dump();
88+
}
89+
90+
exit();
91+
}
92+
6193
$codeAttribute = $getCodeAttribute($method->getAttributes());
6294

6395
if ($codeAttribute === null) {

tools/Test.class

146 Bytes
Binary file not shown.

tools/test.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ public String testMe (int n, String m, int l, int i, int v, int k) {
294294

295295
}
296296

297+
public static void main (int[] args) {
298+
System.out.println("Called int type main " + args[0]);
299+
}
300+
297301
private int testPrivateInteger (int value) {
298302
return value + 1 * 2 + 3;
299303
}

0 commit comments

Comments
 (0)