Skip to content

Commit 8fc7dae

Browse files
committed
Enhance invokeinterface that enable to use default syntax in interface
1 parent a290351 commit 8fc7dae

22 files changed

+461
-82
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
namespace PHPJava\Core\JVM\Invoker\Extended;
3+
4+
use PHPJava\Core\JVM\Invoker\Extended\Specifics\JavaMethodSpecifics;
5+
use PHPJava\Core\JVM\Invoker\Extended\Specifics\MethodSpecificsInterface;
6+
7+
trait JavaMethodSpecifiable
8+
{
9+
public function getSpecifics(string $methodName, ...$arguments): MethodSpecificsInterface
10+
{
11+
$methodInfo = $this->findMethod(
12+
$methodName,
13+
...$arguments
14+
);
15+
16+
return new JavaMethodSpecifics(
17+
$methodInfo
18+
);
19+
}
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
namespace PHPJava\Core\JVM\Invoker\Extended;
3+
4+
use PHPJava\Core\JVM\Invoker\Extended\Specifics\MethodSpecificsInterface;
5+
use PHPJava\Core\JVM\Invoker\Extended\Specifics\PHPMethodSpecifics;
6+
7+
trait PHPMethodSpecifiable
8+
{
9+
public function getSpecifics(string $methodName, ...$arguments): MethodSpecificsInterface
10+
{
11+
return new PHPMethodSpecifics(
12+
$this->findMethod(
13+
$methodName
14+
)
15+
);
16+
}
17+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
namespace PHPJava\Core\JVM\Invoker\Extended\Specifics;
3+
4+
use PHPJava\Kernel\Maps\MethodAccessFlag;
5+
use PHPJava\Kernel\Structures\_MethodInfo;
6+
7+
class JavaMethodSpecifics implements MethodSpecificsInterface
8+
{
9+
/**
10+
* @var _MethodInfo
11+
*/
12+
private $methodInfo;
13+
14+
public function __construct(_MethodInfo $methodInfo)
15+
{
16+
$this->methodInfo = $methodInfo;
17+
}
18+
19+
public function isAbstract(): bool
20+
{
21+
return ($this->methodInfo->getAccessFlag() & MethodAccessFlag::ACC_ABSTRACT) !== 0;
22+
}
23+
24+
public function isStatic(): bool
25+
{
26+
return ($this->methodInfo->getAccessFlag() & MethodAccessFlag::ACC_STATIC) !== 0;
27+
}
28+
29+
public function isFinal(): bool
30+
{
31+
return ($this->methodInfo->getAccessFlag() & MethodAccessFlag::ACC_FINAL) !== 0;
32+
}
33+
34+
public function isPublic(): bool
35+
{
36+
return ($this->methodInfo->getAccessFlag() & MethodAccessFlag::ACC_PUBLIC) !== 0;
37+
}
38+
39+
public function isPrivate(): bool
40+
{
41+
return ($this->methodInfo->getAccessFlag() & MethodAccessFlag::ACC_PRIVATE) !== 0;
42+
}
43+
44+
public function isProtected(): bool
45+
{
46+
return ($this->methodInfo->getAccessFlag() & MethodAccessFlag::ACC_PROTECTED) !== 0;
47+
}
48+
49+
public function isBridge(): bool
50+
{
51+
return ($this->methodInfo->getAccessFlag() & MethodAccessFlag::ACC_BRIDGE) !== 0;
52+
}
53+
54+
public function isNative(): bool
55+
{
56+
return ($this->methodInfo->getAccessFlag() & MethodAccessFlag::ACC_NATIVE) !== 0;
57+
}
58+
59+
public function isStrict(): bool
60+
{
61+
return ($this->methodInfo->getAccessFlag() & MethodAccessFlag::ACC_STRICT) !== 0;
62+
}
63+
64+
public function isSynchronized(): bool
65+
{
66+
return ($this->methodInfo->getAccessFlag() & MethodAccessFlag::ACC_SYNCHRONIZED) !== 0;
67+
}
68+
69+
public function isSynthetic(): bool
70+
{
71+
return ($this->methodInfo->getAccessFlag() & MethodAccessFlag::ACC_SYNTHETIC) !== 0;
72+
}
73+
74+
public function isVarargs(): bool
75+
{
76+
return ($this->methodInfo->getAccessFlag() & MethodAccessFlag::ACC_VARARGS) !== 0;
77+
}
78+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
namespace PHPJava\Core\JVM\Invoker\Extended\Specifics;
3+
4+
interface MethodSpecificsInterface
5+
{
6+
public function isAbstract(): bool;
7+
8+
public function isStatic(): bool;
9+
10+
public function isFinal(): bool;
11+
12+
public function isPublic(): bool;
13+
14+
public function isPrivate(): bool;
15+
16+
public function isProtected(): bool;
17+
18+
public function isBridge(): bool;
19+
20+
public function isNative(): bool;
21+
22+
public function isStrict(): bool;
23+
24+
public function isSynchronized();
25+
26+
public function isSynthetic();
27+
28+
public function isVarargs();
29+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
namespace PHPJava\Core\JVM\Invoker\Extended\Specifics;
3+
4+
class PHPMethodSpecifics implements MethodSpecificsInterface
5+
{
6+
private $methodInfo;
7+
8+
public function __construct(\ReflectionMethod $methodInfo)
9+
{
10+
$this->methodInfo = $methodInfo;
11+
}
12+
13+
public function isAbstract(): bool
14+
{
15+
return $this->methodInfo->isAbstract();
16+
}
17+
18+
public function isStatic(): bool
19+
{
20+
return $this->methodInfo->isStatic();
21+
}
22+
23+
public function isFinal(): bool
24+
{
25+
return $this->methodInfo->isFinal();
26+
}
27+
28+
public function isPublic(): bool
29+
{
30+
return $this->methodInfo->isPublic();
31+
}
32+
33+
public function isPrivate(): bool
34+
{
35+
return $this->methodInfo->isPrivate();
36+
}
37+
38+
public function isProtected(): bool
39+
{
40+
return $this->methodInfo->isProtected();
41+
}
42+
43+
public function isBridge(): bool
44+
{
45+
return false;
46+
}
47+
48+
public function isNative(): bool
49+
{
50+
return false;
51+
}
52+
53+
public function isStrict(): bool
54+
{
55+
return false;
56+
}
57+
58+
public function isSynchronized(): bool
59+
{
60+
return false;
61+
}
62+
63+
public function isSynthetic(): bool
64+
{
65+
return false;
66+
}
67+
68+
public function isVarargs(): bool
69+
{
70+
return false;
71+
}
72+
}

src/Core/JVM/Invoker/InvokerInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace PHPJava\Core\JVM\Invoker;
33

44
use PHPJava\Core\JVM\ClassInvokerInterface;
5+
use PHPJava\Core\JVM\Invoker\Extended\Specifics\MethodSpecificsInterface;
56

67
interface InvokerInterface
78
{
@@ -24,4 +25,6 @@ public function has(string $name): bool;
2425
public function callStaticInitializerIfNotInstantiated(): InvokerInterface;
2526

2627
public function getAnnotations(string $name): array;
28+
29+
public function getSpecifics(string $methodName, ...$arguments): MethodSpecificsInterface;
2730
}

src/Core/JVM/Invoker/JavaClassMethodInvoker.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class JavaClassMethodInvoker implements InvokerInterface
1414
use Extended\ArgumentsStringifyable;
1515
use Extended\StaticConstructorInitializable;
1616
use Extended\JavaMethodAnnotationAffectable;
17+
use Extended\JavaMethodSpecifiable;
1718

1819
/**
1920
* @var ClassInvokerInterface

src/Core/JVM/Invoker/PHPClassMethodInvoker.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class PHPClassMethodInvoker implements InvokerInterface
1313
use Extended\StaticConstructorInitializable;
1414
use Extended\PHPMethodAnnotationAffectable;
1515
use Extended\PHPMethodFindable;
16+
use Extended\PHPMethodSpecifiable;
1617

1718
/**
1819
* @var ClassInvokerInterface

src/Core/JVM/JavaClassInvoker.php

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

47+
/**
48+
* @var array
49+
*/
50+
private $innerClasses = [];
51+
4752
/**
4853
* @throws \PHPJava\Exceptions\NormalizerException
4954
*/

src/Core/JavaArchive.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
namespace PHPJava\Core;
33

44
use PHPJava\Core\JVM\Parameters\Runtime;
5-
use PHPJava\Core\Stream\Reader\InlineReader;
65
use PHPJava\Exceptions\UndefinedEntrypointException;
7-
use PHPJava\Kernel\Internal\JavaClassDeferredLoader;
6+
use PHPJava\Kernel\Internal\JavaInlineClassDeferredLoader;
87
use PHPJava\Kernel\Resolvers\ClassResolver;
98
use PHPJava\Kernel\Resolvers\FileTypeResolver;
109
use PHPJava\Packages\java\io\FileNotFoundException;
@@ -127,8 +126,7 @@ function ($fileName) {
127126
continue;
128127
}
129128
$classPath = str_replace('/', '.', $className);
130-
$this->classes[$classPath] = new JavaClassDeferredLoader(
131-
InlineReader::class,
129+
$this->classes[$classPath] = new JavaInlineClassDeferredLoader(
132130
[$className, $code],
133131
$this->options
134132
);

0 commit comments

Comments
 (0)