Package de.tuhrig.thofu.java

Source Code of de.tuhrig.thofu.java.LJInstanceField

package de.tuhrig.thofu.java;

import org.apache.commons.lang3.reflect.FieldUtils;

import de.tuhrig.thofu.Environment;
import de.tuhrig.thofu.types.LException;
import de.tuhrig.thofu.types.LList;
import de.tuhrig.thofu.types.LObject;
import de.tuhrig.thofu.types.LSymbol;

/**
* Represents an instance field.
*
* @author Thomas Uhrig (tuhrig.de)
*/
public class LJInstanceField extends LJava {

  private LJObject object;
 
  private String fieldName;
 
  public LJInstanceField(LSymbol key) {

    fieldName = key.toString();
   
    fieldName = fieldName.substring(1, fieldName.length()).replace("$", "");
  }

  @Override
  public LObject evaluate(Environment environment, LObject tokens) {

    if(object == null) {
     
      try {
       
        LList tmp = (LList) tokens;

        object = (LJObject) tmp.get(0).run(environment, tokens);

        this.result = FieldUtils.readDeclaredField(object.getJObject(), fieldName);
      }
      catch (Exception e) {

        throw new LException("[" + e.getClass() + "] - " + e.getMessage(), e);
      }
    }
   
    return this;
  }
 
  @Override
  public int argrumentSize(LObject tokens) {

    return -1;
  }
}
TOP

Related Classes of de.tuhrig.thofu.java.LJInstanceField

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.