LiquidJava VS Code Extension
Extend your Java code with Liquid Types and catch bugs earlier!LiquidJava is an additional type checker for Java, based on liquid types and typestates, which provides stronger safety guarantees to Java programs at compile-time. With this extension, you can use LiquidJava directly in VS Code, with real-time diagnostic reporting, syntax highlighting for refinements, and an interactive webview for displaying details about diagnostics and state machine diagrams.
InstallationTo try out the extension, install it from the VS Code Marketplace or the Open VSX Marketplace. Additionally, you'll need the Language Support for Java(TM) by Red Hat VS Code extension, and add the Maven
Gradle
A repository with LiquidJava examples is available at liquidjava-examples. You can try them out without setting up your local environment using GitHub Codespaces. Getting started in VS CodeThe Get Started with LiquidJava walkthrough introduces LiquidJava and its interactive tutorial, includes copyable Maven/Gradle annotation dependencies, then explains verification and its status indicator, diagnostics, state machines, context, the Command Palette, and logs. It also links to the interactive tutorial. It opens once on installation, following VS Code’s walkthrough preferences. You can dismiss it at any time and reopen it with LiquidJava: Show Walkthrough from the Command Palette or LiquidJava: Show Commands. VS Code saves its progress across workspaces. What are Liquid Types?Liquid types extend a language with logical predicates over the basic types. They allow developers to restrict the values that a variable, parameter or return value can have. These kinds of constraints help to catch more bugs before the program is executed. For example, they allow us to prevent bugs like array index out-of-bounds or division by zero at compile-time. LiquidJavaRefinementsTo refine a variable, field, parameter or return value, use the
Refinement AliasesTo simplify the usage of refinements, you can create predicate aliases using the
Object State Modeling via TypestatesBeyond basic refinements, LiquidJava also supports object state modeling via typestates, which allows developers to specify when a method can or cannot be called based on the state of the object. You can also provide a custom error message for when the method precondition is violated. For example:
Ghost Variables and External RefinementsFinally, LiquidJava also provides ghost variables, which are used to track additional information about the program state when typestates aren't enough, with the
You can find more examples of how to use LiquidJava on the LiquidJava Website. To learn how to use LiquidJava, you can also follow the LiquidJava tutorial. For more information, check the following repositories:
|
