Changeset 4523
- Timestamp:
- 10/24/03 00:05:13 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/lisp/Java.java
r4514 r4523 3 3 * 4 4 * Copyright (C) 2002-2003 Peter Graves 5 * $Id: Java.java,v 1.1 2 2003-10-23 15:01:41piso Exp $5 * $Id: Java.java,v 1.13 2003-10-24 00:05:13 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 25 25 import java.lang.reflect.InvocationTargetException; 26 26 import java.lang.reflect.Method; 27 import java.lang.reflect.Field; 27 28 import java.lang.reflect.Modifier; 28 29 … … 30 31 { 31 32 // ### jclass 32 private static final Primitive1 JCLASS = 33 new Primitive1("jclass", PACKAGE_JAVA){33 private static final Primitive1 JCLASS = new Primitive1("jclass", PACKAGE_JAVA) 34 { 34 35 public LispObject execute(LispObject arg) throws ConditionThrowable 35 36 { … … 39 40 catch (ClassNotFoundException e) { 40 41 throw new ConditionThrowable(new LispError("class not found: " + arg)); 42 } 43 catch (Throwable t) { 44 throw new ConditionThrowable(new LispError(getMessage(t))); 45 } 46 } 47 }; 48 49 // ### jfield 50 // jfield class-name field-name &optional instance 51 private static final Primitive JFIELD = new Primitive("jfield", PACKAGE_JAVA) 52 { 53 public LispObject execute(LispObject[] args) throws ConditionThrowable 54 { 55 if (args.length < 2 || args.length > 3) 56 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 57 String className = LispString.getValue(args[0]); 58 String fieldName = LispString.getValue(args[1]); 59 Object instance = null; 60 try { 61 final Class c = Class.forName(className); 62 final Field f = c.getField(fieldName); 63 if (args.length == 3) { 64 if (args[2] instanceof LispString) 65 instance = LispString.getValue(args[2]); 66 else 67 instance = JavaObject.getObject(args[2]); 68 } 69 return makeLispObject(f.get(instance)); 70 } 71 catch (ClassNotFoundException e) { 72 throw new ConditionThrowable(new LispError("class not found: " + className)); 73 } 74 catch (NoSuchFieldException e) { 75 throw new ConditionThrowable(new LispError("no such field")); 76 } 77 catch (SecurityException e) { 78 throw new ConditionThrowable(new LispError("inaccessible field")); 79 } 80 catch (IllegalAccessException e) { 81 throw new ConditionThrowable(new LispError("illegal access")); 82 } 83 catch (IllegalArgumentException e) { 84 throw new ConditionThrowable(new LispError("illegal argument")); 41 85 } 42 86 catch (Throwable t) { … … 49 93 // jconstructor class-name &rest parameter-class-names 50 94 private static final Primitive JCONSTRUCTOR = 51 new Primitive("jconstructor", PACKAGE_JAVA) { 95 new Primitive("jconstructor", PACKAGE_JAVA) 96 { 52 97 public LispObject execute(LispObject[] args) throws ConditionThrowable 53 98 { … … 78 123 // ### jmethod 79 124 // jmethod class-ref name &rest parameter-class-names 80 private static final Primitive JMETHOD = 81 new Primitive("jmethod", PACKAGE_JAVA){125 private static final Primitive JMETHOD = new Primitive("jmethod", PACKAGE_JAVA) 126 { 82 127 public LispObject execute(LispObject[] args) throws ConditionThrowable 83 128 { … … 129 174 // ### jstatic 130 175 // jstatic method class &rest args 131 private static final Primitive JSTATIC = 132 new Primitive("jstatic", PACKAGE_JAVA){176 private static final Primitive JSTATIC = new Primitive("jstatic", PACKAGE_JAVA) 177 { 133 178 public LispObject execute(LispObject[] args) throws ConditionThrowable 134 179 { … … 208 253 else if (arg instanceof LispFloat) 209 254 initargs[i-1] = new Double(((LispFloat)arg).getValue()); 255 else if (arg instanceof JavaObject) 256 initargs[i-1] = ((JavaObject)arg).getObject(); 210 257 } 211 258 return new JavaObject(constructor.newInstance(initargs)); … … 326 373 static { 327 374 export("JCLASS", PACKAGE_JAVA); 375 export("JFIELD", PACKAGE_JAVA); 328 376 export("JCONSTRUCTOR", PACKAGE_JAVA); 329 377 export("JMETHOD", PACKAGE_JAVA);
Note: See TracChangeset
for help on using the changeset viewer.