Skip to content

Commit 4eb00e3

Browse files
committed
Fix mistaken superclass resolver
1 parent b190342 commit 4eb00e3

5 files changed

Lines changed: 48 additions & 17 deletions

File tree

src/Core/JVM/Invoker/Invokable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(JavaClassInvoker $javaClassInvoker, array $methods,
4040
$this->methods = $methods;
4141
$this->options = $options;
4242
$this->debugTool = new DebugTool(
43-
str_replace('/', '.', $javaClassInvoker->getJavaClass()->getClassName(true)),
43+
str_replace('/', '.', $javaClassInvoker->getJavaClass()->getClassName()),
4444
$this->options
4545
);
4646
}

src/Core/JavaClassInterface.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
<?php
22
namespace PHPJava\Core;
3+
use PHPJava\Core\JVM\ConstantPool;
4+
use PHPJava\Core\Stream\Reader\ReaderInterface;
35

6+
/**
7+
* @method __construct(ReaderInterface $reader, array $options = [])
8+
* @method ConstantPool getConstantPool()
9+
* @method JavaClass getSuperClass()
10+
* @method void debug()
11+
* @method array getAttributes()
12+
* @method JavaClass getParentClass()
13+
* @method bool hasParentClass()
14+
* @method JavaClassInvoker getInvoker()
15+
* @method array getDefinedMethods()
16+
* @method array getDefinedFields()
17+
* @method array getInnerClasses()
18+
* @method string getPackageName()
19+
* @method string getClassName(bool $shortName = false)
20+
* @method mixed getOptions($key = null)
21+
*/
422
interface JavaClassInterface
523
{
624
}

src/Core/JavaClassInvoker.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ public function construct(...$arguments): self
106106
);
107107

108108
if (isset($this->dynamicMethods['<init>'])) {
109-
$this->getDynamic()->getMethods()->call('<init>', ...$arguments);
109+
$this->getDynamic()->getMethods()->call(
110+
'<init>',
111+
...$arguments
112+
);
110113
}
111114

112115
return $this;

src/Utilities/ClassResolver.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,26 @@ public function resolve(string $javaPath, JavaClass $class = null): array
4646
case static::RESOURCE_TYPE_INNER_CLASS:
4747
// TODO: Implement here
4848
break;
49+
case static::RESOURCE_TYPE_JAR:
50+
if (($key = array_search($relativePath, $this->resolvedPaths, true)) !== false) {
51+
return $this->resolvedPaths[$relativePath];
52+
}
53+
/**
54+
* @var JavaArchive $value
55+
*/
56+
try {
57+
return $this->resolvedPaths[] = [
58+
static::RESOLVED_TYPE_CLASS,
59+
$value->getClassByName($relativePath),
60+
];
61+
} catch (ClassNotFoundException $e) {
62+
}
63+
break;
4964
case static::RESOURCE_TYPE_FILE:
5065
$path = realpath($value . '/' . $relativePath . '.class');
66+
if ($path === false) {
67+
break;
68+
}
5169
if (($key = array_search($path, $this->resolvedPaths, true)) !== false) {
5270
return $this->resolvedPaths[$key];
5371
}
@@ -68,18 +86,6 @@ public function resolve(string $javaPath, JavaClass $class = null): array
6886
];
6987
}
7088
break;
71-
case static::RESOURCE_TYPE_JAR:
72-
/**
73-
* @var JavaArchive $value
74-
*/
75-
try {
76-
return $this->resolvedPaths[] = [
77-
static::RESOLVED_TYPE_CLASS,
78-
$value->getClassByName($relativePath),
79-
];
80-
} catch (ClassNotFoundException $e) {
81-
}
82-
break;
8389
case static::RESOURCE_TYPE_CLASS:
8490
/**
8591
* @var ReaderInterface $value

src/Utilities/SuperClassResolver.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
namespace PHPJava\Utilities;
33

44
use PHPJava\Core\JavaClass;
5+
use PHPJava\Core\JavaClassInterface;
56
use PHPJava\Core\JVM\FlexibleMethod;
67

78
class SuperClassResolver
89
{
910
private $classes = [];
1011
private $constantPool;
1112

12-
public function resolveMethod($methodName, JavaClass $class)
13+
public function resolveMethod($methodName, JavaClassInterface $class)
1314
{
1415
$cpInfo = $class->getConstantPool();
15-
if ($class->getSuperClass() instanceof JavaClass) {
16+
if ($class->getSuperClass() instanceof JavaClassInterface) {
1617
foreach ($class->getSuperClass()->getInvoker()->getDynamic()->getMethods()->getList() as $calleeMethodName => $callee) {
1718
if ($methodName !== $calleeMethodName) {
1819
continue;
@@ -36,6 +37,9 @@ public function resolveMethod($methodName, JavaClass $class)
3637
[new FlexibleMethod($class->getSuperClass(), $callee)]
3738
);
3839
}
39-
return array_merge($prependItems, $this->classes);
40+
return array_merge(
41+
$prependItems,
42+
$this->classes
43+
);
4044
}
4145
}

0 commit comments

Comments
 (0)