Skip to content

Commit e677122

Browse files
committed
Fix #179; enable to reads fields on SuperClass
1 parent 36b0c48 commit e677122

22 files changed

Lines changed: 179 additions & 71 deletions

src/Core/JVM/ClassInvokerInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ public function getDynamic(): AccessorInterface;
2727
public function getStatic(): AccessorInterface;
2828

2929
public function getProvider(string $providerName): ProviderInterface;
30+
31+
public function getClassObject();
3032
}

src/Core/JVM/Field/FieldInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ public function __construct(ClassInvokerInterface $javaClassInvoker, array $fiel
1010
public function get(string $name);
1111

1212
public function set(string $name, $value);
13+
14+
public function getList(): array;
1315
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace PHPJava\Core\JVM\Field;
3+
4+
trait FieldListable
5+
{
6+
public function getList(): array
7+
{
8+
return $this->fields;
9+
}
10+
}

src/Core/JVM/Field/JavaDynamicField.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class JavaDynamicField implements FieldInterface
77
{
88
use FieldGettable;
99
use FieldSettable;
10+
use FieldListable;
1011

1112
/**
1213
* @var ClassInvokerInterface

src/Core/JVM/Field/JavaStaticField.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class JavaStaticField implements FieldInterface
77
{
88
use FieldGettable;
99
use FieldSettable;
10+
use FieldListable;
1011

1112
/**
1213
* @var ClassInvokerInterface

src/Core/JVM/Field/PHPDynamicField.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
class PHPDynamicField implements FieldInterface
99
{
10+
use FieldListable;
11+
1012
/**
1113
* @var ClassInvokerInterface|PHPClassInvoker
1214
*/

src/Core/JVM/Field/PHPStaticField.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
class PHPStaticField implements FieldInterface
88
{
9+
use FieldListable;
10+
911
/**
1012
* @var ClassInvokerInterface
1113
*/

src/Core/JVM/JavaClassInvoker.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ class JavaClassInvoker implements ClassInvokerInterface
4444
*/
4545
private $options = [];
4646

47-
public function __construct(
48-
JavaClassInterface $javaClass,
49-
array $options
50-
) {
47+
/**
48+
* @throws \PHPJava\Exceptions\NormalizerException
49+
*/
50+
public function __construct(JavaClassInterface $javaClass, array $options)
51+
{
5152
$this->javaClass = $javaClass;
5253
$this->options = $options;
54+
$cpInfo = $this->javaClass->getConstantPool();
5355

54-
$cpInfo = $javaClass->getConstantPool();
55-
56-
foreach ($javaClass->getDefinedMethods() as $methodInfo) {
56+
foreach ($this->javaClass->getDefinedMethods() as $methodInfo) {
5757
/**
5858
* @var _MethodInfo $methodInfo
5959
*/
@@ -66,7 +66,7 @@ public function __construct(
6666
}
6767
}
6868

69-
foreach ($javaClass->getDefinedFields() as $fieldInfo) {
69+
foreach ($this->javaClass->getDefinedFields() as $fieldInfo) {
7070
/**
7171
* @var _FieldInfo $fieldInfo
7272
*/
@@ -84,7 +84,10 @@ public function __construct(
8484
JavaClassDynamicMethodInvoker::class,
8585
JavaDynamicField::class,
8686
$this->dynamicMethods,
87-
[],
87+
Normalizer::normalizeFields(
88+
$this->dynamicFields,
89+
$this->javaClass
90+
),
8891
$this->options
8992
);
9093

@@ -122,4 +125,12 @@ public function construct(...$arguments): ClassInvokerInterface
122125

123126
return $this;
124127
}
128+
129+
/**
130+
* @return JavaClassInterface
131+
*/
132+
public function getClassObject()
133+
{
134+
return $this->javaClass;
135+
}
125136
}

src/Core/JVM/Stream/BinaryReader.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public function readUnsignedShort(): int
6565

6666
public function readInt(): int
6767
{
68-
$bytes = array_values(unpack('c4', $this->read(4)));
69-
return ($bytes[0] << 24) | ($bytes[1] << 16) | ($bytes[2] << 8) | $bytes[3];
68+
return current(unpack('N', $this->read(4)));
7069
}
7170

7271
public function readShort(): int

src/Core/JavaCompiledClass.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,12 @@ public function __construct(ReaderInterface $reader, array $options = [])
240240
]);
241241
}
242242

243-
$this->debugTool->getLogger()->info('End of Class');
244-
245243
$this->invoker = new JavaClassInvoker(
246244
$this,
247245
$options
248246
);
247+
248+
$this->debugTool->getLogger()->info('End of Class');
249249
}
250250

251251
public function __debugInfo()
@@ -312,16 +312,14 @@ public function getDefinedMethods(): array
312312

313313
public function getDefinedExtendedClasses(): array
314314
{
315-
$beforeClass = null;
316-
$currentClass = Formatter::convertPHPNamespacesToJava($this->getClassName());
317315
$parents = [];
318-
var_dump($parents);
319-
for (;;) {
320-
$parents[] = $currentClass = $this->getSuperClass();
321-
var_dump($currentClass);
322-
exit();
316+
$currentClassObject = $this;
317+
while ($parentClass = $currentClassObject->getSuperClass()) {
318+
$parents[] = Formatter::convertPHPNamespacesToJava($parentClass->getClassName());
319+
$currentClassObject = $parentClass;
323320
}
324-
return [];
321+
$parents[] = Formatter::convertPHPNamespacesToJava($this->getClassName());
322+
return $parents;
325323
}
326324

327325
public function getDefinedInterfaceClasses(): array

0 commit comments

Comments
 (0)