Skip to content

volodya-lombrozo/jsmith

Repository files navigation

jsmith

Maven Central License Hits-of-Code codecov

Jsmith is a random Java program generator. The project is largely inspired by csmith, a tool for the C language. The primary purpose of the library is to provide classes for generating random Java programs to test Java compilers or translators.

If you need to generate random Java programs for any other purpose, you can also give Jsmith a try.

Installation

The library is available on Maven Central. To add it to your project, add the following snippet to your pom.xml:

<dependency>
  <groupId>com.github.volodya-lombrozo</groupId>
  <artifactId>jsmith</artifactId>
  <version>0.1.2</version>
</dependency>

How to Use

The library provides a set of classes for generating random Java programs. To generate a random class, you can use the new RandomJavaClass().src() command:

public class BasicExample {
    public static void main(String... args) {
        RandomJavaClass clazz = new RandomJavaClass();
        String code = clazz.src();
        System.out.println(code);
    }
}

You can also pass the seed parameter to the RandomJavaClass constructor to generate the same class every time: new RandomJavaClass(seed).src().

Pay attention, that a single RandomJavaClass instance can generate only one random class and the invocation of src() method will return the same class every time:

public class SameExample {
    public static void main(String... args) {
        RandomJavaClass clazz = new RandomJavaClass();
        assert clazz.src().equals(clazz.src()); // true
    }
}

Internals

If you’re interested in understanding the internal mechanics of the library, you can explore the Under the Hood guide, which provides an in-depth explanation of the core design and generation logic. Additionally, the process of Semantic-Aware Generation explains how the library generates programs with semantic awareness. For more detailed technical documentation, visit the docs directory.

Contribution

Fork repository, make changes, send us a pull request. We will review your changes and apply them to the main branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request, please run full Maven build:

$ mvn clean install -Pqulice

You will need Maven 3.3+ and Java 8+ installed.

About

Jsmith, a random generator of Java programs

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published