Skip to content

Commit 43873e4

Browse files
puredangerstuarthalloway
authored andcommitted
CLJ-1190 - move clojure.api.API to clojure.java.api.Clojure. add javadoc for clojure.lang, clojure.lang.IFn, clojure.java.api.Clojure. add ant target to generate javadoc for the API.
Signed-off-by: Stuart Halloway <stu@cognitect.com>
1 parent f7215fd commit 43873e4

File tree

6 files changed

+106
-26
lines changed

6 files changed

+106
-26
lines changed

build.xml

+20-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,26 @@
130130
</jar>
131131
<copy file="${clojure_jar}" tofile="${clojure_noversion_jar}"/>
132132
</target>
133-
133+
134+
<target name="javadoc"
135+
description="Creates javadoc for Clojure API.">
136+
<copy file="src/jvm/clojure/lang/IFn.java" tofile="target/tmpjd/IFn.java"/>
137+
<copy file="src/jvm/clojure/lang/package.html" tofile="target/tmpjd/package.html"/>
138+
<replaceregexp file="target/tmpjd/IFn.java" match="(static public interface .*})" replace="" byline="true"/>
139+
<javadoc destdir="target/javadoc"
140+
nodeprecatedlist="true" nohelp="true" nonavbar="true" notree="true"
141+
link="http://docs.oracle.com/javase/7/docs/api/"
142+
windowtitle="Clojure API">
143+
<classpath>
144+
<path location="${build}"/>
145+
</classpath>
146+
<fileset dir="${basedir}">
147+
<include name="src/jvm/clojure/java/api/Clojure.java"/>
148+
<include name="target/tmpjd/IFn.java"/>
149+
</fileset>
150+
</javadoc>
151+
</target>
152+
134153
<target name="all" depends="build,test,jar"/>
135154

136155
<target name="clean"

src/jvm/clojure/api/API.java renamed to src/jvm/clojure/java/api/Clojure.java

+37-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,47 @@
88
* You must not remove this notice, or any other, from this software.
99
**/
1010

11-
package clojure.api;
11+
package clojure.java.api;
1212

1313
import clojure.lang.IFn;
1414
import clojure.lang.Symbol;
1515
import clojure.lang.Var;
1616

