Skip to main content

lance

lance is a library to generate code from code.

Usage

Let's see how we can generate code by using lance

Java

Class Generation

Here is a json file which is fed to lance library to generate java code

 {
   "fqcn": "com.susamn.MetaClass",
   "type": "CLASS"
 }

generates java code as:

package com.susamn;

public class MetaClass {

}
  • fqcn is Fully Qualified Class Name

Seems pretty easy right. Let's see some involved code generation which is usable. Here is the json file for that:

{
  "generate_path": "",
  "classes":[
    {
      "fqcn": "com.susamn.Meta",
      "type": "CLASS",
      "extends": {
        "fqcn": "com.susamn.Parent",
        "generic_types": ["java.lang.Integer"]
      },
      "implements": [
        {
          "fqcn": "java.io.Serializable",
          "generic_types": ["java.lang.Integer"]
        },
        {
          "fqcn": "org.apache.Logger",
          "generic_types": ["com.susamn.Root","java.lang.String"]
        }

      ],
      "annotations": [
        {
          "fqcn": "com.susamn.ClassLevelAnnotation1"
        },
        {
          "fqcn": "com.susamn.ClassLevelAnnotation2",
          "data": {
            "key1": {
             "type": "INTEGER",
             "value": 23
           }
         }
        }
      ],
      "attributes": [
        {
          "name": "logger",
          "mode": "public",
          "type": {
            "of": "CLASS",
            "fqcn": "org.slf4j.api.Logger"
          },
          "accessors": true,
          "initialized_form": {
            "form": "LoggerFactory.getLogger(RiskAssessmentController.class)",
            "imports": ["org.apache.logger.api.LoggerFactory","com.susamn.RiskAssessmentController"]
          }
        },
        {
          "name": "foo",
          "mode": "private",
          "type": {
           "of": "STRING"
          },
          "accessors": true,
          "initialized_form": {
            "form": "\"Foo_Value\"",
            "imports": []
          },
          "annotation_level": "GETTER_ANNOTATION",
          "annotations": [
           {
              "fqcn": "com.susamn.Annotation1",
              "data": {
               "key1": {
                 "type": "INTEGER",
                 "value": 23
                }
             }
           },
            {
             "fqcn": "com.susamn.Annotation2",
              "data": {
                "key1": {
                 "type": "STRING",
                  "value": "String data"
                }
             }
            }
          ]
       },
        {
          "name": "foobar",
          "mode": "private",
         "type": {
           "of": "STRING"
         },
         "accessors": true,
          "annotations": [
            {
              "fqcn": "com.susamn.Annotation3"
            },
            {
              "fqcn": "com.susamn.Annotation4",
              "data": {
               "key1": {
                  "type": "INTEGER",
                  "value": 23
                }
              }
           }
          ]
       },
        {
          "name": "bar",
          "mode": "private",
         "type": {
           "of": "LIST_STRING"
         },
         "accessors": true
       },
        {
         "name": "far",
         "mode": "private",
          "type": {
            "of":"LIST_INTEGER"
          },
         "accessors": true
        },
       {
          "name": "boo",
         "mode": "private",
          "type": {
            "of":"LIST_CLASS",
           "fqcn": "com.susamn.Custom"
          },
          "accessors": true
       },
       {
          "name": "doo",
          "mode": "private",
          "type": {
            "of":"INTEGER"
         },
         "accessors": true
       },
        {
          "name": "dar",
          "mode": "private",
         "type": {
            "of":"FLOAT"
         }
       }
     ],
      "methods": [
       {
         "name": "processRequest",
         "mode": "public",
         "type": {
           "of": "STRING"
         },
         "inputs": [
           {
              "name": "body",
              "type": {
               "of": "STRING",
               "annotations": [
                 {
                    "fqcn": "com.susamn.ResponseBody"
                  }
                ]
              }
            },
            {
              "name": "clazz",
             "type": {
               "of":"LIST_CLASS",
               "fqcn": "com.susamn.Custom2"
              }
           },
           {
             "type": {
               "of": "CLASS",
               "fqcn": "org.springframework.web.mvc.HttpEntity",
               "generic_types": ["java.lang.String"]
             }
           }
         ],
          "annotations": [
            {
              "fqcn": "com.susamn.Annotation11",
             "data": {
               "key1": {
                  "type": "INTEGER",
                  "value": 78.10
               }
              }
            },
            {
              "fqcn": "com.susamn.Annotation10",
              "data": {
                "key1": {
                 "type": "INTEGER",
                 "value": 12.19
               }
              }
            }
          ]
        },
        {
          "name": "syncRequest",
          "mode": "public",
          "type": {
            "of": "CLASS",
            "fqcn": "org.springframework.web.mvc.HttpEntity",
            "generic_types": ["GENERIC"]
          },
          "inputs": [
            {
              "name": "value",
              "type": {
                "of": "STRING",
                "annotations": [
                  {
                    "fqcn": "com.susamn.ResponseBody"
                  }
                ]
              }
            }
          ]
        },
        {
          "name": "deleteRequest",
          "mode": "public",
          "type": {
            "of": "CLASS",
            "fqcn": "org.springframework.web.mvc.HttpEntity",
            "generic_types": ["java.lang.Boolean"]
          },
          "inputs": [
            {
              "type": {
                "of": "STRING",
                "annotations": [
                  {
                    "fqcn": "com.susamn.ResponseBody"
                  }
                ]
              }
            }
          ],
          "body": {
            "form": ["Map<Integer,RiskAssessment> map = new HashMap<>();", "map.put(1, new RiskAssessment());"],
            "imports": ["java.util.Map","java.util.HashMap","com.susamn.RiskAssessment"]
          }
        }
      ]
    }
  ]
}

