com.io7m.jpplib
jpplib is a small Java™ package to pretty-print information using line breaks and indentation. For instance, it can be used to print
while (i>0) { i--; j++; }instead of
while (i>0) { i --; j++;}if the maximum line width is 15 characters. Or you could use it to print (nested)
java.util.List
s and Map
s on
one line, if they fit, or on several lines, with indentation, if
they don't.
The purpose of jpplib is not to pretty-print Java™
programs. It is a library that can be used to write pretty-printers
for all manner of structured information: programs, XML files,
mathematical expressions, abstract syntax trees, content of data
structures for debugging... Apart from a few included examples, it
does not contain any actual pretty-printers, any more
than java.io
contains any code for printing concrete
information.
The algorithm employed by jpplib is that described by Derek C. Oppen in his paper Prettyprinting, TOPLAS volume 2 number 4, ACM, 1980, pp. 465-483, with some extensions. It has the property that if the input contains enough actual text (and not just administrative chit-chat), then pretty-printing uses constant space, and time linear in the size of the input. In fact, output will begin before the whole input has been given, so this class can be used to pretty-print a stream of data.
An interesting extension is the mark()
method of the
Layouter
class, which allows to attach an arbitrary
object to a given position in the text. This object can be retrieved
in the formatted output by the back-end. The mark()
feature is useful e.g. for interactive applications, where the user
may click on a position in the formatted text, and the software needs
to figure out which piece of data corresponds to the text that was
clicked on.
Releases
The most recently published version of the software is 1.0.0.
Source code and binaries are available from the repository.
Documentation
Documentation for the 1.0.0 release is available for reading online.
Documentation for current and older releases is archived in the repository.
No documentation is currently available.
Maven
The following is a complete list of the project's modules expressed as Maven dependencies:
<dependency> <groupId>com.io7m.jpplib</groupId> <artifactId>com.io7m.jpplib</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>com.io7m.jpplib</groupId> <artifactId>com.io7m.jpplib.core</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>com.io7m.jpplib</groupId> <artifactId>com.io7m.jpplib.demo</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>com.io7m.jpplib</groupId> <artifactId>com.io7m.jpplib.tests</artifactId> <version>1.0.0</version> </dependency>
Each release of the project is made available on Maven Central within ten minutes of the release announcement.
Changes
Subscribe to the releases atom feed.
2024-05-10 | Release: com.io7m.jpplib 1.0.0 |
2020-10-12 | Change: Update junit:4.12 → 4.13.1. |
2024-04-30 | Change: Update org.slf4j:slf4j-api:2.0.10 → 2.0.13. |
2024-05-10 | Change: Move to new organization. |
2017-12-07 | Release: com.io7m.jpplib 0.8.0 |
2017-12-07 | Change: Use primogenitor, rename project to com.io7m.jpplib |
2017-12-07 | Change: Require JDK 9 to build the code (but the result is still Java 8 bytecode) |
2017-12-07 | Change: Add an Automatic-Module-Name manifest field for use in Java 9 projects |
2016-09-22 | Release: com.io7m.jpplib 0.7.4 |
2016-09-22 | Change: Add getDefaultIndentation() to Layout |
2016-09-01 | Release: com.io7m.jpplib 0.7.3 |
2016-09-01 | Change: Delegate to the correct super method in DataLayouter. (tickets: 3 ) |
2016-08-05 | Release: com.io7m.jpplib 0.7.2 |
2016-08-05 | Change: Update POM plugins. |
2016-08-05 | Change: The packaged jar is now an OSGi bundle. |
2016-05-29 | Release: com.io7m.jpplib 0.7.1 |
2016-05-12 | Change: Add finish() method to Layouter class (tickets: 1 ) |
2016-05-12 | Change: Add SLF4J support for tracing layouts (tickets: 2 ) |
2016-05-11 | Release: com.io7m.jpplib 0.7.0 |
2016-05-11 | Change: Initial fork of project. |
Sources
This project uses Git to manage source code.
Repository: https://www.github.com/io7m-com/jpplib
$ git clone https://www.github.com/io7m-com/jpplib
License
Copyright (c) 2009, Martin Giese All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Bug Tracker
The project uses GitHub Issues to track issues.