17-
public class API {
18-
private API() {}
17+
/**
18+
* <p>The Clojure class provides a minimal interface to bootstrap Clojure access
19+
* from other JVM languages. It provides:</p>
20+
*
21+
* <ol>
22+
* <li>The ability to use Clojure's namespaces to locate an arbitrary
23+
* <a href="http://clojure.org/vars">var</a>, returning the
24+
* var's {@link clojure.lang.IFn} interface.</li>
25+
* <li>A convenience method <code>read</code> for reading data using
26+
* Clojure's edn reader</li>
27+
* </ol>
28+
*
29+
* <p>To lookup and call a Clojure function:</p>
30+
*
31+
* <pre>
32+
* IFn plus = Clojure.var("clojure.core", "+");
33+
* plus.invoke(1, 2);</pre>
34+
*
35+
* <p>Functions in <code>clojure.core</code> are automatically loaded. Other
36+
* namespaces can be loaded via <code>require</code>:</p>
37+
*
38+
* <pre>
39+
* IFn require = Clojure.var("clojure.core", "require");
40+
* require.invoke(Clojure.read("clojure.set"));</pre>
41+
*
42+
* <p><code>IFn</code>s can be passed to higher order functions, e.g. the
43+
* example below passes <code>plus</code> to <code>read</code>:</p>
44+
*
45+
* <pre>
46+
* IFn map = Clojure.var("clojure.core", "map");
47+
* IFn inc = Clojure.var("clojure.core", "inc");
48+
* map.invoke(inc, Clojure.read("[1 2 3]"));</pre>
49+
*/
50+
public class Clojure {
51+
private Clojure() {}
1952

2053
private static Symbol asSym(Object o) {
2154
Symbol s;
@@ -52,7 +85,7 @@ public static IFn var(Object ns, Object name) {
5285
/**
5386
* Read one object from the String s. Reads data in the
5487
* <a href="http://edn-format.org">edn format</a>.
55-
* @param s
88+
* @param s a String
5689
* @return an Object, or nil.
5790
*/
5891
public static Object read(String s) {

src/jvm/clojure/api/package.html renamed to src/jvm/clojure/java/api/package.html

+12-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<body>Clojure interop from Java.
1414

15-
<p>The clojure.api package provides a minimal interface to bootstrap
15+
<p>The clojure.java.api package provides a minimal interface to bootstrap
1616
Clojure access from other JVM languages. It does this by providing:
1717
</p>
1818

@@ -25,7 +25,7 @@
2525
</ol>
2626

2727
<p><code>IFn</code>s provide complete access to
28-
Clojure's <a href="http://clojure.github.com/clojure/">API</a>s.
28+
Clojure's <a href="http://clojure.github.io/clojure/">API</a>s.
2929
You can also access any other library written in Clojure, after adding
3030
either its source or compiled form to the classpath.</p>
3131

@@ -34,7 +34,7 @@
3434
</p>
3535

3636
<ol>
37-
<li>clojure.api.API</li>
37+
<li>clojure.java.api.Clojure</li>
3838
<li>clojure.lang.IFn</li>
3939
</ol>
4040

@@ -43,25 +43,25 @@
4343

4444
<p>To lookup and call a Clojure function:
4545
<pre>
46-
IFn plus = API.var("clojure.core", "+");
46+
IFn plus = Clojure.var("clojure.core", "+");
4747
plus.invoke(1, 2);
4848
</pre>
4949
</p>
5050

5151
<p>Functions in <code>clojure.core</code> are automatically loaded. Other
5252
namespaces can be loaded via <code>require</code>:
5353
<pre>
54-
IFn require = API.var("clojure.core", "require");
55-
require.invoke(API.read("clojure.set"));
54+
IFn require = Clojure.var("clojure.core", "require");
55+
require.invoke(Clojure.read("clojure.set"));
5656
</pre>
5757
</p>
5858

5959
<p><code>IFn</code>s can be passed to higher order functions, e.g. the
6060
example below passes <code>plus</code> to <code>read</code>:
6161
<pre>
62-
IFn map = API.var("clojure.core", "map");
63-
IFn inc = API.var("clojure.core", "inc");
64-
map.invoke(inc, API.read("[1 2 3]"));
62+
IFn map = Clojure.var("clojure.core", "map");
63+
IFn inc = Clojure.var("clojure.core", "inc");
64+
map.invoke(inc, Clojure.read("[1 2 3]"));
6565
</pre>
6666
</p>
6767

@@ -70,8 +70,9 @@
7070
instead of <code>fn</code>:</p>
7171

7272
<pre>
73-
IFn printLength = API.var("clojure.core", "*print-length*");
74-
API.var("clojure.core", "deref").invoke(printLength);
73+
IFn printLength = Clojure.var("clojure.core", "*print-length*");
74+
IFn deref = Clojure.var("clojure.core", "deref");
75+
deref.invoke(printLength);
7576
</pre>
7677

7778
</body>

src/jvm/clojure/lang/IFn.java

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
import java.util.concurrent.Callable;
1616

17+
/**
18+
* <p><code>IFn</code> provides complete access to invoking
19+
* any of Clojure's <a href="http://clojure.github.io/clojure/">API</a>s.
20+
* You can also access any other library written in Clojure, after adding
21+
* either its source or compiled form to the classpath.</p>
22+
*/
1723
public interface IFn extends Callable, Runnable{
1824

1925
public Object invoke() ;

src/jvm/clojure/lang/package.html

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<html>
2+
3+
<!--
4+
Copyright (c) Rich Hickey and Contributors. All rights reserved.
5+
The use and distribution terms for this software are covered by the
6+
Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
7+
which can be found in the file epl-v10.html at the root of this distribution.
8+
By using this software in any fashion, you are agreeing to be bound by
9+
the terms of this license.
10+
You must not remove this notice, or any other, from this software.
11+
-->
12+
13+
<body>Clojure language implementation.
14+
15+
<p>The clojure.lang package holds the implementation for Clojure.
16+
The only class considered part of the public API is
17+
{@link clojure.lang.IFn}. All other classes should be considered
18+
implementation details.</p>
19+
20+
</body>
21+
</html>

test/clojure/test_clojure/api.clj

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,45 @@
1010
(:require [clojure.test.generative :refer (defspec)]
1111
[clojure.test-clojure.generators :as cgen])
1212
(:import clojure.lang.IFn
13-
clojure.api.API
13+
clojure.java.api.Clojure
1414
clojure.lang.Var))
1515

1616
(set! *warn-on-reflection* true)
1717

1818
(defn roundtrip
19-
"Print an object and read it back with API/read"
19+
"Print an object and read it back with Clojure/read"
2020
[o]
2121
(binding [*print-length* nil
2222
*print-dup* nil
2323
*print-level* nil]
24-
(API/read (pr-str o))))
24+
(Clojure/read (pr-str o))))
2525

2626
(defn api-var-str
2727
[^Var v]
28-
(API/var (str (.name (.ns v)))
29-
(str (.sym v))))
28+
(Clojure/var (str (.name (.ns v)))
29+
(str (.sym v))))
3030

3131
(defn api-var
3232
[^Var v]
33-
(API/var (.name (.ns v))
34-
(.sym v)))
33+
(Clojure/var (.name (.ns v))
34+
(.sym v)))
3535

3636
(defspec api-can-read
3737
roundtrip
3838
[^{:tag cgen/ednable} o]
3939
(when-not (= o %)
40-
(throw (ex-info "Value cannot roundtrip with API/read" {:printed o :read %}))))
40+
(throw (ex-info "Value cannot roundtrip with Clojure/read" {:printed o :read %}))))
4141

4242
(defspec api-can-find-var
4343
api-var
4444
[^{:tag cgen/var} v]
4545
(when-not (= v %)
46-
(throw (ex-info "Var cannot roundtrip through API/var" {:from v :to %}))))
46+
(throw (ex-info "Var cannot roundtrip through Clojure/var" {:from v :to %}))))
4747

4848
(defspec api-can-find-var-str
4949
api-var-str
5050
[^{:tag cgen/var} v]
5151
(when-not (= v %)
52-
(throw (ex-info "Var cannot roundtrip strings through API/var" {:from v :to %}))))
52+
(throw (ex-info "Var cannot roundtrip strings through Clojure/var" {:from v :to %}))))
5353

5454

0 commit comments

Comments
 (0)