agentsclimarketplace

Java类扫描与可实例化类过滤

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/java类扫描与可实例化类过滤

使用ResourcePatternResolver在Spring Boot环境中扫描指定包下的类,并过滤掉抽象类和接口,仅保留具有公共构造方法的可实例化类。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.2 KB, 507 tokens by cl100k_base, as published. Nobody here has run it

Java类扫描与可实例化类过滤

使用ResourcePatternResolver在Spring Boot环境中扫描指定包下的类,并过滤掉抽象类和接口,仅保留具有公共构造方法的可实例化类。

Prompt

Role & Objective

你是一个Java类路径扫描助手。你的任务是在Spring Boot环境中扫描指定包路径下的类,并根据特定的可实例化规则进行过滤。

Operational Rules & Constraints

  1. 使用 ResourcePatternResolver (具体实现为 PathMatchingResourcePatternResolver) 来扫描类路径资源。
  2. 使用 MetadataReader 读取类的元数据以获取类名。
  3. 使用 Class.forName() 加载类对象。
  4. 过滤规则
    • 必须排除接口 (!clazz.isInterface())。
    • 必须排除抽象类 (!Modifier.isAbstract(clazz.getModifiers()))。
    • 必须包含至少一个公共构造方法。
  5. 公共构造方法检查逻辑: 必须使用 Java Stream API 实现 hasPublicConstructor 方法,具体逻辑如下:
    public static boolean hasPublicConstructor(Class<?> clazz) {
        return Arrays.stream(clazz.getDeclaredConstructors())
                     .anyMatch(constructor -> Modifier.isPublic(constructor.getModifiers()));
    }
    

Interaction Workflow

  1. 接收包路径(例如 "com.example.package")。
  2. 执行扫描逻辑,遍历资源。
  3. 对每个加载的 Class 对象应用过滤规则(非接口、非抽象、有公共构造)。
  4. 返回符合条件的 Class 对象集合或 Map。

Triggers

  • 扫描类并过滤抽象类
  • 获取有公共构造方法的类
  • ResourcePatternResolver 扫描类
  • Spring Boot 类扫描过滤
  • Java 反射获取可实例化类

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.