Java Code Generator - Zontroy

Java Code Generator

What do you think of creating hundreds of code files with the code inside in just a few minutes using Zontroy as a Java Code Generator? 

Zontroy Generator is a developer tool for generating source code. Zontroy is compatible with Java and all Java frameworks. You can generate Java code using Zontroy IDE or command line of any known IDE such as Visual Studio Code, Eclipse or Netbeans.

Zontroy can be used for any kind of java project. For our example, we are going to generate a sample code. Let’s write a java controller class as a sample and generate other classes we need using the sample class.

//CustomerController.java
public class CustomerController {
    @Autowired
    private CustomerRepository customerRepository;

    @GetMapping("/customers")
    public List getAllCustomers() {
        return customerRepository.findAll();
    }
}

By modifying the code as shown below, we can generate other classes we need.

// [[[zg-entity...zg-name]]]Controller.java.zref
public class [[[zg-entity...zg-name]]]Controller {
    @Autowired
    private [[[zg-entity...zg-name]]]Repository zg-lowerFirstCase(((zg-entity...zg-name)))Repository;

    @GetMapping("/zg-lowerFirstCase(((zg-entity...zg-name)))s")
    public List[[[zg-entity...zg-name]]] getAll[[[zg-entity...zg-name]]]s() {
        return zg-lowerFirstCase(((zg-entity...zg-name)))Repository.findAll();
    }
}

Let’s look at the details:

1. Go to File > New Project.

2. Create an Empty Zontroy Project

3. Fill in the form with the required project details. PostgreSQL and Pagila Database is used at this sample. Pagila Database is available on github. If you like, you can use Oracle, MySQL or MSSQL databases as well with the same code sample. Java is selected as the programming language and the project name is given. Location is the directory on our pc.

4. We need to add a template file in order to generate code. These template files are required and function as the input for Zontroy. We add a zref (Zontroy Repeating File) to the project for this example.

5. Name the file as below to create a code file for each entity. It refers to the name of each entity based on our database or entity repository. Other predefined properties of an entity is defined in our documentation section.

6. Write the generation code in zref. All of the keywords begin with “zg-” prefix. In this way, you don’t need to split your code using quotes, double quotes or any other character. [[[zg-entity…zg-name]]] will be replaced with the name of the entity by Zontroy Interpreter. There are plenty of built-in functions to use in our library such as “zg-lowerFirstCase”. Detailed information about built-in functions are provided on our Docs pageDocs page.

7. Generate other files and source code.

8. Review the generated code. Generation process is completed at this step. We have generated 21 code files with their implemented code in seconds.

This is a sample application on using Zontroy as a Java Code Generator. You can generate any type of code files in this way, even a javascript file or typescript file.

Zontroy is a very flexible tool to use for any layer of your multi-tier applications. It doesn’t matter if your project is a desktop, web or mobile application. You can develop code like a development team by yourself using Zontroy.

Download Zontroy and start generating code for your applications!

Comments

  • HM Rajahamsa

    28 May 2022

    Good platform to learn more

    reply
    • Zontroy Team

      29 May 2022

      Thanks!

      reply
  • HM Rajahamsa

    28 May 2022

    I wanted to learn soon as possible

    reply
    • Zontroy Team

      29 May 2022

      Thank you for your interest!

      Zontroy generates many parts of source code which are normally written manually. It is an easy to use developer tool and boosts the productivity of developers. You can check our Docs and Videos pages, and Blog posts to learn more. And always feel free to ask your questions!

      Best,
      Zontroy Team

      reply
  • Djimgou Dany

    10 April 2022

    Hi thank you for this AWESOME TOOL. I think it’s the next generation generator for developer. I’m using the free one, but it lacks many useful FEATURES.

    For example in java generation:
    – how the get root package, or current file package? How to walk inside packages hiérarchie? Parent package, …

    – for example [[[java:zg-package…name]]] to get the current file package name
    – [[[java:ZG-PACKAGE…SimpleNAME]]] to get Simple name package name

    In addition how to get a referenced entity object when iteration through entity fields?
    For exemple you have provided
    [[[Item…referencedEntityname]]] which is very good. But It should better to provide a way to iteration over entity hiérarchy. For example:

    [[[ITEM…REFERENCEDENTITY:name]]]

    [[[ITEM…REFERENCEDENTITY:Fields]]]

    [[[ITEM…REFERENCEDENTITY:FkFIELDS]]]

    …..

    Thank you in advance.

    Please is it possible to contribute in zontroy development as developer?

    reply
    • Zontroy

      25 April 2022

      Hi, thank you for using Zontroy!

      We appreciate your feedback and kind words. It is, actually, possible to perform many code generation tasks with Zontroy Free. The features you mentioned are not limitations of Zontroy Free. Package Name and Referenced Entity features are included in the upcoming release which is currently being tested.

      Zontroy 2.2.2 will be out soon!

      Best,
      Zontroy Team

      P.S. Thank you for your offer to contribute. For now, you can develop Zontroy templates and contribute to Zontroy Template Store. In order to do that, you should first open a Zontroy user account.

      reply

Post a Comment