2 #######################
3 javasphinx User's Guide
4 #######################
6 Welcome to the javasphinx user's guide.
11 javasphinx is a Sphinx_ extension that provides a Sphinx domain_ for documenting
12 Java projects and a ``javasphinx-apidoc`` command line tool for automatically
13 generating API documentation from existing Java source code and Javadoc
16 .. _Sphinx: http://sphinx-doc.org
17 .. _domain: http://sphinx-doc.org/domains.html
22 javasphinx is available in the Python Package Index (PyPi) and can be installed
23 using tools such as ``pip`` or ``easy_install``,
27 $ pip install javasphinx
33 $ easy_install -U javasphinx
38 To enable javasphinx for your existing Sphinx configuration add ``'javasphinx'``
39 to the list of extensions in your conf.py file. javasphinx can be configured to
40 cross link to external sources of documentation using the ``javadoc_url_map``
43 .. code-block:: python
46 'com.netflix.curator' : ('http://netflix.github.com/curator/doc', 'javadoc'),
47 'org.springframework' : ('http://static.springsource.org/spring/docs/3.1.x/javadoc-api/', 'javadoc'),
48 'org.springframework.data.redis' : ('http://static.springsource.org/spring-data/data-redis/docs/current/api/', 'javadoc')
51 Each key in the map should be a Java package. Each value is a tuple of the form
52 ``(base_url, doc_type)`` where ``base_url`` is the base URL of the documentation
53 source, and ``doc_type`` is one of,
56 For documentation generated by the Javadoc tool *before* version 8.
59 For documentation generated by the Javadoc tool after version 8. This is
60 required due to changes in how method anchors are generated (see JDK-8144118_).
63 For external documentation generated by javasphinx.
65 When comparing referenced types to the list of available packages the longest
66 match will be used. Entries for ``java``, ``javax``, ``org.xml``, and
67 ``org.w3c`` packages pointing to http://docs.oracle.com/javase/8/docs/api are
68 included automatically and do not need to be defined explicitly.
70 .. _JDK-8144118: https://bugs.openjdk.java.net/browse/JDK-8144118
78 The Java domain uses the name **java** and provides the following directives,
80 .. rst:directive:: .. java:type:: type-signature
82 Describe a Java type. The signature can represent either a class, interface,
83 enum or annotation declaration.
85 Use the ``param`` field to document type parameters.
91 .. java:type:: public interface List<E> extends Collection<E>, Iterable<E>
93 An ordered collection (also known as a *sequence*)
95 :param E: type of item stored by the list
99 .. java:type:: public interface List<E> extends Collection<E>, Iterable<E>
101 An ordered collection (also known as a *sequence*)
103 :param E: type of item stored by the list
105 .. rst:directive:: .. java:field:: field-signature
107 Describe a Java field.
109 .. rst:directive:: .. java:method:: method-signature
111 Describe a Java method.
113 Use the ``param`` field to document parameters.
115 Use the ``throws`` field to document exceptions thrown by the method.
117 Use the ``return`` field to document the return type
119 .. rst:directive:: .. java:constructor:: constructor-signature
121 Describe a Java constructor.
123 Use the ``param`` field to document parameters.
125 Use the ``throws`` field to document exceptions thrown by the constructor.
127 .. rst:directive:: .. java:package:: package
129 Provide package-level documentation and also sets the active package for the
130 type, method, field, constructors, and references that follow.
132 Use the ``:noindex:`` option if the directive is only being used to specify
133 the active package. Only one directive for a given package should exclude
136 .. rst:directive:: .. java:import:: package type
138 Declare the given type as being provided by the given package. This
139 information helps javasphinx create cross references for types in type,
140 method, and field declarations. It also allows explicit cross references
141 (using the ``java:ref`` role) to exclude the package qualification.
143 The method, construct, field, and type directives all accept the following
146 .. describe:: package
148 Specify the package the declaration is within. Can be used instead of, or to
149 override, a ``java:package`` directive.
151 .. describe:: outertype
153 Specify the class/interface the documented object is contained within. This
154 option should be provided for any constructor, method, or field directive
155 that isn't nested within a corresponding type directive.
160 The following roles are provided,
162 .. rst:role:: java:ref
164 This role can be used to create a cross reference to any object type within
165 the Java domain. Aliases for this role include ``java:meth``, ``java:type``,
166 ``java:field``, ``java:package``, and ``java:construct``.
168 An explicit title can be provided by using the standard ``title <reference>``
171 .. rst:role:: java:extdoc
173 This role can be used to explicitly link to an externally documented
174 type. The reference must be fully qualified and supports an explicit title
175 using the ``title <reference>`` syntax.
177 The ``java:ref`` role will also create external references as a fall-back if
178 it can't find a matching local declaration so using this role is not strictly
184 The ``javasphinx-apidoc`` tool is the counterpoint to the ``sphinx-apidoc`` tool
185 within the Java domain. It can be used to generate reST source from existing
186 Java source code which has been marked up with Javadoc-style comments. The
187 generated reST is then processed alongside hand-written documentation by Sphinx.
189 At minimum a source and destination directory must be provided. The input
190 directory will be scanned for .java files and documentation will be generated
191 for all non-private types and members. A separate output file will be generated
192 for each type (including inner classes). Each file is put within a directory
193 corresponding to its package (with periods replaced by directory separators) and
194 with the basename of the file deriving from the type name. Inner types are
195 placed in files with a basename using a hyphen to separate inner and outer
196 types, e.g. ``OuterType-InnerType.rst``.
198 By default ``javasphinx-apidoc`` will not override existing files. Two options
199 can change this behavior,
201 .. option:: -f, --force
203 All existing output files will be rewritten. If a cache directory is
204 specified it will be rebuilt.
206 .. option:: -u, --update
208 Updated source files will have their corresponding output files
209 updated. Unchanged files will be left alone. Most projects will want to use
212 For larger projects it is recommended to use a cache directory. This can speed
213 up subsequent runs by an order of magnitude or more. Specify a directory to
214 store cached output using the :option:`-c` option,
216 .. option:: -c, --cache-dir
218 Specify a directory to cache intermediate documentation representations. This
219 directory will be created if it does not already exist.