days
-6
-3
hours
-2
-2
minutes
-4
-8
seconds
-2
-8
search
Spoon full of code

Academic-owned Java library transforms, rewrites, analyzes, and transpiles code

Sarah Schlothauer
java
© Shutterstock / Icealex

Today’s spotlight lands on Spoon: a Java library that allows you to transform and analyze Java code. This library is as brainy and academic as it is powerful. Give it a stir!

There’s no shortage of helpful open source Java libraries! We love diving deep and today we looking at at Spoon. Created by Inria, the French National Institute for computer science and applied mathematics, Spoon allows you to transform and analyze Java code.

Have you used this academic library yet? Come and get your check-out card.

    In a cloud native world enamored with microservices and serverless, meet Quarkus – Java’s brilliant response to technologies like Node.js, Python and Go that had proven quicker, smaller and arguably more nimble. Download your free beginner's tutorial written by JAX London speaker Alex Soto.

The library is open (source)

SEE ALSO: Meet Apron – A small library for advanced Java properties

Spoon’s lengthy history passed it through several hands. GitHub user tdurieux commented on November 3, 2018 about Spoon’s creation. “The Spoon project started at the beginning of 2007 with Renaud Pawlak as a tool for research…The Spoon architecture did not massively change since that period.” After this fact, it was paid for by Inria. However, as tdurieux goes on to explain, now Spoon is maintained by the open source community: “half academic and half industry”. (You can read more about the timeline here.)

So, what does Spoon do?

From GitHub:

Spoon is a library to analyze, transform, rewrite, transpile Java source code (incl Java 9 & Java 10). It parses source files to build a well-designed AST with powerful analysis and transformation API. Made at Inria with ❤️, 🍻 and ✨. http://spoon.gforge.inria.fr/

According to Spoon’s design philosophy, it stays as true as possible to the original Java language concepts.

Powerful, yet easy transformations

SEE ALSO: How to fix a VirtualMachineError in Java

The latest version, Spoon 7.1.0 released on October 10, 2018. With the latest update, a host of new features, improved documentation, and bug fixes (what’s an update without a few?) came to the table. This includes updated performance issues, added support for javadoc inline tags, and added encoding detection callback.

View an example and learn how to make your first transformation!

For academic usage, you must cite “Spoon: A Library for Implementing Analyses and Transformations of Java Source Code” in your work. (Of course, for those interested in this library and computer science this paper is a treasure trove to explore! We highly recommend giving it at least a good browse.)

Just a few features worth stirring around:

  • Queries: Added in Spoon 5.5, queries can be chained, and reused
  • Filters: A Filter defines a predicate of the form of a matches method that returns true if an element has to be selected in the filtering operation.
  • Matching elements
  • Patterns: Create a Spoon pattern for finding elements with PatternBuilder

Downloading Spoon

Compiling Spoon requires the JDK and Maven.

Need help?

Thankfully, the community for Spoon is fairly large and active. Since it has been around for so long, experts aplenty have advice and know-how. (Not to mention that some of the top minds helped create and support it!) Pull requests welcome!

Author
Sarah Schlothauer

Sarah Schlothauer

All Posts by Sarah Schlothauer

Sarah Schlothauer is an assistant editor for JAXenter.com. She received her Bachelor's degree from Monmouth University and is currently enrolled at Goethe University in Frankfurt, Germany where she is working on her Masters. She lives in Frankfurt with her husband and cat. She is also the editor for Conditio Humana, an online magazine about ethics, AI, and technology.

Leave a Reply

Be the First to Comment!

avatar
400
  Subscribe  
Notify of