{"id":28356783,"url":"https://github.com/askmeagain/lazygen","last_synced_at":"2025-07-15T10:40:43.621Z","repository":{"id":57732490,"uuid":"469491179","full_name":"AskMeAgain/LazyGen","owner":"AskMeAgain","description":"Java Code Generator to add Lazy/Caching methods to any class/interface. Also compatible with MapStruct!","archived":false,"fork":false,"pushed_at":"2022-03-27T13:46:00.000Z","size":268,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-04T12:46:46.147Z","etag":null,"topics":["codegeneration","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AskMeAgain.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":"2022-03-13T20:48:27.000Z","updated_at":"2024-08-07T15:05:27.000Z","dependencies_parsed_at":"2022-09-10T23:02:02.023Z","dependency_job_id":null,"html_url":"https://github.com/AskMeAgain/LazyGen","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/AskMeAgain/LazyGen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AskMeAgain%2FLazyGen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AskMeAgain%2FLazyGen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AskMeAgain%2FLazyGen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AskMeAgain%2FLazyGen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AskMeAgain","download_url":"https://codeload.github.com/AskMeAgain/LazyGen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AskMeAgain%2FLazyGen/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265429198,"owners_count":23763706,"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":["codegeneration","java"],"created_at":"2025-05-28T07:09:40.853Z","updated_at":"2025-07-15T10:40:43.612Z","avatar_url":"https://github.com/AskMeAgain.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LazyGen\n\nThis annotation processor adds a lazy/cacheable method to any non-final method annotated with `@LazyGen` via code\ngeneration.\n\nNote: A Lazy/Cacheable method is a method which only executes its body once and keeps a copy of the result in memory.\n\n## Gradle\n\n    annotationProcessor 'io.github.askmeagain:lazygenprocessor:1.2.1'\n    implementation 'io.github.askmeagain:lazygenprocessor:1.2.1'\n\n## Getting Started\n\n1. Add LazyGen package and annotation processor to your project\n2. Add `@GenerateLazyClass(ResultType.XXX)` to a class (or interface in case\n   of [MapStruct mapper](https://github.com/mapstruct/mapstruct))\n3. Specify how your result should look like:\n   1. `ResultType.CLASS`: Creates a normal class which extends the original class\n   2. `ResultType.ABSTRACT_CLASS`: Creates an abstract class which extends/implements the interface\n   3. `ResultType.MAPSTRUCT_COMPATIBLE`: Creates an abstract class, prepared correctly for usage with\n      [MapStruct](https://github.com/mapstruct/mapstruct)\n   4. `ResultType.MAPSTRUCT_COMPATIBLE_WITHOUT_ANNOTATIN` is the same as step 3, but the @Mapper annotation is not added\n4. Add `@LazyGen` to any method on this class and any childs (class or interface doesnt matter)\n5. Hit build\n6. A class is generated which inherits the original class, with Lazy as suffix\n\n## OneTimeUsage vs MultiUsage\n\nYou can also specify how the caching should be implemented:\n\n* `ONE_TIME_USE`: returns always the same (cached) value, ignoring the input parameters\n* `MULTI_USE`: will cache the result of the method in a map based on a key. The key is calculated via\n  `hashCode()` of the input parameters\n* `PARENT`: default on `@LazyGen` methods, use what the `@GenerateLazyClass` specified (by default `ONE_TIME_USE`)\n\nYou can configure a general usage, via `@GenerateLazyClass(usage = ONE_TIME_USE)`, but each `@LazyGen` method can\noverride this behaviour by themselves.\n\n## Making MapStruct lazy\n\n1. Add `@GenerateLazyClass(ResultType.MAPSTRUCT_COMPATIBLE)` to your mapstruct mapper\n2. Remove `@Mapper` annotation from your mapper\n3. Add `@LazyGen` to any method\n4. Get your MapStruct mapper via `Mappers.getMapper(XXXXXXLazy.class);`\n\nNote: Methods which are touched by the MapStruct annotation processor can only be made lazy if they are\nimplemented/referenced via `@Named` annotation or else MapStruct cannot find the correct method since the `@Named`\nannotation is not inheritable.\n\n## Examples\n\n### Simple Example\n\n\u003cdetails\u003e\u003csummary\u003eBefore\u003c/summary\u003e\n\u003cp\u003e\n\n    @GenerateLazyClass\n    public class NormalClass {\n        \n        @LazyGen\n        String abc(){\n            return \"Test\";\n        }\n    }\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eAfter\u003c/summary\u003e\n\u003cp\u003e\n\n    public class LazyNormalClass extends NormalClass {\n        private java.lang.String _abc;\n        \n        @Override\n        public java.lang.String abc() {\n            if (_abc != null) {\n                return _abc;\n            }\n            _abc = super.abc();\n            return _abc;\n        }\n    }\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n### MapStruct Example\n\n\u003cdetails\u003e\u003csummary\u003eBefore\u003c/summary\u003e\n\u003cp\u003e\n\n    @GenerateLazyClass(ResultType.MAPSTRUCT_COMPATIBLE)\n    public interface TestMapper {\n    \n        @Mapping(target = \".\", source = \"input\", qualifiedByName = \"a\")\n        String mapSummations(String input);\n        \n        @LazyGen\n        @Named(\"a\")\n        default String a(TestMapper calculator) {\n            System.out.println(\"a\");\n            return \"a\";\n        }\n    }\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eAfter\u003c/summary\u003e\n\u003cp\u003e\n\n    @Mapper\n    public abstract class LazyTestMapper implements TestMapper {\n    \n        @Named(\"a\")\n        @Override\n        public java.lang.String a(io.github.askmeagain.lazygen.calculator.simple.MapstructAbstractClass _TestMapper0) {\n            if (_a != null) {\n                return _a;\n            }\n            _a = TestMapper.super.a(_TestMapper0);\n            return _a;\n        }\n        private java.lang.String _a;\n    }\n\n\u003c/p\u003e\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faskmeagain%2Flazygen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faskmeagain%2Flazygen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faskmeagain%2Flazygen/lists"}