Changeset 15066


Ignore:
Timestamp:
06/09/17 19:26:28 (6 years ago)
Author:
Mark Evenson
Message:

Further fixes for JSS

JAVAPARSER now "stacks" its macro definition on the existing one it
inherits from JSS.

Refactor all tests to just pollute CL-USER where necessary (strictly
speaking it shouldn't be necessary as all PROVE tests should be able
to use lexical bindings.

Document existence of Java field access via SHARPSIGN-QUOTATION_MARK,
e.g.

(#"{java.lang.System}.{fileSeparator}")

and the new Java DSL

(asdf:make :javaparser)
(#"'#1"new ByteBuddy?()

.subclass(Object.class,t)
.method(ElementMatchers?.named("toString"))
.intercept(FixedValue?.value("Hello World!"))
.make()
.load(getClass().getClassLoader())
.getLoaded()"

Location:
trunk/abcl/contrib/jss
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/contrib/jss/README.markdown

    r14587 r15066  
    5353An interactive restart is available to resolve class ambiguity.
    5454
    55 Static calls are possible as well with the #" macro, but the
    56 first argument MUST BE A SYMBOL to distinguish
     55Static calls are possible as well with the SHARPSIGN-QUOTATION_MARK
     56macro, but the first argument *must* be a symbol to distinguish
    5757
    5858     (#"getProperties" "java.lang.System")
     
    9797the moment (lazy)
    9898
    99 (japropos string) finds all class names matching string
     99    (japropos string)
    100100
    101 (jcmn class-name) lists the names of all methods for the class
     101finds all class names matching STRING.
    102102
     103    (jcmn class-name)
     104   
     105lists the names of all methods for the CLASS-NAME.
     106
     107Java static fields may be addressed via the SHARPSIGN-QUOTATION_MARK macro as
     108 
     109    (#"{java.lang.System}.{fileSeparator}")
     110 
     111### Javaparser
     112
     113On the reference of the JAVAPARSER system, one may use a Java DSL to
     114specify invocation and chains:
     115
     116    (asdf:make :javaparser)
     117    (#"'#1"new ByteBuddy()
     118      .subclass(Object.class,t)
     119      .method(ElementMatchers.named("toString"))
     120      .intercept(FixedValue.value("Hello World!"))
     121      .make()
     122      .load(getClass().getClassLoader())
     123      .getLoaded()"
     124   
    103125Compatibility
    104126-------------
     
    134156<> dc:created "2005" ;
    135157   dc:author "Mark <evenson.not.org@gmail.com>";
    136    dc:revised "06-DEC-2012" ;
    137    <> abcl:documents <urn:abcl.org/release/1.3.0-dev/contrib/jss#3.0.5" .
     158   dc:revised "09-JUN-2017" ;
     159   asdf:long-description <urn:abcl.org/release/1.5.0/contrib/jss/README.markdown#3.3.0>" .
    138160
    139161   
  • trunk/abcl/contrib/jss/javaparser.lisp

    r15065 r15066  
    6666  (defun read-invoke/javaparser (stream char arg)
    6767    (if (eql arg 1)
    68         (if (ignore-errors (jclass "com.github.javaparser.ParseStart")) ;; chosen randomly, TODO memoize
     68
     69        (if (ignore-errors
     70              (jclass "com.github.javaparser.ParseStart"))         ;; chosen randomly, TODO memoize
    6971            (read-sharp-java-expression stream)
    7072            ;; Deal with possiblity of not loading jar
    7173            (error "Cannot load javaparser code needed for the #1 macro"))
    72   (progn
    73     (unread-char char stream)
    74     (let ((name (read stream)))
    75       (if (or (find #\. name) (find #\{ name))
    76     (jss-transform-to-field name)
    77     (let ((object-var (gensym))
    78           (args-var (gensym)))
    79       `(lambda (,object-var &rest ,args-var)
    80          (invoke-restargs ,name  ,object-var ,args-var ,(eql arg 0)))))))))
     74        (read-invoke stream char arg)))
    8175  (set-dispatch-macro-character #\# #\" 'read-invoke/javaparser))
    8276
  • trunk/abcl/contrib/jss/jss.asd

    r15046 r15066  
    33  :author "Alan Ruttenberg, Mark Evenson"
    44  :long-description "<urn:abcl.org/release/1.5.0/contrib/jss#>"
    5   :version "3.2.4"
     5  :version "3.3.0"
    66  :components ((:module base :pathname "" :serial t
    77                        :components ((:file "packages")
  • trunk/abcl/contrib/jss/t/javaparser.lisp

    r15065 r15066  
    11(in-package :cl-user)
    2 
    3 #+(or) ;;
    4 (in-package :jss)
    52
    63(defparameter expanded '(let ((jss::this jss::*object-for-this*))
     
    3330
    3431(prove:plan 1)
    35 (proveis jss::source
    36     jss::expanded)
     32(prove:is source expanded)
    3733
    3834(prove:finalize)
  • trunk/abcl/contrib/jss/t/jss-tests.lisp

    r15065 r15066  
    11(in-package :cl-user)
    22
    3 (defpackage jss-test
    4   (:use :cl :cl-user :jss :prove))
     3(prove:plan 6)
    54
    6 (in-package :jss-test)
    7 
    8 (plan 6)
    9 
    10 (is (read-from-string "#\"{bar}.{foo}\"") '(get-java-field bar foo t))
    11 (is (read-from-string "#\"q.bar.{foo}\"") '(get-java-field (load-time-value (find-java-class "q.bar")) foo t))
    12 (is (read-from-string "#\"{bar}.foo\"") '(get-java-field bar "foo" t))
    13 (is-error (read-from-string "#\".bar.foo\"") 'simple-error)
     5(prove:is
     6 (read-from-string "#\"{bar}.{foo}\"")
     7 '(get-java-field bar foo t))
     8(prove:is
     9 (read-from-string "#\"q.bar.{foo}\"")
     10 '(get-java-field (load-time-value (find-java-class "q.bar")) foo t))
     11(prove:is
     12 (read-from-string "#\"{bar}.foo\"")
     13 '(get-java-field bar "foo" t))
     14(prove:is-error
     15 (read-from-string "#\".bar.foo\"")
     16 'simple-error)
    1417;;; http://abcl.org/trac/ticket/205
    15 (is (with-constant-signature ((substring "substring")) (substring "01234" 2)) "234")
     18(prove:is
     19 (with-constant-signature ((substring "substring"))
     20   (substring "01234" 2)) "234")
    1621;;; http://abcl.org/trac/ticket/229 - note: version of test for this ticket was broken in tests.lisp
    17 (is (#"toString" (find "size"
    18       (#"getMethods" (find-java-class "java.util.Collections$UnmodifiableMap"))
    19     :test 'string-equal :key #"getName"))
     22(prove:is (#"toString"
     23           (find "size" (#"getMethods" (find-java-class "java.util.Collections$UnmodifiableMap"))
     24                 :test 'string-equal :key #"getName"))
    2025    (#"toString" (java::jmethod "java.util.Collections$UnmodifiableMap" "size" )))
    2126
    2227;; test that optimized jss is much faster than unoptimized
    23 (defun optimized-jss (count)
    24   (loop repeat count do (#"compile" 'regex.Pattern ".*")))
     28(let ()
     29  (defun optimized-jss (count)
     30    (loop repeat count do (#"compile" 'regex.Pattern ".*")))
     31  (let ((jss::*inhibit-jss-optimization* t))
     32    (defun unoptimized-jss (count)
     33      (loop repeat count do (#"compile" 'regex.Pattern ".*"))))
     34  (defun just-loop (count)
     35    (loop repeat count))
     36  (let ((jss::*inhibit-jss-optimization* nil))
     37    (compile 'just-loop)
     38    (compile 'optimized-jss))
     39  (let ((jss::*inhibit-jss-optimization* t))
     40    (compile 'unoptimized-jss))
    2541
    26 (let ((jss::*inhibit-jss-optimization* t))
    27   (defun unoptimized-jss (count)
    28   (loop repeat count do (#"compile" 'regex.Pattern ".*"))))
     42  (defmacro timeit (&body body)
     43    `(let ((start (#"currentTimeMillis" 'system)))
     44       ,@body
     45       (- (#"currentTimeMillis" 'system) start)))
    2946
    30 (defun just-loop (count)
    31   (loop repeat count))
    32 
    33 (let ((jss::*inhibit-jss-optimization* nil))
    34   (compile 'just-loop)
    35   (compile 'optimized-jss))
    36 (let ((jss::*inhibit-jss-optimization* t))
    37   (compile 'unoptimized-jss))
    38 
    39 (defmacro timeit (&body body)
    40   `(let ((start (#"currentTimeMillis" 'system)))
    41     ,@body
    42     (- (#"currentTimeMillis" 'system) start)))
    43 
    44 
    45 (plan 1)
    46 (is-type (let ((just-loop (timeit (just-loop 10000))))
     47  (prove:plan 1)
     48  (prove:is-type (let ((just-loop (timeit (just-loop 10000))))
    4749     (+ 0.0
    4850        (/ (-  (timeit (optimized-jss 10000)) just-loop)
    4951      (-  (timeit (unoptimized-jss 10000)) just-loop))))
    50    '(float 0 0.1))
     52                 '(float 0 0.1)
     53                 "Testing JSS compiler optimization
"))
    5154
    52 (plan 2)
     55(prove:plan 2)
    5356(let* ((jss::*inhibit-jss-optimization* nil)
    54        (optimized-jss (macroexpand (precompiler::precompile-form '(#"compile" 'regex.Pattern ".*") t))))
     57       (optimized-jss
     58        (macroexpand (precompiler::precompile-form
     59                                    '(#"compile" 'regex.Pattern ".*") t))))
    5560  (let* ((jss::*inhibit-jss-optimization* t)
    56          (unoptimized-jss (macroexpand (precompiler::precompile-form '(#"compile" 'regex.Pattern ".*") t))))
    57     (is (car optimized-jss) 'java:jstatic)
    58     (is (caar unoptimized-jss) 'lambda)))
     61         (unoptimized-jss
     62          (macroexpand (precompiler::precompile-form '(#"compile" 'regex.Pattern ".*") t))))
     63    (prove:is (car optimized-jss) 'java:jstatic)
     64    (prove:is (caar unoptimized-jss) 'lambda)))
    5965
    60 (finalize)
     66(prove:finalize)
    6167
Note: See TracChangeset for help on using the changeset viewer.