-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathMethods.php
More file actions
57 lines (49 loc) · 2.13 KB
/
Methods.php
File metadata and controls
57 lines (49 loc) · 2.13 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
<?php
declare(strict_types=1);
namespace PHPJava\Compiler\Builder\Segments;
use PHPJava\Compiler\Builder\Method;
use PHPJava\Compiler\Builder\Segments\Attributes\Attributes;
use PHPJava\Compiler\Builder\Segments\Attributes\AttributesCount;
use PHPJava\Compiler\Builder\Structures\Info\Utf8Info;
use PHPJava\Exceptions\CompilerException;
class Methods extends AbstractSegment implements SegmentInterface
{
public function build(): void
{
foreach ($this->classFileStructureBuilder->getMethods() as $method) {
/**
* @var Method $method
*/
$name = $this->classFileStructureBuilder->getConstantPool()[$method->getNameIndex()];
$descriptor = $this->classFileStructureBuilder->getConstantPool()[$method->getDescriptorIndex()];
if (!($name instanceof Utf8Info)) {
throw new CompilerException(
'The method entry is not implemented by Utf8Info. (index: ' . $method->getNameIndex() . ', Segment: ' . __CLASS__ . ')'
);
}
if (!($descriptor instanceof Utf8Info)) {
throw new CompilerException(
'The method entry is not implemented by Utf8Info. (index: ' . $method->getDescriptorIndex() . ', Segment: ' . __CLASS__ . ')'
);
}
$this->binaryWriter->writeUnsignedShort($method->getAccessFlags());
$this->binaryWriter->writeUnsignedShort($method->getNameIndex());
$this->binaryWriter->writeUnsignedShort($method->getDescriptorIndex());
// Build attributes_count
AttributesCount::init(
$method->getAttributes(),
$this->classFileStructureBuilder->getConstantPool(),
$this->binaryWriter
)->build();
if (count($method->getAttributes()) === 0) {
continue;
}
// Build attributes
Attributes::init(
$method->getAttributes(),
$this->classFileStructureBuilder->getConstantPool(),
$this->binaryWriter
)->build();
}
}
}