com.github.dakusui.logias.lisp.func.java.Get Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of logiaslisp Show documentation
Show all versions of logiaslisp Show documentation
A JSON based Lisp processor.
The newest version!
package com.github.dakusui.logias.lisp.func.java;
import java.lang.reflect.Field;
import com.github.dakusui.logias.lisp.s.Literal;
import com.github.dakusui.logias.lisp.s.Sexp;
public class Get extends Accessor {
public Get(boolean b) {
super(b);
}
@Override
protected Sexp perform(Object target, Field field, Object valueToAssign) {
Sexp ret = Sexp.nil;
try {
Object v;
if (isStatic()) {
v = field.get(null);
} else {
v = field.get(target);
}
if (v instanceof Boolean) {
if (Boolean.TRUE.equals(v)) {
ret = Sexp.T;
} else {
ret = Sexp.nil;
}
} else {
ret = new Literal(v);
}
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
return ret;
}
@Override
protected int numParams() {
return 2;
}
}