{"id":16374971,"url":"https://github.com/moderocky/mimic","last_synced_at":"2025-03-21T01:32:14.113Z","repository":{"id":103957289,"uuid":"439128387","full_name":"Moderocky/Mimic","owner":"Moderocky","description":"A stronger alternative for Java's Proxy API. Allows the creation of 'mimicked' classes and interfaces with the ability to replace their method behaviour.","archived":false,"fork":false,"pushed_at":"2024-05-08T09:34:08.000Z","size":51,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-12T03:19:08.442Z","etag":null,"topics":["bytecode","java","java-17","proxy","reflection"],"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/Moderocky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-16T21:13:08.000Z","updated_at":"2024-05-08T09:42:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"a242e24f-0730-4cda-a4ab-a31eed7003e0","html_url":"https://github.com/Moderocky/Mimic","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moderocky%2FMimic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moderocky%2FMimic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moderocky%2FMimic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moderocky%2FMimic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Moderocky","download_url":"https://codeload.github.com/Moderocky/Mimic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221811251,"owners_count":16884285,"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":["bytecode","java","java-17","proxy","reflection"],"created_at":"2024-10-11T03:19:00.545Z","updated_at":"2024-10-28T09:05:23.146Z","avatar_url":"https://github.com/Moderocky.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Mimic\n=====\n\n### Opus #10\n\nA replacement candidate for Java's Proxy API. Allows the creation of 'mimicked' classes and interfaces with the ability to replace their method behaviour.\n\n## Maven Information\n```xml\n\u003crepository\u003e\n    \u003cid\u003ekenzie\u003c/id\u003e\n    \u003cname\u003eKenzie's Repository\u003c/name\u003e\n    \u003curl\u003ehttps://repo.kenzie.mx/releases\u003c/url\u003e\n\u003c/repository\u003e\n``` \n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003emx.kenzie\u003c/groupId\u003e\n    \u003cartifactId\u003emimic\u003c/artifactId\u003e\n    \u003cversion\u003e1.1.0\u003c/version\u003e\n    \u003cscope\u003ecompile\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n## Introduction\n\nThis small library was designed to replace the `java.lang.reflect.Proxy` system in the JDK's reflection API. Like most of the API, proxies are filled with needless, slow boilerplate and use old-fashioned practices with faster, modern alternatives.\n\nThese internal APIs are very difficult to replace with third-party implementations: JDK classes benefit from being able to avoid module security, instruction verification and having access to powerful system methods that are completely barred to other packages in newer Java versions.\nBy using my *Weapons of Disorder*, Mimic is able to access some of these internal benefits allowing it to sufficiently replace proxies.\n\nMimic allows the superficial creation of any (non-final) type, with user-provided method behaviour. Unlike Java proxies, Mimic is not limited only to interfaces and allows superclasses to be used as well. No reflection is used during method-calling.\n\nThis is effected by writing a class at runtime which adapts all the available methods to call a user-provided invoker system very similar to Java's proxy handler but without using a reflection object to increase speed and reliability.\n\nMimic also comes with some tools for building more advanced proxy behaviour, such as forwarding specific methods directly to objects (or object-suppliers), mapping methods to individual executors or simply not implementing a method at all.\nWhile the resulting behaviour is achievable with the JDK's Proxy, it will be significantly slower as Mimic bakes the access route directly into the compiled code for maximum efficiency.\n\n## Examples\n\nCreating a very basic mimic, identical in function to Java's proxies:\n```java \ninterface Blob {\n    String say(String word);\n}\n\nfinal Blob blob = Mimic.create((proxy, method, arguments) -\u003e arguments[0], Blob.class);\nassert blob.say(\"hello\").equals(\"hello\");\n```\n\nMimicking a default class:\n```java \nclass Alice {\n    public Instant timeNow() {\n        return Instant.now();\n    }\n}\n\nfinal Alice alice = Mimic.create((proxy, method, arguments) -\u003e Instant.EPOCH, Alice.class);\nassert alice.timeNow().equals(Instant.EPOCH);\n```\n\nMimicking multiple types:\n```java \nclass Alice {\n}\n\ninterface Bob {\n}\n\nfinal Alice alice = Mimic.create(executor, Alice.class, Bob.class);\nassert alice instanceof Bob;\n```\n\nForwarding calls to an object:\n```java \ninterface Thing {\n    int bean(int i);\n    \n    String say(String word);\n}\n\nclass Box {\n    public int bean(int i) {\n        return 0;\n    }\n    \n    public String say(String word) {\n        return \"hello\";\n    }\n}\n    \nfinal Thing thing = Mimic.create(Thing.class).forward(new Box()).build();\nassert !(thing instanceof Box); // not a Box\nassert thing.bean(3) == 0; // forwarded call to the new Box()\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoderocky%2Fmimic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoderocky%2Fmimic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoderocky%2Fmimic/lists"}