From 32cf16b713e6737f8e19ea226f1e8b286f38f1df Mon Sep 17 00:00:00 2001 From: Alan Ruttenberg Date: Wed, 6 Apr 2022 00:02:43 -0400 Subject: [PATCH] Update to javaparser 3.24.2. Fix tests. Fix typo: ignoreable -> ignorable. Have invoke load javaparser first time #1 is used. --- contrib/jss/README.markdown | 12 ++++++++---- contrib/jss/invoke.lisp | 20 ++++++++++++-------- contrib/jss/javaparser-tests.asd | 1 + contrib/jss/javaparser.asd | 2 +- contrib/jss/javaparser.lisp | 10 +++++++--- contrib/jss/jss-tests.asd | 1 + contrib/jss/t/javaparser.lisp | 3 +-- 7 files changed, 31 insertions(+), 18 deletions(-) diff --git a/contrib/jss/README.markdown b/contrib/jss/README.markdown index b14e4b1c1..4b0b74fc9 100644 --- a/contrib/jss/README.markdown +++ b/contrib/jss/README.markdown @@ -106,14 +106,18 @@ lists the names of all methods for the CLASS-NAME. Java static fields may be addressed via the SHARPSIGN-QUOTATION_MARK macro as - (#"{java.lang.System}.{fileSeparator}") + (#"java.lang.System.out") + +Java fields can by dynamically accessed with + + (let ((class 'java.lang.system) + (field "out")) + #"{class}.{field}") ### Javaparser -On the reference of the JAVAPARSER system, one may use a Java DSL to -specify invocation and chains: +Use #1"" to use JAVAPARSER to parse an expression. JAVAPARSER will be loaded on first use. - (asdf:make :javaparser) (#1"new ByteBuddy() .subclass(Object.class,t) .method(ElementMatchers.named("toString")) diff --git a/contrib/jss/invoke.lisp b/contrib/jss/invoke.lisp index 06f0faf87..66875e37e 100644 --- a/contrib/jss/invoke.lisp +++ b/contrib/jss/invoke.lisp @@ -206,14 +206,18 @@ NAME can either string or a symbol according to the usual JSS conventions." (eval-when (:compile-toplevel :load-toplevel :execute) (defun read-invoke (stream char arg) - (unread-char char stream) - (let ((name (read stream))) - (if (or (find #\. name) (find #\{ name)) - (jss-transform-to-field name arg) - (let ((object-var (gensym)) - (args-var (gensym))) - `(lambda (,object-var &rest ,args-var) - (invoke-restargs ,name ,object-var ,args-var ,(eql arg 0))))))) + (if (eql arg 1) + (progn (asdf:make 'javaparser) + (read-sharp-java-expression stream)) + (progn + (unread-char char stream) + (let ((name (read stream))) + (if (or (find #\. name) (find #\{ name)) + (jss-transform-to-field name arg) + (let ((object-var (gensym)) + (args-var (gensym))) + `(lambda (,object-var &rest ,args-var) + (invoke-restargs ,name ,object-var ,args-var ,(eql arg 0))))))))) (set-dispatch-macro-character #\# #\" 'read-invoke)) (defmacro with-constant-signature (fname-jname-pairs &body body) diff --git a/contrib/jss/javaparser-tests.asd b/contrib/jss/javaparser-tests.asd index 1df8f263d..69335626f 100644 --- a/contrib/jss/javaparser-tests.asd +++ b/contrib/jss/javaparser-tests.asd @@ -1,3 +1,4 @@ +(in-package :asdf) (defsystem javaparser-tests :defsystem-depends-on (prove-asdf) :depends-on (javaparser diff --git a/contrib/jss/javaparser.asd b/contrib/jss/javaparser.asd index 1daf62e08..1ef7a8157 100644 --- a/contrib/jss/javaparser.asd +++ b/contrib/jss/javaparser.asd @@ -3,7 +3,7 @@ :defsystem-depends-on (abcl-asdf) :components ((:module jar - :components ((:mvn "com.github.javaparser/javaparser-core/3.0.1"))) + :components ((:mvn "com.github.javaparser/javaparser-core/3.24.2"))) (:module source :depends-on (jar) :pathname "" :serial t diff --git a/contrib/jss/javaparser.lisp b/contrib/jss/javaparser.lisp index 122f8e2ed..ccdc315d8 100644 --- a/contrib/jss/javaparser.lisp +++ b/contrib/jss/javaparser.lisp @@ -2,7 +2,11 @@ (defvar *class-to-last-component* (make-hash-table :test 'equalp)) -(defclass javaparser () ()) +(defclass javaparser () ((parser :accessor parser))) + +(defmethod initialize-instance ((p javaparser)&key) + (call-next-method) + (setf (parser p) (new 'javaparser))) (defmacro def-java-read (ast-class class fields &body body) (let ((jclass (find-java-class (concatenate 'string "com.github.javaparser.ast.expr." (string ast-class))))) @@ -29,7 +33,8 @@ (defmethod read-java-expression ((r javaparser) expression) `(let ((this *object-for-this*)) - ,(process-node r (#"parseExpression" 'javaparser expression)))) + (declare (ignorable this)) + ,(process-node r (#"getResult" (#"parseExpression" (parser r) expression))))) (def-java-read LongLiteralExpr javaparser () (read-from-string (#"replaceFirst" (#"getValue" node) "L" ""))) @@ -65,7 +70,6 @@ (eval-when (:compile-toplevel :load-toplevel :execute) (defun read-invoke/javaparser (stream char arg) (if (eql arg 1) - (if (ignore-errors (jclass "com.github.javaparser.ParseStart")) ;; chosen randomly, TODO memoize (read-sharp-java-expression stream) diff --git a/contrib/jss/jss-tests.asd b/contrib/jss/jss-tests.asd index 1c503ce7e..64a98c92b 100644 --- a/contrib/jss/jss-tests.asd +++ b/contrib/jss/jss-tests.asd @@ -1,4 +1,5 @@ ;;;; -*- Mode: LISP -*- +(in-package :asdf) (defsystem jss-tests :defsystem-depends-on (quicklisp-abcl prove-asdf) diff --git a/contrib/jss/t/javaparser.lisp b/contrib/jss/t/javaparser.lisp index e44073a62..d02d3f8c5 100644 --- a/contrib/jss/t/javaparser.lisp +++ b/contrib/jss/t/javaparser.lisp @@ -1,6 +1,7 @@ (in-package :cl-user) (defparameter expanded '(let ((jss::this jss::*object-for-this*)) + (declare (ignorable jss::this)) (jcall "getLoaded" (jcall "load" (jcall "make" @@ -26,8 +27,6 @@ .load(getClass().getClassLoader()) .getLoaded()" ) -(in-package :jss-test) - (prove:plan 1) (prove:is source expanded)