-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy path_checkcast.php
More file actions
54 lines (44 loc) · 1.5 KB
/
_checkcast.php
File metadata and controls
54 lines (44 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
namespace PHPJava\Kernel\Mnemonics;
use PHPJava\Kernel\Resolvers\TypeResolver;
use PHPJava\Packages\java\lang\ClassCastException;
use PHPJava\Utilities\Formatter;
final class _checkcast extends AbstractOperationCode implements OperationCodeInterface
{
public function getOperands(): ?Operands
{
parent::getOperands();
if ($this->operands !== null) {
return $this->operands;
}
$indexbyte = $this->readUnsignedShort();
return $this->operands = new Operands(
['indexbyte', $indexbyte, ['indexbyte1', 'indexbyte2']]
);
}
/**
* @throws ClassCastException
*/
public function execute(): void
{
parent::execute();
$cp = $this->getConstantPool();
$index = $this->getOperands()['indexbyte'];
$objectref = $this->popFromOperandStack();
if ($objectref === null) {
return;
}
$castTo = $cp[$cp[$index]->getClassIndex()]->getString();
$fromObjectClass = Formatter::convertPHPNamespacesToJava(get_class($objectref));
[$classes, $interfaces] = TypeResolver::getExtendedClasses(
'L' . str_replace('/', '.', $castTo)
)[0] ?? [[], []];
if (in_array($fromObjectClass, $classes, true)) {
return;
}
throw new ClassCastException(
'class \\' . get_class($objectref) . ' cannot be cast to class ' . Formatter::convertJavaNamespaceToPHP($castTo)[1]
);
}
}