All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dakusui.logias.lisp.func.java.Get Maven / Gradle / Ivy

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;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy