{"id":13485577,"url":"https://github.com/sviperll/adt4j","last_synced_at":"2025-03-16T17:34:04.807Z","repository":{"id":13114566,"uuid":"15796294","full_name":"sviperll/adt4j","owner":"sviperll","description":"adt4j - Algebraic Data Types for Java","archived":false,"fork":false,"pushed_at":"2018-03-02T08:07:43.000Z","size":5422,"stargazers_count":143,"open_issues_count":12,"forks_count":8,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-10-12T07:16:37.980Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sviperll.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-10T11:22:52.000Z","updated_at":"2024-06-04T02:15:43.000Z","dependencies_parsed_at":"2022-08-26T22:31:27.643Z","dependency_job_id":null,"html_url":"https://github.com/sviperll/adt4j","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sviperll%2Fadt4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sviperll%2Fadt4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sviperll%2Fadt4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sviperll%2Fadt4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sviperll","download_url":"https://codeload.github.com/sviperll/adt4j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221666405,"owners_count":16860415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T18:00:26.757Z","updated_at":"2024-10-27T10:58:55.575Z","avatar_url":"https://github.com/sviperll.png","language":"Java","funding_links":[],"categories":["Projects","Java","项目","I. Development","Development"],"sub_categories":["Code Generators","代码生成器","8. Code generation and changing byte code"],"readme":"adt4j - Algebraic Data Types for Java\n=====================================\n\nThis library implements [Algebraic Data Types](http://en.wikipedia.org/wiki/Algebraic_data_type) for Java.  \nADT4J provides annotation processor for `@GenerateValueClassForVisitor` annotation.  \nADT4J generates new class for each `@GenerateValueClassForVisitor` annotation.\n\nIt allows you to easily define custom data types. Like this:\n\n```java\n// Define Expression data type\n@WrapsGeneratedValueClass(visitor = ExpressionVisitor.class)\n// ExpressionBase class will be automatically generated by annotation processor\n// You can use any other name instead of ExpressionBase, like VeryLongNameThatYouShouldNeverActuallyUse\nclass Expression extends ExpressionBase {\n  public static void main(String[] args) {\n    // Static constructor methods are automatically generated for Expression class\n    Expression e = mul(sum(lit(5), lit(1)), lit(2));\n\n    // Reasonable default toString implementation is provided:\n    System.out.println(e + \" = \" + e.eval());\n  }\n\n  // This is the required boilerplate for wrapper-class\n  Expression(ExpressionBase base) {\n    super(base);\n  }\n\n  // Example of \"pattern-matching\"\n  int eval() {\n    return accept(new ExpressionVisitor\u003cInteger\u003e() {\n      Integer lit(int i) {\n        return i;\n      }\n      Integer sum(Expression e1, Expression e2) {\n        return e1.eval() + e2.eval();\n      }\n      Integer mul(Expression e1, Expression e2) {\n        return e1.eval() * e2.eval();\n      }\n    });\n  }\n\n  // Actual data-type definition\n  // Data type is recursive. No special treatment of recursive definition is required.\n  @GenerateValueClassForVisitor(wrapperClass = Expression.class)\n  @Visitor(resultVariableName=\"R\")\n  interface ExpressionVisitor\u003cR\u003e {\n    @GeneratePredicate(name = \"isLiteral\");\n    R lit(int i);\n\n    R sum(@Getter(name = \"leftOperand\") Expression e1, @Getter(name = \"rightOperand\") Expression e2);\n    R mul(@Getter(name = \"leftOperand\") Expression e1, @Getter(name = \"rightOperand\") Expression e2);\n  }\n\n}\n```\n\nFeatures\n--------\n\n * Support recursive data types\n * Generate hashCode, equals and toString implementations with value semantics\n * Generate predicates, getters and \"updaters\" with additional annotations\n * Fully customizable API: custom names and access levels for generated methods\n * Optionally generate Comparable implementation with precise compile-time type-check if it is possible\n * Optionally generate serializable classes with precise compile-time type-check if it is possible\n * Sensible error messages\n * Support generated class extention through standard Java's inheritance.\n * Reasonably fast\n\nKnown Issues\n------------\n\n * maven-compiler-plugin version 3.2 and later doesn't work nicely with\n   annotation processors, see [MCOMPILER-235](https://issues.apache.org/jira/browse/MCOMPILER-235).\n   Only clean builds work. Repeated compilation causes duplicate class errors.\n\n * It is possible to support explicit recursive data-types definitions\n   without `selfReferenceVariableName` hack, but\n   [javac bug](http://mail.openjdk.java.net/pipermail/compiler-dev/2015-November/009864.html)\n   prevents it from working. It works when no type-parameters are used,\n   see [IntListVisitor.java example](https://github.com/sviperll/adt4j/blob/master/adt4j-examples/src/main/java/com/github/sviperll/adt4j/examples/IntListVisitor.java.\n\nLicense\n-------\n\nADT4J is under BSD 3-clause license.\n\nFlattr\n------\n\n[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=sviperll\u0026url=https%3A%2F%2Fgithub.com%2Fsviperll%2Fadt4j\u0026title=adt4j\u0026language=Java\u0026tags=github\u0026category=software)\n\nInstallation\n------------\n\nUse maven dependency to use ADT4J:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.sviperll\u003c/groupId\u003e\n  \u003cartifactId\u003eadt4j\u003c/artifactId\u003e\n  \u003cversion\u003e3.2\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nYou can use `adt4j-shaded` artifact to simplify deployment and to avoid dependencies' conflicts.\n`adt4j-shaded` has no dependencies and does not pollute classpath.\nAll java-packages provided by `adt4j-shaded` are rooted at `com.github.sviperll.adt4j` package.\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.sviperll\u003c/groupId\u003e\n  \u003cartifactId\u003eadt4j-shaded\u003c/artifactId\u003e\n  \u003cversion\u003e3.2\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n\nChangelog\n---------\n\nSee [NEWS file](https://github.com/sviperll/adt4j/blob/master/NEWS.md).\n\nUsage\n-----\n\nSee [Tutorial](https://github.com/sviperll/adt4j/wiki/Tutorial)\n\nBuild\n-----\n\n    $ git clone git@github.com:sviperll/adt4j.git\n    $ cd adt4j\n    $ mvn test\n\nCheck for errors and warnings.\n\nADT4J is built to be compatible with Java 7.\nSee [universal-maven-parent](https://github.com/sviperll/universal-maven-parent) project's documentation\nfor instructions about building projects compatible with JDK7.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsviperll%2Fadt4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsviperll%2Fadt4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsviperll%2Fadt4j/lists"}