New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1".." reader for more complicated java expressions, using javaparser #52

Closed
wants to merge 3 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+51 −12
Diff settings

Always

Just for now

Viewing a subset of changes. View all
Prev

Add jss hook and test

  • Loading branch information...
alanruttenberg committed Jun 8, 2017
commit 155db3e3fbb19a2969221edce465bf45f1560abe
View
@@ -205,14 +205,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)
(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 (require '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)
(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)
View
@@ -23,8 +23,9 @@
(defun optimized-jss (count)
(loop repeat count do (#"compile" 'regex.Pattern ".*")))
(defun unoptimized-jss (count)
(loop repeat count do (#"compile" 'regex.Pattern ".*")))
(let ((jss::*inhibit-jss-optimization* t))
(defun unoptimized-jss (count)
(loop repeat count do (#"compile" 'regex.Pattern ".*"))))
(defun just-loop (count)
(loop repeat count))
@@ -44,8 +45,8 @@
(plan 1)
(is-type (let ((just-loop (timeit (just-loop 10000))))
(+ 0.0
(print (/ (- (timeit (optimized-jss 10000)) just-loop)
(- (timeit (unoptimized-jss 10000)) just-loop)))))
(/ (- (timeit (optimized-jss 10000)) just-loop)
(- (timeit (unoptimized-jss 10000)) just-loop))))
'(float 0 0.1))
(plan 2)
@@ -58,4 +59,38 @@
(finalize)
(plan 1)
(in-package :jss)
(defparameter expanded '(let ((jss::this jss::*object-for-this*))
(jcall "getLoaded"
(jcall "load"
(jcall "make"
(jcall "intercept"
(jcall "method"
(jcall "subclass"
(new '|ByteBuddy|)
(find-java-class '|Object|)
t)
(jstatic "named"
'|ElementMatchers|
"toString"))
(jstatic "value"
'|FixedValue|
"Hello World!")))
(jcall "getClassLoader"
(jcall "getClass" jss::this))))))
(defparameter source '#1"new ByteBuddy().subclass(Object.class,t)
.method(ElementMatchers.named("toString"))
.intercept(FixedValue.value("Hello World!"))
.make()
.load(getClass().getClassLoader())
.getLoaded()" )
(in-package :jss-test)
(is jss::source
jss::expanded)
(finalize)
ProTip! Use n and p to navigate between commits in a pull request.