-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathAttributeInfo.php
More file actions
81 lines (68 loc) Β· 2.47 KB
/
AttributeInfo.php
File metadata and controls
81 lines (68 loc) Β· 2.47 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
80
81
<?php
declare(strict_types=1);
namespace PHPJava\Kernel\Attributes;
use PHPJava\Core\JVM\Parameters\GlobalOptions;
use PHPJava\Core\JVM\Parameters\Runtime;
use PHPJava\Exceptions\ValidatorException;
final class AttributeInfo implements AttributeInterface
{
use \PHPJava\Kernel\Core\BinaryReader;
use \PHPJava\Kernel\Core\ConstantPool;
use \PHPJava\Kernel\Core\AttributeReference;
use \PHPJava\Kernel\Core\DebugTool;
/**
* @var int
*/
private $attributeNameIndex;
/**
* @var int
*/
private $attributeLength;
/**
* @var AttributeInterface
*/
private $attributeData;
/**
* @throws ValidatorException
*/
public function execute(): void
{
$loadAttributes = GlobalOptions::get('load_attributes') ?? Runtime::LOAD_ATTRIBUTES;
$this->attributeNameIndex = $this->readUnsignedShort();
$this->attributeLength = $this->readUnsignedInt();
$cpInfo = $this->getConstantPool();
$currentOffset = $this->getOffset();
$attributeName = $cpInfo[$this->attributeNameIndex]->getString();
if ($loadAttributes !== null && !in_array($attributeName, $loadAttributes, true)) {
$this->read($this->attributeLength);
$this->getDebugTool()->getLogger()->debug('Skip to load an attribute: ' . $attributeName);
return;
}
$classAttributeName = '\\PHPJava\\Kernel\\Attributes\\' . $attributeName . 'Attribute';
$this->getDebugTool()->getLogger()->debug('Load an attribute: ' . $attributeName);
$this->attributeData = new $classAttributeName($this->reader);
$this->attributeData->setConstantPool($this->getConstantPool());
$this->attributeData->setDebugTool($this->getDebugTool());
$this->attributeData->setAttributeReference($this);
$this->attributeData->execute();
if ($this->attributeLength != ($actual = $this->getOffset() - $currentOffset)) {
throw new ValidatorException(
'Invalid attribute counter. expect number is ' .
$this->attributeLength .
', but actual number is ' . $actual . '.'
);
}
}
public function getAttributeData(): ?AttributeInterface
{
return $this->attributeData;
}
public function getAttributeNameIndex(): int
{
return $this->attributeNameIndex;
}
public function getAttributeLength(): int
{
return $this->attributeLength;
}
}