{"id":13810756,"url":"https://github.com/google/CallBuilder","last_synced_at":"2025-05-14T15:31:11.863Z","repository":{"id":29737468,"uuid":"33280870","full_name":"google/CallBuilder","owner":"google","description":"Make a Java builder by defining one function.","archived":true,"fork":false,"pushed_at":"2018-01-12T23:47:34.000Z","size":263,"stargazers_count":106,"open_issues_count":6,"forks_count":24,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-19T22:27:10.976Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/google.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-02T00:45:33.000Z","updated_at":"2024-10-25T12:32:14.000Z","dependencies_parsed_at":"2022-09-06T09:10:40.371Z","dependency_job_id":null,"html_url":"https://github.com/google/CallBuilder","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2FCallBuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2FCallBuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2FCallBuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2FCallBuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google","download_url":"https://codeload.github.com/google/CallBuilder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254171724,"owners_count":22026500,"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-08-04T03:00:24.920Z","updated_at":"2025-05-14T15:31:06.852Z","avatar_url":"https://github.com/google.png","language":"Java","readme":"# CallBuilder\nMake a builder by defining one function.  \n(_beta_: be ready for breaking API changes)\n\n*CallBuilder* is a Java code generator that finally makes it easy to make a\nbuilder class. Builders are great when you have a constructor or method with\nmany parameters. They are even helpful when you have two or more arguments of\nthe same type, since the order is easy to mix up.\n\nBuilders are usually hard to write. You will probably need around 4 lines for\nevery field, and if it's an inner class, it makes the file long and cumbersome\nto navigate. This discourages many people from writing builders, and those\npeople give up and learn to live with brittle, and hard-to-read code. If you\nwant to add multiple setters for a field (common for lists that may have add and\naddAll), your builder will quickly become a chore to write and a burden to\nmaintain.\n\nCallBuilder changes that. To use it, you can simply write the method or\nconstructor as you normally would, but add the `@CallBuilder` annotation:\n\n```java\npublic class Person {\n  @CallBuilder\n  Person(\n      String familyName,\n      String givenName,\n      List\u003cString\u003e addressLines,\n      @Nullable Integer age) {\n    // ...\n  }\n}\n```\n\nNow you will have access to a `PersonBuilder` class in the same package!\n\n```java\nPerson friend = new PersonBuilder()\n    .setAddressLines(Arrays.asList(\"1123 Easy Street\", \"Townplace, XZ\"))\n    .setAge(22)\n    .setGivenName(\"John\")\n    .setFamilyName(\"Doe\")\n    .build();\n```\n\nWith the field styles feature, you can define custom behavior for the fields\nthat are of a certain type. This can make the API more natural and look more\nlike a manually-written builder:\n\n```java\npublic class Person {\n  @CallBuilder\n  Person(\n      String familyName,\n      String givenName,\n      @BuilderField(style = ArrayListAdding.class) ArrayList\u003cString\u003e addressLines,\n      @Nullable Integer age) {\n    // ...\n  }\n}\n```\n\nThis can be used like:\n\n```java\nPerson friend = new PersonBuilder()\n    .addToAddressLines(\"1123 Easy Street\")\n    .addToAddressLines(\"Townplace, XZ\")\n    .setAge(22)\n    .setGivenName(\"John\")\n    .setFamilyName(\"Doe\")\n    .build();\n```\n","funding_links":[],"categories":["Projects built with Bazel"],"sub_categories":["Google projects"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2FCallBuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle%2FCallBuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2FCallBuilder/lists"}