Metadata-Version: 2.5
Name: sphinx-java
Version: 1.0.0
Summary: Java domain for Sphinx
Project-URL: Homepage, https://github.com/djungelorm/sphinx-java
Author: Chris Thunes
Author-email: djungelorm <djungelorm@users.noreply.github.com>
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Documentation :: Sphinx
Requires-Python: >=3.11
Requires-Dist: sphinx>=7.2
Requires-Dist: tree-sitter-java>=0.23.5
Requires-Dist: tree-sitter>=0.23
Description-Content-Type: text/markdown

# sphinx-java

A Sphinx domain for documenting Java APIs. It is a continuation of [javasphinx](https://github.com/bronto/javasphinx), which is no longer maintained, without the `javasphinx-apidoc` tool.

## Usage

Install using pip:

```
pip install sphinx-java
```

Enable the extension in your `conf.py`:

```py
extensions = ['sphinx_java']
```

Document a type and its members with the `java` directives:

```rst
.. java:package:: com.example.shapes

.. java:import:: java.util List

.. java:type:: public abstract class Polygon<P extends Point> implements Shape

   A shape with straight sides.

   :param P: The type of the vertices.

   .. java:constructor:: public Polygon(List<P> vertices)

      :param vertices: The vertices, in order.
      :throws IllegalArgumentException: If there are too many vertices.

   .. java:method:: public <S extends Shape> boolean contains(S shape)

      :param S shape: The shape.
      :return: Whether the polygon contains the shape.

   .. java:field:: public static final int MAX_SIDES = 100
```

See [`tests/roots/test-basic/index.rst`](https://github.com/djungelorm/sphinx-java/blob/main/tests/roots/test-basic/index.rst) for more examples.

## Directives

- `java:package`: sets the package of the directives and references that follow, and is the target of references to the package. A package on several pages links to the first page by name. Add `:no-index:` to set the package without a target.
- `java:import`: declares the package of a type, as in `.. java:import:: java.util List`. References to the type and its nested types, such as `Map.Entry`, then link to that package's docs. Import a nested type as in `.. java:import:: java.util Map.Entry`, and then refer to it as `Entry`.
- `java:type`: a class, interface, enum, record or annotation. Document type parameters with `param` fields.
- `java:constructor` and `java:method`: document parameters with `param` and exceptions with `throws`. A method also takes `return`.
- `java:field`: one field.
- `java:enumconstant`: one enum constant, such as `RED` or `RED(0xFF0000)`. The `java:field` role links to it.

A constructor, method or field outside a `java:type` directive takes the `:outertype:` option to name its type. Every object directive takes `:package:` to override the current package, and the standard `:no-index:` options.

Type parameters and primitive types are plain text. The package of a qualified name, such as `java.util` in `java.util.List`, is one link to the package.

## Roles

Reference an object with `java:type`, `java:meth`, `java:construct`, `java:field` or `java:package`, or with `java:ref` for any object type:

```rst
:java:type:`Polygon`, :java:meth:`Polygon.contains(S)`, :java:ref:`~com.example.shapes.Polygon`
```

A leading `~` shows only the last part of the name. A method reference with parameter types links to that overload. The `any` role also finds Java objects.

## External Docs

A reference that matches no local object links to external Javadoc. Map packages to their docs with `javadoc_url_map` in your `conf.py`:

```py
javadoc_url_map = {
    'org.javatuples': ('https://www.javatuples.org/apidocs/', 'javadoc'),
}
```

Each value is a base URL and a docs type. The longest matching package is used. The docs types are:

- `javadoc`: Javadoc before Java 8.
- `javadoc8`: Javadoc from Java 8, which changed the method anchors.
- `javadoc11`: Java SE docs from Java 11, which put module names in the paths.
- `sphinx`: docs generated by javasphinx-apidoc.

The `java`, `javax`, `org.ietf`, `org.w3c` and `org.xml` packages link to the Java SE 25 docs, unless the map has them. Choose another Java SE version, 8 or 11 and later, with `javadoc_java_se_version`:

```py
javadoc_java_se_version = 21
```

Link to external docs explicitly with the `java:extdoc` role:

```rst
:java:extdoc:`java.util.Map.Entry`
```

## Migrating From javasphinx

Change the extension name in your `conf.py` from `javasphinx` to `sphinx_java`. The directives, roles and `javadoc_url_map` are the same. javasphinx linked to the Java SE 8 docs. Set `javadoc_java_se_version = 8` to keep those links.

## License

Apache 2.0, from javasphinx.
