Changeset 14326


Ignore:
Timestamp:
12/17/12 15:22:09 (8 years ago)
Author:
Mark Evenson
Message:

Refactor java.beans.* out of Java.java.

Enables patches for building on Android to exclude source by
file-level compilation units.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Java.java

    r14239 r14326  
    3636import static org.armedbear.lisp.Lisp.*;
    3737
    38 import java.beans.BeanInfo;
    39 import java.beans.IntrospectionException;
    40 import java.beans.Introspector;
    41 import java.beans.PropertyDescriptor;
    4238import java.lang.reflect.Array;
    4339import java.lang.reflect.Constructor;
     
    12421238    };
    12431239
    1244     private static final Primitive JGET_PROPERTY_VALUE = new pf__jget_property_value();
    1245     @DocString(name="%jget-propety-value", args="java-object property-name",
    1246     doc="Gets a JavaBeans property on JAVA-OBJECT.\n" +
    1247         "SYSTEM-INTERNAL: Use jproperty-value instead.")
    1248     private static final class pf__jget_property_value extends Primitive
    1249     {
    1250         pf__jget_property_value()
    1251         {
    1252       super("%jget-property-value", PACKAGE_JAVA, false,
    1253                   "java-object property-name");
    1254         }
    1255      
    1256         @Override
    1257         public LispObject execute(LispObject javaObject, LispObject propertyName) {
    1258       try {
    1259         Object obj = javaObject.javaInstance();
    1260         PropertyDescriptor pd = getPropertyDescriptor(obj, propertyName);
    1261         Object value = pd.getReadMethod().invoke(obj);
    1262         if(value instanceof LispObject) {
    1263             return (LispObject) value;
    1264         } else if(value != null) {
    1265             return JavaObject.getInstance(value, true);
    1266         } else {
    1267             return NIL;
    1268         }
    1269       } catch (Exception e) {
    1270                 return error(new JavaException(e));
    1271       }
    1272         }
    1273     };
    1274    
    1275     private static final Primitive JSET_PROPERTY_VALUE = new pf__jset_property_value();
    1276     @DocString(name="%jset-propety-value", args="java-object property-name value",
    1277     doc="Sets a JavaBean property on JAVA-OBJECT.\n" +
    1278         "SYSTEM-INTERNAL: Use (setf jproperty-value) instead.")
    1279     private static final class pf__jset_property_value extends Primitive
    1280     {
    1281         pf__jset_property_value()
    1282         {
    1283       super("%jset-property-value", PACKAGE_JAVA, false,
    1284                   "java-object property-name value");
    1285         }
    1286      
    1287         @Override
    1288         public LispObject execute(LispObject javaObject, LispObject propertyName, LispObject value) {
    1289       Object obj = null;
    1290       try {
    1291     obj = javaObject.javaInstance();
    1292     PropertyDescriptor pd = getPropertyDescriptor(obj, propertyName);
    1293     Object jValue;
    1294     //TODO maybe we should do this in javaInstance(Class)
    1295     if(value instanceof JavaObject) {
    1296         jValue = value.javaInstance();
    1297     } else {
    1298         if(Boolean.TYPE.equals(pd.getPropertyType()) ||
    1299            Boolean.class.equals(pd.getPropertyType())) {
    1300       jValue = value != NIL;
    1301         } else {
    1302       jValue = value != NIL ? value.javaInstance() : null;
    1303         }
    1304     }
    1305     pd.getWriteMethod().invoke(obj, jValue);
    1306     return value;
    1307       } catch (Exception e) {
    1308             return error(new JavaException(e));
    1309       }
    1310         }
    1311     };
    1312 
    13131240    private static final Primitive JRUN_EXCEPTION_PROTECTED = new pf_jrun_exception_protected();
    13141241    @DocString(name="jrun-exception-protected", args="closure",
     
    13391266    };
    13401267
    1341     static PropertyDescriptor getPropertyDescriptor(Object obj, LispObject propertyName) throws IntrospectionException {
    1342         String prop = ((AbstractString) propertyName).getStringValue();
    1343         BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
    1344         for(PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
    1345           if(pd.getName().equals(prop)) {
    1346             return pd;
    1347           }
    1348         }
    1349         error(new LispError("Property " + prop + " not found in " + obj));
    1350 
    1351         return null; // not reached
    1352     }
    1353    
    13541268    private static Class classForName(String className) {
    13551269  return classForName(className, JavaClassLoader.getPersistentInstance());
Note: See TracChangeset for help on using the changeset viewer.