this generates java code:

package com.susamn;

import com.susamn.Annotation1;
import com.susamn.Annotation10;
import com.susamn.Annotation11;
import com.susamn.Annotation2;
import com.susamn.Annotation3;
import com.susamn.Annotation4;
import com.susamn.ClassLevelAnnotation1;
import com.susamn.ClassLevelAnnotation2;
import com.susamn.Custom;
import com.susamn.Custom2;
import com.susamn.Parent;
import com.susamn.ResponseBody;
import com.susamn.RiskAssessment;
import com.susamn.RiskAssessmentController;
import com.susamn.Root;
import java.io.Serializable;
import java.lang.Boolean;
import java.lang.Integer;
import java.lang.String;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.Logger;
import org.apache.logger.api.LoggerFactory;
import org.slf4j.api.Logger;
import org.springframework.web.mvc.HttpEntity;


@ClassLevelAnnotation1
@ClassLevelAnnotation2(key1 = 23)
public class Meta extends Parent<Integer> implements Serializable<Integer>, Logger<Root,String> {

    public Logger logger = LoggerFactory.getLogger(RiskAssessmentController.class);
    private List<String> bar;
    private List<Integer> far;
    private List<Custom> boo;
    private int doo;
    private float dar;

    @Annotation1(key1 = 23)
    @Annotation2(key1 = "String data")
    private String foo = "Foo_Value";

    @Annotation3
    @Annotation4(key1 = 23)
    private String foobar;

    public Logger getLogger(){
        return this.logger;
    }
    public void setLogger(Logger logger){
        this.logger = logger;
    }
    public String getFoo(){
        return this.foo;
    }
    public void setFoo(String foo){
        this.foo = foo;
    }
    public String getFoobar(){
        return this.foobar;
    }
    public void setFoobar(String foobar){
        this.foobar = foobar;
    }
    public List<String> getBar(){
        return this.bar;
    }
    public void setBar(List<String> bar){
        this.bar = bar;
    }
    public List<Integer> getFar(){
        return this.far;
    }
    public void setFar(List<Integer> far){
        this.far = far;
    }
    public List<Custom> getBoo(){
        return this.boo;
    }
    public void setBoo(List<Custom> boo){
        this.boo = boo;
    }
    public int getDoo(){
        return this.doo;
    }
    public void setDoo(int doo){
        this.doo = doo;
    }
    @Annotation11(key1 = 78.1)
    @Annotation10(key1 = 12.19)
    public String processRequest(@ResponseBody String body, List<Custom2> clazz, HttpEntity<String> val0){
    }
    public HttpEntity<?> syncRequest(@ResponseBody String value){
    }
    public HttpEntity<Boolean> deleteRequest(@ResponseBody String val0){
        Map<Integer,RiskAssessment> map = new HashMap<>();
        map.put(1, new RiskAssessment());
    }

}

Metadata

Release files for lance 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lance 1.2.1
File Size Uploaded Provenance Actions
lance-1.2.1.tar.gz 16.2 kB Without provenance Details for lance-1.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lance 1.2.1
File Interpreter ABI Platform Actions
lance-1.2.1-py3-none-any.whl Python 3 none any Details for lance-1.2.1-py3-none-any.whl

Total release size: 38.8 kB

Release files / lance-1.2.1.tar.gz

Download URL lance-1.2.1.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2849817a5eb7f5e610a4cf766bc3bd096d7f9e230bcc5a60c8dd3986510705e4
BLAKE2b-256 checksum
How to use checksums
6d2f19bab0b1d8d5a4917581db6a7d2e132cca11323192f476cd27ed996192bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Release files / lance-1.2.1-py3-none-any.whl

Download URL lance-1.2.1-py3-none-any.whl
Size 22.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f9ac09055c7935c8d351bccd5f0deda9ecfce6b31fb1acdf650ef97140114137
BLAKE2b-256 checksum
How to use checksums
981ed47c5ff992a79d3987b4ac0a4d8a905457099f7def942dc6e1bd9c2216e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Security for lance 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page