Skip to content
Annotation processor for generating inferred objects.
Java Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
inference-basic Refactoring of freemarker model Nov 7, 2019
inference-codegen
.gitignore
.travis.yml
INTERNALS.md
LICENSE
README.md
appveyor.yml
deploy.sh
pom.xml

README.md

OO-Inference

Travis AppVeyor Codecov

Annotation processor for generating inferred objects. For information about what are inferences and inferred objects and why do they needed, check this page.

How to use it

  1. Add a maven dependency:
<dependencies>
    <dependency>
        <groupId>com.pragmaticobjects.oo.inference</groupId>
        <artifactId>inference-basic</artifactId>
        <version>x.y.z</version>
    </dependency>
</dependencies>
  1. Define and annotate an inference:
public @Infers(value = "GithubUser", memoized = true) class GithubUserInference implements Inference<User> {
    private final String apiToken;

    public GithubUserInference(String apiToken) {
        this.apiToken = apiToken;
    }

    @Override
    public final User inferredInstance() {
        try {
            Github github = new RtGithub(apiToken);
            com.jcabi.github.User self = github.users().self();
            return new StaticUser(self.login(), self.emails().iterate());    
        } catch(IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}
  1. Build the project

During the project build, sources for inferred class (UserInferred) and inferred alias (GithubUser) for the defined inference will automatically be generated.

  1. Use generated sources
public class App {
    public static void main( String[] args ) throws Exception {
        Memory mem = new MemoryCHM();
        User user = new GithubUser("xxxsomegithubtokenxxx", mem);
        System.out.println(user.name());
    }
}
You can’t perform that action at this time.