Coca
Coca is a toolbox which is design for legacy system refactoring and analysis, includes call graph, concept analysis, api tree, design patterns suggest. Coca 是一个用于系统重构、系统迁移和系统分析的工具箱。它可以分析代码中的测试坏味道、模块化分析、行数统计、分析调用与依赖、Git 分析以及自动化重构等。
Install / Use
/learn @phodal/CocaREADME
Coca - toolbox for system refactoring and analysis
Coca is a toolbox which is design for legacy system refactoring and analysis, includes call graph, concept analysis, api tree, design patterns suggest. Coca 是一个用于系统重构、系统迁移和系统分析的工具箱。它可以分析代码中的测试坏味道、模块化分析、行数统计、分析调用与依赖、Git 分析以及自动化重构等。
Related Tools: Coco is an effective DevOps analysis and auto-suggest tool.
Kotlin version: Chapi
Migration Guide (Chinese Version): 《系统重构与迁移指南》
Refactoring Modeling:
- Languages Support: Java (full features)
Features List:
Available Commands:
analysis analysis code
api scan HTTP api from annotation
arch project package visualization
bs generate bad smell list and suggestions
call show call graph with specific method
cloc count lines of code with complexity estimation
concept build domain concept from source code
count count most refs function
evaluate evaluate code situation and refactor effort
git analysis git commit history for revs count, summary and suggest
help Help about any command
rcall reverse call graph visualization
refactor auto refactor code
suggest find usable Design Patterns from code
tbs generate tests bad smell
todo scan all todo, and list with time
version version
Getting started
Requirements: graphviz for dot file to image (such as svg, png)
The easiest way to get coca is to use one of the pre-built release binaries which are available for OSX, Linux, Windows on the release page.
You can also install yourself :
go install github.com/modernizing/coca@latest
Usage
Analysis
coca analysis
Arch
coca arch
Android Studio Gradle DSL Module (merge header)
command: coca arch -x "com.android.tools.idea.gradle.dsl" -H true
Android Studio Gradle DSL Module Elements Part:
command: coca arch -x "com.android.tools.idea.gradle.dsl.parser.elements"
Find Bad Smells
coca bs -s type
Examples Result:
{
"dataClass": [
{
"File": "examples/api/BookController.java",
"BS": "dataClass"
}
],
"lazyElement": [
{
"File": "examples/api/model/BookRepresentaion.java",
"BS": "lazyElement"
}
]
}
Code Line Count
coca cloc
Results:
───────────────────────────────────────────────────────────────────────────────
Language Files Lines Blanks Comments Code Complexity
───────────────────────────────────────────────────────────────────────────────
Go 58 31763 7132 890 23741 2847
Java 44 971 208 21 742 62
Markdown 8 238 75 0 163 0
Gherkin Specificati… 2 32 2 16 14 0
Document Type Defin… 1 293 36 0 257 0
License 1 201 32 0 169 0
SQL 1 2 0 0 2 0
SVG 1 199 0 34 165 0
Shell 1 3 1 1 1 0
XML 1 13 0 0 13 0
gitignore 1 61 8 4 49 0
───────────────────────────────────────────────────────────────────────────────
Total 119 33776 7494 966 25316 2909
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop $803,822
Estimated Schedule Effort 14.120551 months
Estimated People Required 6.743156
───────────────────────────────────────────────────────────────────────────────
Results to json
coca cloc --by-file --format json
Cloc by directory
coca cloc ~/intellij-community/android/ --by-directory --include-ext=java,kt --not-match=".*(Test|Tests)\.(kt|java)"
results csv:
module,summary
adt-branding,169
adt-testutils,257
adt-ui,21987
adt-ui-model,3450
android,361270
android-adb,497
android-common,3280
android-debuggers,3030
android-kotlin,8816
android-lang,24796
android-lang-databinding,6392
android-layout-inspector,2533
...
Cloc Top File
coca cloc ~/intellij-community/android/designer/src/com/android/tools/idea --top-file --top-size 10
output to: coca_reporter/sort_cloc.json and also:
| LENGTH | COMPLEXITY | LOCATION |
|--------|------------|-----------------------------------|
| 1642 | 236 | ConstraintLayoutHandler.java |
| 1492 | 375 | ConstraintComponentUtilities.java |
| 1189 | 166 | CommonActions.java |
| 1184 | 325 | ConstraintWidget.java |
| 1169 | 129 | SingleWidgetView.java |
| 1115 | 213 | ScoutArrange.java |
| 1097 | 281 | ScoutWidget.java |
| 1081 | 224 | 3d/Rasterize.java |
| 1016 | 159 | LayoutlibSceneManager.java |
| 1014 | 220 | TimeLinePanel.java |
Build Deps Tree
coca call -c com.phodal.pholedge.book.BookController.createBook -r com.phodal.pholedge.
Examples Results:
Identify Spring API
coca api -f
With Count
coca api -r com.phodal.pholedge. -c
or multi package:
coca api -r com.macro.mall.demo.controller.,com.zheng.cms.admin.,com.phodal.pholedge -c
+------+--------+------------------------------------------------+------------------------------------------------------------------------+
| SIZE | METHOD | URI | CALLER |
+------+--------+------------------------------------------------+------------------------------------------------------------------------+
| 36 | GET | /aliyun/oss/policy | controller.OssController.policy |
| 21 | POST | /aliyun/osscallback | controller.OssController.callback |
| 17 | GET | /subject/list | controller.CmsSubjectController.getList |
| 17 | GET | /esProduct/search | search.controller.EsProductController.search |
| 17 | GET | /order/list | controller.OmsOrderController.list |
| 17 | GET | /productAttribute/list/{cid} | controller.PmsProductAttributeController.getList |
| 17 | GET | /productCategory/list/{parentId} | controller.PmsProductCategoryController.getList |
| 17 | GET | /brand/list | controller.PmsBrandController.getList |
| 17 | GET | /esProduct/search/simple | search.controller.EsProductController.search |
+------+--------+------------------------------------------------+------------------------------------------------------------------------+
Git Analysis
coca git -t
Results:
+---------------------------------------------------------------------------------------------------------------------+-----------+-------------+
| ENTITYNAME | REVSCOUNT | AUTHORCOUNT |
+---------------------------------------------------------------------------------------------------------------------+-----------+-------------+
| build.gradle | 1326 | 36 |
| src/asciidoc/index.adoc | 239 | 20 |
| build-spring-framework/resources/changelog.txt | 187 | 10 |
| spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java | 170 | 10 |
| spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java | 159 | 15 |
| src/docs/asciidoc/web/webmvc.adoc | 121 | 24 |
| spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParse
Related Skills
apple-reminders
337.4kManage Apple Reminders via remindctl CLI (list, add, edit, complete, delete). Supports lists, date filters, and JSON/plain output.
gh-issues
337.4kFetch GitHub issues, spawn sub-agents to implement fixes and open PRs, then monitor and address PR review comments. Usage: /gh-issues [owner/repo] [--label bug] [--limit 5] [--milestone v1.0] [--assignee @me] [--fork user/repo] [--watch] [--interval 5] [--reviews-only] [--cron] [--dry-run] [--model glm-5] [--notify-channel -1002381931352]
healthcheck
337.4kHost security hardening and risk-tolerance configuration for OpenClaw deployments
imsg
337.4kiMessage/SMS CLI for listing chats, history, and sending messages via Messages.app.
