44import com .scriptbasic .executors .commands .CommandMethod ;
55import com .scriptbasic .interfaces .AnalysisException ;
66import com .scriptbasic .interfaces .Expression ;
7+ import com .scriptbasic .interfaces .ExpressionList ;
78import com .scriptbasic .interfaces .ScriptBasicKeyWords ;
89import com .scriptbasic .spi .Command ;
910import com .scriptbasic .utility .ExpressionUtility ;
@@ -29,42 +30,68 @@ public CommandAnalyzerMethod(final Context ctx) {
2930 */
3031 @ Override
3132 public Command analyze () throws AnalysisException {
32- final var methodName = ExpressionUtility
33- . convertToString ( analyzeExpression ());
33+ final String methodName = getMethodName ();
34+
3435 LexUtility .checkLexeme (ctx .lexicalAnalyzer , ScriptBasicKeyWords .KEYWORD_FROM ,
3536 "Keyword 'FROM' is missing in command 'METHOD'" );
36- final var className = ExpressionUtility
37- . convertToString ( analyzeExpression () );
37+
38+ final String className = getClassName ( );
3839
3940 LexUtility .checkLexeme (ctx .lexicalAnalyzer , ScriptBasicKeyWords .KEYWORD_IS ,
4041 "Keyword 'IS' is missing in command 'METHOD'" );
4142 LexUtility .checkLexeme (ctx .lexicalAnalyzer , "(" ,
4243 "'(' is missing in command 'METHOD' after the keyword 'IS'" );
4344
44- final var argExpressions = ctx .expressionListAnalyzer .analyze ();
45+ final var argClasses = getArgClasses ();
46+
4547 LexUtility .checkLexeme (ctx .lexicalAnalyzer , ")" ,
4648 "')' is missing in command 'METHOD'" );
49+
50+ final String alias = getAlias (methodName );
51+
52+ final var node = new CommandMethod ();
53+ node .setArgumentTypes (argClasses .toArray (new Class <?>[0 ]));
54+ node .setKlass (KlassUtility .forNameEx (className ));
55+ node .setMethodName (methodName );
56+ node .setAlias (alias );
57+ consumeEndOfStatement ();
58+
59+ return node ;
60+ }
61+
62+ private String getAlias (String methodName ) throws AnalysisException {
4763 final String alias ;
4864 if (LexUtility .isLexeme (ctx .lexicalAnalyzer , ScriptBasicKeyWords .KEYWORD_USE )) {
4965 LexUtility .checkLexeme (ctx .lexicalAnalyzer , ScriptBasicKeyWords .KEYWORD_AS ,
5066 "Keyword 'AS' is missung after 'USE in command 'METHOD'" );
51- alias = ExpressionUtility . convertToString ( analyzeExpression () );
67+ alias = getString ( );
5268 } else {
5369 alias = methodName ;
5470 }
71+ return alias ;
72+ }
73+
74+ private String getClassName () throws AnalysisException {
75+ return getString ();
76+ }
77+
78+ private String getString () throws AnalysisException {
79+ return ExpressionUtility
80+ .convertToString (analyzeExpression ());
81+ }
82+
83+ private String getMethodName () throws AnalysisException {
84+ return getString ();
85+ }
86+
87+ private ArrayList <Class <?>> getArgClasses () throws AnalysisException {
88+ final var argExpressions = ctx .expressionListAnalyzer .analyze ();
5589 final ArrayList <Class <?>> argClasses = new ArrayList <>();
5690 for (final Expression expression : argExpressions ) {
5791 final var argClassName = ExpressionUtility .convertToString (expression );
5892 argClasses .add (KlassUtility .forNameEx (argClassName ));
5993 }
60- final var node = new CommandMethod ();
61- node .setArgumentTypes (argClasses .toArray (new Class <?>[0 ]));
62- node .setKlass (KlassUtility .forNameEx (className ));
63- node .setMethodName (methodName );
64- node .setAlias (alias );
65- consumeEndOfStatement ();
66-
67- return node ;
94+ return argClasses ;
6895 }
6996
7097}
0 commit comments