ArrayGet.java 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package gnu.kawa.reflect;
  2. import gnu.bytecode.*;
  3. import gnu.mapping.*;
  4. import java.io.*;
  5. import java.lang.reflect.Array;
  6. public class ArrayGet extends Procedure2 implements Externalizable {
  7. Type element_type;
  8. public ArrayGet(Type element_type) {
  9. this.element_type = element_type;
  10. setProperty(Procedure.validateApplyKey,
  11. "gnu.kawa.reflect.CompileArrays:validateArrayGet");
  12. setProperty(Procedure.compilerXKey,
  13. "gnu.kawa.reflect.CompileArrays:compileGet");
  14. }
  15. public Object apply2 (Object array, Object index)
  16. {
  17. Object value = Array.get(array, ((Number) index).intValue());
  18. return element_type.coerceToObject(value);
  19. }
  20. public boolean isSideEffectFree ()
  21. {
  22. return true;
  23. }
  24. public void writeExternal(ObjectOutput out) throws IOException
  25. {
  26. out.writeObject(element_type);
  27. }
  28. public void readExternal(ObjectInput in)
  29. throws IOException, ClassNotFoundException
  30. {
  31. element_type = (Type) in.readObject();
  32. }
  33. }