Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/calvin-l/lightweight-typestate-checker
An easy-to-use typestate checker
https://github.com/calvin-l/lightweight-typestate-checker
Last synced: 23 days ago
JSON representation
An easy-to-use typestate checker
- Host: GitHub
- URL: https://github.com/calvin-l/lightweight-typestate-checker
- Owner: Calvin-L
- License: mit
- Created: 2023-06-02T05:30:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-22T01:48:33.000Z (over 1 year ago)
- Last Synced: 2024-10-16T08:10:43.469Z (2 months ago)
- Language: Java
- Size: 35.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lightweight Typestate Checker
An easy-to-use typestate checker for Java.
Features:
- Lightweight: no complicated alias analysis or ownership annotations.
(Instead, certain annotations have to be "stable"---more on this when I get
around to writing it up.)
- Easy-to-use: no need to learn a new language. Typestate transitions are
specified using simple annotations: `@RequiresState`, `@NewStateOnReturn`,
`@NewStateOnReturnIf`, and `@NewStateOnException`.
- Sound: you are never allowed to call a method when an object could be in the
wrong state.## Example
```java
public class Example {public static void main(String[] args) throws IOException {
try (Conn c = new Conn()) {// Attempting to use `c` before calling `connect()` is bad!
// > error: [contracts.precondition] precondition of c.use is not satisfied.
// > found : c is @State("idle")
// > required: c is @State("connected")
c.use();}
}static class Conn implements AutoCloseable {
@NewStateOnReturn("idle")
public Conn() {
}@RequiresState(value="this", state="idle")
@NewStateOnReturn("connected")
public void connect() {
}@RequiresState(value="this", state="connected")
public void use() {
}@Override
@NewStateOnReturn("closed")
@NewStateOnException(exception=Throwable.class, state="closed")
public void close() {
}}
}
```## Quickstart
Add `-processor org.lwtsc.LightWeightTypeStateChecker` to your `javac` flags.
(More on adding this to your existing build system when I get around to writing
it up---but you can start by reading
[the official Checker Framework docs](https://checkerframework.org/manual/#external-tools)
and studying
[the example project](/example/)).