Skip to content
Java Code Generation Framework
Branch: master
Clone or download
verhas Merge pull request #13 from Michael1993/equals-update
Added super calls to core Equals generator.
Latest commit 9907813 Jul 3, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE Update issue templates Nov 6, 2018
images dependencies changed May 25, 2019
javageci-annotation builder first version May 23, 2019
javageci-api set generates random name for unnamed sets Jun 25, 2019
javageci-core Added super hashCode calls to objects method when appropriate. Jul 3, 2019
javageci-engine fix a bug in Repeated Jun 28, 2019
javageci-examples Modified Equals generator to have param 'useSuper'. Jul 3, 2019
javageci-jamal getAllMethodsSorted now returns really all methods Jun 26, 2019
javageci-tools Removed copy-paste code, moved exception to a more logical place. Jul 3, 2019
.gitignore initial code upload Oct 4, 2018
.travis.yml dist:xenial in travis file Apr 29, 2019
ACCESSOR.md Moved unnecessary tutorial part from README.md to TUTORIAL_USE.md. Jun 24, 2019
CLONER.md documentation updated Jun 1, 2019
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Nov 6, 2018
CONFIGURATION.md mnemonic can be made configurable using an option in the config builder Jun 24, 2019
DELEGATOR.md delegator implements a builder May 23, 2019
EQUALS.md documentation was updated May 31, 2019
EXPLANATION.md analysis and cleanup of the code Oct 10, 2018
FAQ.md FAQ updated according to suggestions by Martin Grajcar Jun 2, 2019
FILTER_EXPRESSIONS.md some more selectgors were added Jun 3, 2019
FLUENT.md FLUENT.md reformatted Apr 14, 2019
GENERATORS.md Moved unnecessary tutorial part from README.md to TUTORIAL_USE.md. Jun 24, 2019
HOWTO.md analysis and cleanup of the code Oct 10, 2018
IMMUTATOR.md documentation Oct 30, 2018
INJECT.md documentation Oct 30, 2018
LICENSE Create LICENSE Nov 6, 2018
LOGGING.md logging documentation Jun 21, 2019
MAPPER.md typos discovered by KI and fixed Apr 10, 2019
MODULES.md modules documentation first complete draft May 25, 2019
PROXY.md documentation Oct 30, 2018
README.md Moved unnecessary tutorial part from README.md to TUTORIAL_USE.md. Jun 24, 2019
REFERENCE.md template handling of segments is documented Jun 1, 2019
RELEASE.md 1.1.1-SNAPSHOT release Jan 29, 2019
REPEATED.md Repeated generator is configurable with a valuesSupplier Jun 21, 2019
TEMPLATED.md Templated developed further Jun 13, 2019
TUTORIAL.md Minor documentation adjustments. Added missing md file. Jun 23, 2019
TUTORIAL_FROMXML.md Reverted bad change in ...FROMXML.md Jun 25, 2019
TUTORIAL_SIMPLE.md documentation update Apr 15, 2019
TUTORIAL_USE.md Reverted bad change in ...FROMXML.md Jun 25, 2019
diagrams.graffle documentation continued May 26, 2019
genpom.xml pom files are cooked to jam Mar 6, 2019
plugins.jim pom files are cooked to jam Mar 6, 2019
pom.jim pom files are cooked to jam Mar 6, 2019
pom.xml surefire version bumped up to 2.22.1 Jul 1, 2019
pom.xml.jam surefire version bumped up to 2.22.1 Jul 1, 2019
release.sh release.sh updated Jan 29, 2019
run.py documentation Oct 9, 2018
version.jim source comparator can be defined May 9, 2019

README.md

Java::Geci

Java Generate Code Inline

Java::Geci is a library for generating Java code. Code generation programs implemented using Java::Geci can be executed to generate new source code or modify existing Java source files. This way the programmer can use meta programming to express code in a shorter and more expressive way than it would be possible in pure Java.

The framework discovers the files that need generated code, provides easy to use API to generate code and takes care of writing the generated code into the source code. The code generating program should focus on the actual code structure it wants to generate.

When do you need Java::Geci?

There are several occasions when we need generated code. The simplest such scenarios are also supported by IDEs (Eclipse, NetBeans, IntelliJ). They can create setters, getters, constructors, equals() and hashCode() methods in different ways. There are two major problems with that solution.

  • One is that the code generation is manual, and in case the developer forgets to re-generate the code after an influencing change the code becomes outdated.

  • The other problem is that the code generation possibilities are not extendable. There is a limited set of code that the tools can generate and the developer cannot easily extend these possibilities.

Java::Geci eliminates these two problems. It has an execution mode to check if all code generation is up-to-date and this can be used as a unit test. If the developer forgot to update some of the generated code after the program effecting the generated code was changed, the test will fail. (As a matter of fact the test also updates the generated code, you only need to start the build phase again.)

Java::Geci also has an extremely simple API supporting code generators so it is extremely simple to create new code generators that are project specific. You do not even need to package your code generator classes. Just put them into some of the test packages and execute Java::Geci during the test phase of the build process.

Java::Geci already includes several readily available code generators. These are packaged with the core package and can generate

  • setter and getter
  • delegation methods (under development)
  • fluent API classes and interfaces
  • others will be under development

How to use Java::Geci

Include the Java::Geci modules that you want to use in your project. To do that with maven use the following dependencies:

<dependency>
    <!-- This is optional, you can use your own annotations or comment config -->
    <groupId>com.javax0.geci</groupId>
    <artifactId>javageci-annotation</artifactId>
    <version>1.1.2-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>com.javax0.geci</groupId>
    <artifactId>javageci-engine</artifactId>
    <scope>test</scope>
    <version>1.1.2-SNAPSHOT</version>
</dependency>

This documentation contains the latest development version. For release versions you can use see the latest non-SNAPSHOT version in the release history documentation.

There are other modules, but you do not need to declare dependency on them as the engine module has transitive dependency and thus maven automatically will use them. Since Java::Geci works during test execution the dependencies have test scope. The exception is the annotation module. This module defines an annotation that can be used to configure the code generation during test time. Because of that the retention of this module is run-time. Although the annotation is not used in production but it remains in the byte code and thus is has to be the default maven scope.

If for any reason production dependency must not include Java::Geci you can configure some of the generators using comments or you can use your own annotation interfaces that you can define inside your project. Simply copy the Geci.java and Gecis.java to your project into any of your packages and Java::Geci will recognize that they are to configure a generator.

If you look at the test code TestAccessor.java in the test module you can see that this is a proof of concept demonstration sample code:

package javax0.geci.tests.accessor;

import javax0.geci.accessor.Accessor;
import javax0.geci.engine.Geci;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static javax0.geci.api.Source.maven;

public class TestAccessor {

    @Test
    public void testAccessor() throws Exception {
        Assertions.assertFalse(new Geci().source(maven()
                        .module("javageci-examples").mainSource())
                        .register(Accessor.builder().build()).generate(),
                Geci.FAILED);
    }
}

The test runs during the build process and it generates files if that is needed. If files were generated it means that the code was not up to date and a new compilation has to be done. In this case the Assertions.fail() will be invoked and you have to start the build process again. Second time the code generation will recognize that the code it could generate is already there and the process will not fail.

For further information visit the following documentations

You can’t perform that action at this time.