-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemberInvokeOperator.java
More file actions
48 lines (43 loc) · 1.6 KB
/
MemberInvokeOperator.java
File metadata and controls
48 lines (43 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package examples;
import static org.ugp.serialx.Serializer.InvokeFunc;
import static org.ugp.serialx.Serializer.indexOfNotInObj;
import static org.ugp.serialx.Serializer.splitValues;
import java.lang.reflect.InvocationTargetException;
import org.ugp.serialx.JussSerializer;
import org.ugp.serialx.converters.DataParser;
import org.ugp.serialx.converters.ObjectConverter;
/**
* This is example of more advanced parser! It can be used for calling non-static methods from objects via "->" operator!<br>
* For example with this parser registered with {@link JussSerializer#JUSS_PARSERS} you can print out hello world in JUSS like <code>System::out->println "Hello world"</code><br>
* Note: This is only for demonstration purposes and not a real feature so its not fully compatible with JUSS syntax so you will have to use () quiet often depending on where you put this parser!
*
* @author PETO
*
* @serial 1.3.5
*/
public class MemberInvokeOperator implements DataParser
{
@Override
public Object parse(ParserRegistry myHomeRegistry, String str, Object... args)
{
int index;
if ((index = indexOfNotInObj(str, "->", false)) > 0)
{
Object obj = myHomeRegistry.parse(str.substring(0, index).trim(), args);
String[] funcArgs = splitValues(str.substring(index+2).trim(), ' ');
try
{
return InvokeFunc(obj, funcArgs[0], ObjectConverter.parseAll(myHomeRegistry, funcArgs, 1, true, args));
}
catch (InvocationTargetException e)
{
throw new RuntimeException(e);
}
catch (Exception e2)
{
return null;
}
}
return CONTINUE;
}
}