Changeset 12831


Ignore:
Timestamp:
07/28/10 22:13:15 (12 years ago)
Author:
astalla
Message:

First stab at Java collections integration with the sequences protocol.

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

Legend:

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

    r12755 r12831  
    9898        if (type == BuiltInClass.JAVA_OBJECT)
    9999            return T;
    100   if(type.typep(LispClass.findClass(JAVA_CLASS, false)) != NIL) {
     100  LispObject cls = NIL;
     101  if(type instanceof Symbol) {
     102      cls = LispClass.findClass(type, false);
     103  }
     104  if(cls == NIL) {
     105      cls = type;
     106  }
     107  if(cls.typep(LispClass.findClass(JAVA_CLASS, false)) != NIL) {
    101108      if(obj != null) {
    102     Class c = (Class) JAVA_CLASS_JCLASS.execute(type).javaInstance();
     109    Class c = (Class) JAVA_CLASS_JCLASS.execute(cls).javaInstance();
    103110    return c.isAssignableFrom(obj.getClass()) ? T : NIL;
    104111      } else {
    105112    return T;
    106113      }
     114  } else if(cls == BuiltInClass.SEQUENCE) {
     115      //This information is replicated here from java.lisp; it is a very
     116      //specific case, not worth implementing CPL traversal in typep
     117      if(java.util.List.class.isInstance(obj) ||
     118         java.util.Set.class.isInstance(obj)) {
     119    return T;
     120      }
    107121  }
    108122        return super.typep(type);
    109123    }
    110 
    111124
    112125    @Override
  • trunk/abcl/src/org/armedbear/lisp/compile-system.lisp

    r12624 r12831  
    187187                           ;;"j.lisp"
    188188                           "java.lisp"
     189                           "java-collections.lisp"
    189190                           "known-functions.lisp"
    190191                           "known-symbols.lisp"
  • trunk/abcl/src/org/armedbear/lisp/java.lisp

    r12774 r12831  
    149149        method implementation)))))
    150150    lisp-this))
     151
     152(defun jequal (obj1 obj2)
     153  "Compares obj1 with obj2 using java.lang.Object.equals()"
     154  (jcall (jmethod "java.lang.Object" "equals" "java.lang.Object")
     155   obj1 obj2))
    151156
    152157(defun jobject-class (obj)
     
    364369             :java-class +java-lang-object+)))
    365370
     371(defun jclass-additional-superclasses (jclass)
     372  "Extension point to put additional CLOS classes on the CPL of a CLOS Java class."
     373  (let ((supers nil))
     374    (when (jclass-interface-p jclass)
     375      (push (find-class 'java-object) supers))
     376    (when (jequal jclass (jclass "java.util.List"))
     377      (push (find-class 'sequence) supers))
     378    supers))
     379
    366380(defun ensure-java-class (jclass)
    367381  (let ((class (%find-java-class jclass)))
     
    379393                 (list (jclass-superclass jclass))
    380394                 (jclass-interfaces jclass))))))
    381        (if (jclass-interface-p jclass)
    382            (append supers (list (find-class 'java-object)))
    383            supers))
     395       (append supers (jclass-additional-superclasses jclass)))
    384396     :java-class jclass)))))
    385397
Note: See TracChangeset for help on using the changeset viewer.