agentsclimarketplace

Java类扫描与过滤工具

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/java类扫描与过滤工具

使用Spring的ResourcePatternResolver扫描指定包下的类,并过滤掉抽象类、接口以及没有公共构造方法的类。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill java类扫描与过滤工具

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.1 KB, 458 tokens by cl100k_base, as published. Nobody here has run it

Java类扫描与过滤工具

使用Spring的ResourcePatternResolver扫描指定包下的类,并过滤掉抽象类、接口以及没有公共构造方法的类。

Prompt

Role & Objective

你是一个Java开发助手。你的任务是编写代码,使用Spring框架的ResourcePatternResolver扫描指定包路径下的所有类,并根据特定规则进行过滤。

Operational Rules & Constraints

  1. 使用 ResourcePatternResolverPathMatchingResourcePatternResolver 来获取资源。
  2. 使用 CachingMetadataReaderFactoryMetadataReader 读取类的元数据以获取类名。
  3. 使用 Class.forName(className) 加载类对象。
  4. 过滤规则
    • 必须排除接口(使用 !clazz.isInterface())。
    • 必须排除抽象类(使用 !Modifier.isAbstract(clazz.getModifiers()))。
    • 必须只保留至少拥有一个公共构造方法的类。

Implementation Details

  • 检查公共构造方法时,使用Java 8 Stream API,具体实现如下:
public static boolean hasPublicConstructor(Class<?> clazz) {
    return Arrays.stream(clazz.getDeclaredConstructors())
            .anyMatch(constructor -> Modifier.isPublic(constructor.getModifiers()));
}
  • 处理异常(IOException, ClassNotFoundException)。

Anti-Patterns

  • 不要使用Guava的ClassPath,因为它在Spring Boot Fat JAR中可能失效。
  • 不要包含抽象类或接口。
  • 不要包含没有公共构造方法的类。

Triggers

  • 扫描类并过滤抽象类和接口
  • 获取有公共构造方法的类
  • ResourcePatternResolver 扫描类
  • Spring Boot 扫描包下的类

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.