{"id":18080725,"url":"https://github.com/omaraflak/annotation-processor-sample","last_synced_at":"2025-04-12T14:24:14.091Z","repository":{"id":82863372,"uuid":"100613234","full_name":"omaraflak/Annotation-Processor-Sample","owner":"omaraflak","description":"Simple example to illustrate the use of android annotation and annotation processor.","archived":false,"fork":false,"pushed_at":"2024-08-15T13:30:26.000Z","size":180,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T14:24:09.916Z","etag":null,"topics":["android","annotation","annotation-processor","annotationprocessor","generated-code","processor","tutorial"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/omaraflak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-08-17T14:37:21.000Z","updated_at":"2020-05-11T10:03:44.000Z","dependencies_parsed_at":"2023-03-02T04:45:39.837Z","dependency_job_id":"c77f15d0-b0b6-40f9-8c64-d5b05e4846db","html_url":"https://github.com/omaraflak/Annotation-Processor-Sample","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/omaraflak%2FAnnotation-Processor-Sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaraflak%2FAnnotation-Processor-Sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaraflak%2FAnnotation-Processor-Sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaraflak%2FAnnotation-Processor-Sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omaraflak","download_url":"https://codeload.github.com/omaraflak/Annotation-Processor-Sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248579039,"owners_count":21127749,"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":["android","annotation","annotation-processor","annotationprocessor","generated-code","processor","tutorial"],"created_at":"2024-10-31T13:09:35.900Z","updated_at":"2025-04-12T14:24:14.086Z","avatar_url":"https://github.com/omaraflak.png","language":"Java","readme":"# Annotation Processor Example\n\nSimple example to illustrate the use of android annotation processor.\n\nThis code will create an annotation named `@Activity` which is meant to target activities. The processor will generate a `Navigator` class with `static` methods to start the annotated activities.\n\n# Creation Steps (Android Studio)\n\n#### 1) File \u003e New \u003e New Module... \u003e Java Library  -\u003e Name it \"annotation\"\n#### 2) File \u003e New \u003e New Module... \u003e Java Library  -\u003e Name it \"processor\"\n#### 3) In processor build.gradle :\n\n```\ndependencies {\n    /*...*/\n\n    implementation project(':annotation')\n    implementation 'com.squareup:javapoet:1.9.0'\n    implementation 'com.google.auto.service:auto-service:1.0-rc3'\n}\n```\n    \n#### 4) In app build.gradle :\n\n```\ndependencies {\n    /*...*/\n\n    implementation project(':annotation')\n    annotationProcessor project(':processor')\n}\n```\n    \n#### 5) Create new file called `Activity.java` in annotation module :\n\n```java\n@Target(ElementType.TYPE) // To target classes\n@Retention(RetentionPolicy.SOURCE)\npublic @interface Activity {\n}\n```\n    \n#### 6) Create new file called `ActivityProcessor.java` in processor module :\n\n```java\n@AutoService(Processor.class) // DON'T FORGET THIS\npublic class ActivityProcessor extends AbstractProcessor{\n    @Override\n    public synchronized void init(ProcessingEnvironment processingEnvironment) {\n        /* initialize variables */\n    }\n\n    @Override\n    public boolean process(Set\u003c? extends TypeElement\u003e set, RoundEnvironment roundEnvironment) {\n        /* code generation happens here (using JavaPoet) */\n        return false;\n    }\n\n    @Override\n    public Set\u003cString\u003e getSupportedAnnotationTypes() {\n        return Collections.singleton(Activity.class.getCanonicalName());\n    }\n\n    @Override\n    public SourceVersion getSupportedSourceVersion() {\n        return SourceVersion.latestSupported();\n    }\n}\n```\n\n#### 7) Annotate any class and Rebuild your project to generate the code\n\n# Sample\n\n* [Annotation](https://github.com/OmarAflak/Annotation-Processor-Sample/blob/master/annotation/src/main/java/me/aflak/annotation/Activity.java)\n* [Processor](https://github.com/OmarAflak/Annotation-Processor-Sample/blob/master/processor/src/main/java/me/aflak/processor/ActivityProcessor.java)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomaraflak%2Fannotation-processor-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomaraflak%2Fannotation-processor-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomaraflak%2Fannotation-processor-sample/lists"}