1414use PHPJava \Compiler \Lang \Assembler \Traits \Enhancer \Operation \LocalVariableAssignable ;
1515use PHPJava \Compiler \Lang \Assembler \Traits \Enhancer \Operation \LocalVariableLoadable ;
1616use PHPJava \Compiler \Lang \Assembler \Traits \OperationManageable ;
17- use PHPJava \Exceptions \ AssembleStructureException ;
17+ use PHPJava \Compiler \ Lang \ Assembler \ Traits \ ParameterParseable ;
1818use PHPJava \Kernel \Maps \OpCode ;
1919use PHPJava \Kernel \Types \_Void ;
2020use PHPJava \Utilities \ArrayTool ;
21- use PHPJava \Utilities \Formatter ;
2221
2322/**
2423 * @method ClassAssembler getParentAssembler()
@@ -32,6 +31,7 @@ class MethodAssembler extends AbstractAssembler
3231 use LocalVariableAssignable;
3332 use LocalVariableLoadable;
3433 use Bindable;
34+ use ParameterParseable;
3535
3636 protected $ attribute ;
3737
@@ -54,64 +54,22 @@ public function assemble(): void
5454 $ parameters [$ parameter ->var ->name ] = $ parameter ->type ;
5555 }
5656
57- foreach (($ this ->node ->getAttribute ('comments ' ) ?? []) as $ commentAttribute ) {
58- /**
59- * @var \PhpParser\Comment\Doc $commentAttribute
60- */
61- $ documentBlock = \phpDocumentor \Reflection \DocBlockFactory::createInstance ()
62- ->create ($ commentAttribute ->getText ());
63-
64- foreach ($ documentBlock ->getTagsByName ('param ' ) as $ documentParameter ) {
65- /**
66- * @var \phpDocumentor\Reflection\DocBlock\Tags\Param $documentParameter
67- */
68- if (!array_key_exists ($ documentParameter ->getVariableName (), $ parameters )) {
69- // Does not add a variable detail and object ref if local variable parameter is not defined.
70- continue ;
71- }
72-
73- $ type = (string ) $ documentParameter ->getType ();
74-
75- // Update variable detail.
76- $ parameters [$ documentParameter ->getVariableName ()] = [
77- 'type ' => str_replace (
78- '[] ' ,
79- '' ,
80- ltrim (
81- $ type ,
82- '\\'
83- )
84- ),
85- 'deep_array ' => substr_count ($ type , '[] ' ),
86- ];
87-
88- $ className = Formatter::buildSignature (
89- $ parameters [$ documentParameter ->getVariableName ()]['type ' ],
90- $ parameters [$ documentParameter ->getVariableName ()]['deep_array ' ]
91- );
92-
93- $ this ->getEnhancedConstantPool ()
94- ->addClass ($ className );
95-
96- // Fill local storage number.
97- $ this ->assembleAssignVariable (
98- $ documentParameter ->getVariableName (),
99- $ parameters [$ documentParameter ->getVariableName ()]['type ' ],
100- $ parameters [$ documentParameter ->getVariableName ()]['deep_array ' ]
101- );
102- }
103- }
57+ $ parameters = $ this ->parseParameterFromNode (
58+ $ this ->node ,
59+ $ parameters
60+ );
10461
10562 $ descriptorObject = Descriptor::factory ()
10663 // TODO: All method returns void. Will implement return type.
10764 ->setReturn (_Void::class);
10865
10966 foreach ($ parameters as $ keyName => $ value ) {
110- if ($ value === null ) {
111- throw new AssembleStructureException (
112- 'Parameter length are mismatch. '
113- );
114- }
67+ // Fill local storage number.
68+ $ this ->assembleAssignVariable (
69+ $ keyName ,
70+ $ value ['type ' ],
71+ $ value ['deep_array ' ]
72+ );
11573
11674 $ descriptorObject ->addArgument (
11775 $ value ['type ' ],
@@ -148,12 +106,12 @@ public function assemble(): void
148106 }
149107
150108 $ method = (
151- new Method (
152- $ methodAccessFlag ->make (),
153- $ this ->getClassAssembler ()->getClassName (),
154- $ this ->methodName ,
155- $ descriptor
156- )
109+ new Method (
110+ $ methodAccessFlag ->make (),
111+ $ this ->getClassAssembler ()->getClassName (),
112+ $ this ->methodName ,
113+ $ descriptor
114+ )
157115 )
158116 ->setConstantPool ($ this ->getConstantPool ())
159117 ->setConstantPoolFinder ($ this ->getConstantPoolFinder ())
0 commit comments