-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathElementValue.php
More file actions
79 lines (73 loc) Β· 2.44 KB
/
ElementValue.php
File metadata and controls
79 lines (73 loc) Β· 2.44 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
declare(strict_types=1);
namespace PHPJava\Kernel\Structures\Annotations;
use PHPJava\Exceptions\RuntimeException;
final class ElementValue implements AnnotationInterface
{
use \PHPJava\Kernel\Core\BinaryReader;
use \PHPJava\Kernel\Core\ConstantPool;
use \PHPJava\Kernel\Core\DebugTool;
/**
* @var string
*/
private $tag;
/**
* @var int|int[]|(int|static[])[]|Annotation
*/
private $value;
/**
* @throws RuntimeException
* @see https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html#jvms-4.7.16
*/
public function execute(): void
{
$this->tag = chr($this->readByte());
switch ($this->tag) {
case 'B': // const_value_index
case 'C':
case 'D':
case 'F':
case 'I':
case 'J':
case 'S':
case 'Z':
case 's':
$this->value = $this->readUnsignedShort();
break;
case 'e': // enum_const_value
$this->value = [
'type_name_index' => $this->readUnsignedShort(),
'const_name_index' => $this->readUnsignedShort(),
];
break;
case 'c': // class_info_index
$this->value = $this->readUnsignedShort();
break;
case '@': // annotation_value
$this->value = new Annotation($this->reader);
$this->value->setConstantPool($this->getConstantPool());
$this->value->setDebugTool($this->getDebugTool());
$this->value->execute();
break;
case '[': // array_value
$this->value = [
'num_values' => $this->readUnsignedShort(),
'values' => [],
];
for ($i = 0; $i < $this->value['num_values']; $i++) {
$value = new static($this->reader);
$value->setConstantPool($this->getConstantPool());
$value->setDebugTool($this->getDebugTool());
$value->execute();
$this->value['values'][] = $value;
}
break;
default:
throw new RuntimeException('Invalid tag "' . $this->tag . '" in element_value structure.');
}
}
public function getValue()
{
return $this->value;
}
}