source: tags/1.5.0/contrib/jss/README.markdown

Last change on this file was 15074, checked in by Mark Evenson, 7 years ago

Release as 1.5.0

File size: 4.6 KB
Line 
1JSS
2===
3
4Created by Alan Ruttenberg
5
6
7JSS stands for either "Java Simple Syntax" or "Java Syntax Sucks",
8depending on your mood.
9
10The dynamic dispatch of the java.lang.reflect package is used to make
11it real easy, if perhaps less efficient, to write Java code since you
12don't need to be bothered with imports, or with figuring out which
13method to call.  The only time that you need to know a class name is
14when you want to call a static method, or a constructor, and in those
15cases, you only need to know enough of the class name that is unique
16wrt to the classes on your classpath.
17
18Java methods look like this: #"toString". Java classes are represented
19as symbols, which are resolved to the appropriate java class
20name. When ambiguous, you need to be more specific. A simple example
21from CL-USER:
22
23    (require :jss)
24    (in-package :jss)
25    (let ((sw (new 'StringWriter)))
26       (#"write" sw "Hello ")
27       (#"write" sw "World")
28       (print (#"toString" sw)))
29
30What's happened here? First, all the classes in all the jars in the
31classpath have been collected.  For each class a.b.C.d, we have
32recorded that b.c.d, b.C.d, C.d, c.d, and d potentially refer to this
33class. In your call to new, as long as the symbol can refer to only
34one class, we use that class. In this case, it is
35java.io.StringWriter. You could also have written
36
37     (new 'io.stringwriter)
38
39or     
40     (new '|io.StringWriter|)
41
42or     
43     (new 'java.io.StringWriter)
44
45The call
46
47     (#"write" sw "Hello ")
48     
49uses the code in invoke.java to call the method named "write" with
50the arguments sw and "Hello ".  JSS figures out the right java method
51to call, and calls it.
52
53An interactive restart is available to resolve class ambiguity.
54
55Static calls are possible as well with the SHARPSIGN-QUOTATION_MARK
56macro, but the first argument *must* be a symbol to distinguish
57
58     (#"getProperties" "java.lang.System")
59     
60from
61
62     (#"getProperties" 'java.lang.System)     
63     
64The first attempts to call a method on the java.lang.String object
65with the contents "java.lang.System", which results in an error, while
66the second invokes the static java.lang.System.getProperties() method.     
67
68If you want to do a raw java call, use #0"toString". Raw calls
69return their results as Java objects, avoiding doing the usual Java
70object to Lisp object conversions that ABCL does.
71
72
73    (with-constant-signature ((name jname raw?)*) &body body)
74   
75binds a macro which expands to a jcall, promising that the same method
76will be called every time. Use this if you are making a lot of calls and
77want to avoid the overhead of a the dynamic dispatch.
78e.g.
79 
80    (with-constant-signature ((tostring "toString"))
81        (time (dotimes (i 10000) (tostring "foo"))))
82
83runs about three times faster than
84 
85    (time (dotimes (i 10000) (#"toString" "foo")))
86
87So, something like
88
89    (with-constant-signature ((tostring "toString" t)) ...)
90   
91will cause the toString to be a raw java call. See
92JSS::GET-ALL-JAR-CLASSNAMES for an example.
93 
94Implementation is that the first time the function is called, the
95method is looked up based on the arguments passed, and thereafter
96that method is called directly.  Doesn't work for static methods at
97the moment (lazy)
98
99    (japropos string)
100
101finds all class names matching STRING.
102
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   
125Compatibility
126-------------
127
128The function ENSURE-COMPATIBILITY attempts to provide a compatibility
129mode to existing users of JSS by importing the necessary symbols into
130CL-USER.
131
132Some notes on other compatibility issues:
133
134*classpath-manager*
135
136   Since we are no longer using Beanshell, this is no longer present.
137   For obtaining the current classloader use JAVA:*CLASSLOADER*.
138   
139# API
140
141  1.0
142    Equivalent to Alan Ruttenberg's version included with the original
143    [lsw](). 
144   
145[lsw]: http://mumble.net:8080/svn/lsw/trunk/
146[lsw2]: let-me-google-that-for-you   
147   
148
149  3.0
150     In the JSS package loaded from [abcl-contrib]()
151     
152abcl-contrib: http://abcl.org/svn/trunk/abcl/contrib/     
153   
154# Colophon
155
156    <> dc:created "2005" ;
157       dc:author "Mark <evenson.not.org@gmail.com>";
158       dc:revised "11-JUN-2017" .
159
160
161   
Note: See TracBrowser for help on using the repository browser.