{"id":28629847,"url":"https://github.com/codebox/checkstyle-import-checker","last_synced_at":"2025-06-12T12:13:45.469Z","repository":{"id":21743693,"uuid":"25065532","full_name":"codebox/checkstyle-import-checker","owner":"codebox","description":"A Java class to simplify writing custom Checkstyle rules that examine class imports","archived":false,"fork":false,"pushed_at":"2015-11-14T09:29:47.000Z","size":132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-11T21:48:07.895Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://codebox.org.uk/pages/writing-checkstyle-rules-for-imports","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/codebox.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-10-11T06:07:53.000Z","updated_at":"2014-10-11T16:39:32.000Z","dependencies_parsed_at":"2022-08-17T18:15:25.765Z","dependency_job_id":null,"html_url":"https://github.com/codebox/checkstyle-import-checker","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/codebox/checkstyle-import-checker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebox%2Fcheckstyle-import-checker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebox%2Fcheckstyle-import-checker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebox%2Fcheckstyle-import-checker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebox%2Fcheckstyle-import-checker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codebox","download_url":"https://codeload.github.com/codebox/checkstyle-import-checker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebox%2Fcheckstyle-import-checker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259462574,"owners_count":22861514,"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":"2025-06-12T12:13:43.628Z","updated_at":"2025-06-12T12:13:45.461Z","avatar_url":"https://github.com/codebox.png","language":"Java","readme":"# checkstyle-import-checker\n\n[AbstractImportChecker.java](https://github.com/codebox/checkstyle-import-checker) simplifies the process of writing [custom CheckStyle rules](http://checkstyle.sourceforge.net/writingchecks.html) that examine class imports.\n\nNote that Checkstyle contains a number of quite flexible [built-in rules for managing imports](http://checkstyle.sourceforge.net/config_imports.html), you should obviously use these if they meet your needs.\n\nTo implement your own custom import checker just sub-class `AbstractImportChecker` and provide an implementation for `onImport()`:\n\n\u003cpre\u003epublic class ImportChecker extends AbstractImportChecker {\n    @Override\n    public void onImport(String packageName, String importName) {\n        if (! isImportAllowedInPackage(packageName, importName)) {\n            logError(String.format(\"Import %s not allowed in package %s\", importName, packageName));\n        }\n    }\n\n    private boolean isImportAllowedInPackage(String packageName, String importName) {\n        return true; // custom logic here\n    }\n}\u003c/pre\u003e\n\nThe `DottedPath` helper class can be used to check for sub-packages and package membership:\n\n\u003cpre\u003eprivate boolean isImportAllowedInPackage(String packageName, String importName){\n    DottedPath packagePath = new DottedPath(packageName);\n    DottedPath importPath = new DottedPath(importName);\n\n    return importPath.isChildOf(packagePath);\n}\u003c/pre\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodebox%2Fcheckstyle-import-checker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodebox%2Fcheckstyle-import-checker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodebox%2Fcheckstyle-import-checker/lists"}