openrewrite
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "openrewrite":https://skillpi.com/zh/skills/deepskill-3a1040373f52139295402e7b13d20d70ca023761f91caafea8a8d508ee7a889b。安装前核对上游来源和版本:https://skillhub.cn/skills/user_3c6cb52e/run-recipe-driven-codebase-migrations-and-framework-upgrades-with-reviewable-diffs-through-openrewrite。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
skillhub.cn
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
将可重用的重构配方应用于大型代码库以执行框架升级和代码转换,确保变更过程可审计、可审查。
介绍来源: third_party · user_3c6cb52e · 1.0.0 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 适合谁
- 来源文档未说明。
- 输入和输出
- 来源文档未说明。
- 软件、账号及付费要求
- 来源文档未说明。
- 限制与区别
- 来源文档未说明。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: openrewrite
description: OpenRewrite recipe test maintenance. Use when fixing test failures, import ordering issues, type validation problems, IDE warnings, or writing comprehensive recipe tests.OpenRewrite Recipe Development
This skill provides guidelines for developing OpenRewrite recipes and maintaining their tests, with a focus on import ordering issues.
Fixing Import Ordering Test Failures
🔧 OpenRewrite recipe tests often fail due to import order differences, not actual transformation issues.
Problem
OpenRewrite recipe tests fail with diffs showing only import order differences:
-import java.util.List;
-import org.assertj.core.api.Assertions;
+import org.assertj.core.api.Assertions;
+import java.util.List;
Root Cause
OpenRewrite manages imports automatically based on:
- Existing imports in the file
- JavaTemplate configuration
- Import optimization rules
- The order may differ from test expectations
Solution Approach
1. Fix the Recipe (if imports are missing)
Ensure your JavaTemplate is properly configured:
JavaTemplate template = JavaTemplate
.builder("Your.template.code()")
.imports(
"org.assertj.core.api.Assertions",
"org.eclipse.collections.impl.utility.Iterate"
)
.contextSensitive() // Important for proper context handling
.javaParser(JavaParser.fromJavaVersion()
.classpath("assertj-core", "eclipse-collections", "eclipse-collections-api")
)
.build();
Don't forget to call:
maybeAddImport("org.assertj.core.api.Assertions");
maybeAddImport("org.eclipse.collections.impl.utility.Iterate");
maybeRemoveImport("old.package.OldClass");
2. Fix the Test Expectations
Accept the actual import order that OpenRewrite produces:
❌ Instead of forcing a specific order:
// DON'T expect a specific order you want
"import java.util.List;\n" +
"import org.assertj.core.api.Assertions;\n"
✅ Use the actual order OpenRewrite produces:
// DO accept the order OpenRewrite generates
"import org.assertj.core.api.Assertions;\n" +
"import org.eclipse.collections.impl.utility.Iterate;\n" +
"\n" +
"import java.util.List;\n"
3. Common Import Ordering Patterns
OpenRewrite typically orders imports as:
- Third-party packages (org.assertj, org.eclipse.collections, etc.)
- Blank line
- Java standard library (
java.*,javax.*) - Blank line (if static imports exist)
- Static imports
Quick Fix Steps
- Run the failing test and copy the actual output from the error message
- Replace the expected output in your test with the actual output
- Verify the transformation logic is correct (ignore import order)
- Re-run the test to confirm it passes
Note on ~~> Syntax
The ~~> prefix in test expectations is not standard in all codebases. It's used in some OpenRewrite projects to indicate "ignore everything before this line" but isn't recognized in all contexts. If you see it failing, remove it and use exact matching instead.
Example Fix
@Test
void replacesVerifyWithAssertJ() {
rewriteRun(
java(
// Input
"""
import org.eclipse.collections.impl.test.Verify;
import java.util.List;
class Test {
void test() {
List<String> list = List.of("a", "b", "c");
Verify.assertCount(2, list, each -> each.length() > 0);
}
}
""",
// Expected output - use actual order from test failure
"""
import org.assertj.core.api.Assertions;
import org.eclipse.collections.impl.utility.Iterate;
import java.util.List;
class Test {
void test() {
List<String> list = List.of("a", "b", "c");
Assertions.assertThat(Iterate.count(list, each -> each.length() > 0)).isEqualTo(2);
}
}
"""
)
);
}
Testing Best Practices
Type Validation in Tests
For tests involving custom types with incomplete type information, disable type validation as a last resort. Prefer specifying types that exist:
@Test
void withCustomType() {
rewriteRun(
spec -> spec.typeValidationOptions(TypeValidation.none()),
java(
// test code
)
);
}
Suppressing IDE Warnings in Tests
When testing code with intentional issues (that the recipe will fix), suppress IDE warnings:
// Single test method
@SuppressWarnings("RedundantCast")
@Test
void testRedundantCast() { ... }
// Multiple tests with same warning - move to class level
@SuppressWarnings({"ConstantConditions", "RedundantCast"})
class MyRecipeTest implements RewriteTest { ... }
Common suppressions: "RedundantCast", "ConstantConditions", "unused", "unchecked"
IDE Support with Language Comments
Add //language=java before string templates to enable IDE syntax highlighting.
When using java("before", "after") with no customization, place the comment before java:
//language=java
java(
"""
public class Before { }
""",
"""
public class After { }
"""
)
When there's customization or multiple java() calls, place comments on individual strings:
spec -> spec.typeValidationOptions(TypeValidation.none()),
//language=java
java(
"""
public class Test { }
"""
)
Do NOT add //language=java to JavaTemplate strings containing parameters like #{any()} or #{} — these aren't valid Java and will cause IDE errors.
Test Coverage
Ensure comprehensive coverage including:
- Basic cases
- Edge cases (custom types, fully qualified types)
- Cases where the recipe should NOT make changes
- Import handling scenarios
- Formatting preservation
Maven POM Dependency Ordering
Maven POM files should follow a consistent dependency ordering structure. See the java:pom-ordering skill for detailed guidelines.
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 针对 OpenRewrite recipe 开发中的典型痛点(如 import ordering test failures)提供详细解决方案
- 涵盖多种实际场景(type validation、IDE warnings、test coverage)的最佳实践
亮点
- description 清晰列出适用场景(test failures, import ordering, type validation, IDE warnings, recipe tests)
- 触发词精准,边界明确,不易与其他 Skill 混淆
亮点
- Phase/步骤划分清晰(Problem -> Root Cause -> Solution -> Quick Fix Steps)
- 包含多个端到端代码示例,便于理解与实施
- frontmatter 完整,文档结构规范
亮点
- 工具来源(OpenRewrite)及 API 使用方式明确
- 覆盖主要异常处理(type validation, IDE warnings suppression)
- 对不可逆操作(修改测试期望)有确认与验证建议
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
来源文档未说明。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。