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

New macro with-class-lookup-disambiguated #57

wants to merge 1 commit into
base: master
Jump to file or symbol
Failed to load files and symbols.
+29 −2
Diff settings


Just for now

New macro e.g. (with-class-lookup-disambiguated (lang.object) (find-j…

…ava-class 'object)) -> success (otherwise error: ambiguous)
  • Loading branch information...
alanruttenberg committed Jun 15, 2017
commit 5103d57822691d74c66b80c754f8438df6806bba
@@ -245,11 +245,29 @@ want to avoid the overhead of the dynamic dispatch."
(with-constant-signature ,(cdr fname-jname-pairs)
(defvar *class-lookup-overrides*)
(defmacro with-class-lookup-disambiguated (overrides &body body)
"Suppose you have code that references class using the symbol 'object, and this is ambiguous. E.g. in my system java.lang.Object, org.omg.CORBA.Object. Use (with-class-lookup-disambiguated (lang.object) ...). Within dynamic scope, find-java-class first sees if any of these match, and if so uses them to lookup the class."
`(let ((*class-lookup-overrides* ',overrides))
(defun maybe-found-in-overridden (name)
(when (boundp '*class-lookup-overrides*)
(let ((found (find-if (lambda(el) (#"matches" (string el) (concatenate 'string "(?i).*" (string name) "$")))
(if found
(let ((*class-lookup-overrides* nil))
(lookup-class-name found))))))
(defun lookup-class-name (name
(table *class-name-to-full-case-insensitive*)
(muffle-warning nil)
(return-ambiguous nil))
(let ((overridden (maybe-found-in-overridden name)))
(when overridden (return-from lookup-class-name overridden)))
(setq name (string name))
(let* (;; cant (last-name-pattern (#"compile" '|java.util.regex.Pattern| ".*?([^.]*)$"))
;; reason: bootstrap - the class name would have to be looked up...
@@ -1,6 +1,6 @@
(in-package :cl-user)
(prove:plan 6)
(prove:plan 8)
(read-from-string "#\"{bar}.{foo}\"")
@@ -22,7 +22,16 @@
(prove:is (#"toString"
(find "size" (#"getMethods" (find-java-class "java.util.Collections$UnmodifiableMap"))
:test 'string-equal :key #"getName"))
(#"toString" (java::jmethod "java.util.Collections$UnmodifiableMap" "size" )))
(#"toString" (java::jmethod "java.util.Collections$UnmodifiableMap" "size" )))
(jss::with-class-lookup-disambiguated (lang.object) (find-java-class 'object))
(find-java-class 'java.lang.object))
;; Object is ambiguous in default java
(find-java-class 'object)
;; test that optimized jss is much faster than unoptimized
(let ()
ProTip! Use n and p to navigate between commits in a pull request.