|
8 | 8 | use PHPJava\Core\JVM\ConstantPool; |
9 | 9 | use PHPJava\Core\JVM\Validations\MagicByte; |
10 | 10 | use PHPJava\Exceptions\ValidatorException; |
| 11 | +use PHPJava\Kernel\Attributes\AttributeInterface; |
| 12 | +use PHPJava\Kernel\Attributes\InnerClassesAttribute; |
11 | 13 | use PHPJava\Kernel\Maps\AccessFlag; |
12 | 14 | use PHPJava\Kernel\Structures\_Utf8; |
13 | 15 | use PHPJava\Utilities\Formatter; |
@@ -62,6 +64,8 @@ class JavaClass |
62 | 64 | */ |
63 | 65 | private $invoker; |
64 | 66 |
|
| 67 | + private $innerClasses = []; |
| 68 | + |
65 | 69 | /** |
66 | 70 | * JavaClass constructor. |
67 | 71 | * @param JavaClassReader $reader |
@@ -94,6 +98,7 @@ public function __construct(JavaClassReader $reader) |
94 | 98 | $this->thisClass = $reader->getBinaryReader()->readUnsignedShort(); |
95 | 99 |
|
96 | 100 | $constantPoolEntries = $this->constantPool->getEntries(); |
| 101 | + |
97 | 102 | $this->className = $constantPoolEntries[$constantPoolEntries[$this->thisClass]->getClassIndex()]; |
98 | 103 |
|
99 | 104 | // read super class |
@@ -127,14 +132,32 @@ public function __construct(JavaClassReader $reader) |
127 | 132 | $this->constantPool |
128 | 133 | ); |
129 | 134 |
|
| 135 | + foreach ($this->activeAttributes->getEntries() as $entry) { |
| 136 | + if ($entry->getAttributeData() instanceof InnerClassesAttribute) { |
| 137 | + $this->innerClasses = array_merge( |
| 138 | + $this->innerClasses, |
| 139 | + $entry->getAttributeData()->getClasses() |
| 140 | + ); |
| 141 | + } |
| 142 | + } |
| 143 | + |
130 | 144 | $this->invoker = new JavaClassInvoker($this); |
131 | 145 | } |
132 | 146 |
|
133 | | - public function getClassName(): string |
| 147 | + public function getClassName(bool $shortName = false): string |
134 | 148 | { |
| 149 | + if ($shortName === true) { |
| 150 | + $split = explode('$', $this->className->getString()); |
| 151 | + return $split[count($split) - 1]; |
| 152 | + } |
135 | 153 | return $this->className->getString(); |
136 | 154 | } |
137 | 155 |
|
| 156 | + public function getInnerClasses(): array |
| 157 | + { |
| 158 | + return $this->innerClasses; |
| 159 | + } |
| 160 | + |
138 | 161 | public function getFields(): array |
139 | 162 | { |
140 | 163 | return $this->activeFields->getEntries(); |
|
0 commit comments