Skip to content

Commit d2fc9e5

Browse files
committed
WIP commit
1 parent 9d9572f commit d2fc9e5

4 files changed

Lines changed: 44 additions & 17 deletions

File tree

src/Core/JVM/FlexibleMethod.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace PHPJava\Core\JVM;
3+
4+
class FlexibleMethod
5+
{
6+
private $method;
7+
8+
public function __construct(\ReflectionMethod $method)
9+
{
10+
$this->method = $method;
11+
}
12+
}

src/Core/JVM/Invoker/Invokable.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use PHPJava\Core\JavaClass;
55
use PHPJava\Core\JavaClassInvoker;
6+
use PHPJava\Core\JVM\FlexibleMethod;
67
use PHPJava\Core\JVM\Stream\BinaryReader;
78
use PHPJava\Exceptions\IllegalJavaClassException;
89
use PHPJava\Exceptions\RuntimeException;
@@ -97,6 +98,11 @@ function ($argument) {
9798
$method = null;
9899

99100
foreach ($methodReferences as $methodReference) {
101+
// If flexible method is available then Invoker use it all time.
102+
if ($methodReference instanceof FlexibleMethod) {
103+
$method = $methodReference;
104+
break;
105+
}
100106
$constantPool = ($currentConstantPool = $methodReference->getConstantPool())->getEntries();
101107
/**
102108
* @var _MethodInfo $methodReference
@@ -114,6 +120,14 @@ function ($argument) {
114120
throw new NoSuchMethodException('Call to undefined method ' . $name . '.');
115121
}
116122

123+
if ($method instanceof FlexibleMethod) {
124+
/**
125+
* @var FlexibleMethod $method
126+
*/
127+
// TODO: will implement invocation for flexible method
128+
return $method->invoke();
129+
}
130+
117131
$codeAttribute = $getCodeAttribute($method->getAttributes());
118132

119133
if ($codeAttribute === null) {

src/Utilities/SuperClassResolver.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use PHPJava\Core\JavaClass;
55
use PHPJava\Core\JVM\ConstantPool;
6+
use PHPJava\Core\JVM\FlexibleMethod;
67
use PHPJava\Imitation\java\lang\_Object;
78

89
class SuperClassResolver
@@ -25,22 +26,18 @@ public function resolveMethod($methodName, JavaClass $class)
2526
}
2627
return $this->resolveMethod($methodName, $class->getSuperClass());
2728
}
28-
// TODO: Will implement extends imitation classes
29-
// elseif (!($class->getSuperClass() instanceof _Object)) {
30-
// $this->classes = array_merge($this->classes, array_map(
31-
// function ($method) use ($class) {
32-
// return static::convertToCallable($method, $class->getSuperClass());
33-
// },
34-
// (new \ReflectionClass($class->getSuperClass()))->getMethods()
35-
// ));
36-
// return $this->resolveAll($class->getSuperClass());
37-
// }
38-
// $this->classes = array_merge($this->classes, array_map(
39-
// function ($method) use ($class) {
40-
// return static::convertToCallable($method, $class->getSuperClass());
41-
// },
42-
// (new \ReflectionClass($class->getSuperClass()))->getMethods()
43-
// ));
44-
return $this->classes;
29+
30+
$prependItems = [];
31+
foreach ((new \ReflectionClass($class->getSuperClass()))->getMethods() as $callee) {
32+
$resolvedMethodName = $callee->getName();
33+
if (!isset($prependItems[$resolvedMethodName])) {
34+
$prependItems[$resolvedMethodName] = [];
35+
}
36+
$prependItems[$resolvedMethodName] = array_merge(
37+
$prependItems[$resolvedMethodName],
38+
[new FlexibleMethod($callee)]
39+
);
40+
}
41+
return array_merge($prependItems, $this->classes);
4542
}
4643
}

src/Utilities/TypeResolver.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class TypeResolver
99
const PHP_TYPE_MAP = [
1010
'integer' => 'I',
1111
'string' => 'Ljava.lang.String',
12+
'NULL' => '#',
1213
];
1314

1415
const SIGNATURE_MAP = [
@@ -22,6 +23,9 @@ class TypeResolver
2223
'V' => 'void',
2324
'Z' => 'boolean',
2425
'L' => 'class',
26+
27+
// TEMP: various type
28+
'#' => 'none',
2529
];
2630

2731
/**

0 commit comments

Comments
 (0)