Search in sources :

Example 1 with InterfaceNameRegexFilter

use of com.shulie.instrument.simulator.module.util.InterfaceNameRegexFilter in project LinkAgent by shulieTech.

the class ScModule method sc.

@Command(value = "sc", description = "查找类")
public CommandResponse sc(final Map<String, String> param) {
    try {
        final String cnPattern = getParameter(param, "class");
        final String type = getParameter(param, "type");
        if (StringUtils.isBlank(type)) {
            Set<Class<?>> classes = loadedClassDataSource.find(new NameRegexFilter(cnPattern, ".*", true, true));
            List<String> classNames = new ArrayList<String>();
            for (Class<?> clazz : classes) {
                String name = clazz.getCanonicalName() + " " + clazz.getClassLoader().toString();
                classNames.add(name);
            }
            return CommandResponse.success(classNames);
        } else if (StringUtils.equals("s", type)) {
            Set<Class<?>> classes = loadedClassDataSource.find(new SuperNameRegexFilter(cnPattern, ".*", true, true));
            List<String> classNames = new ArrayList<String>();
            for (Class<?> clazz : classes) {
                String name = clazz.getCanonicalName() + " " + clazz.getClassLoader().toString();
                classNames.add(name);
            }
            return CommandResponse.success(classNames);
        } else if (StringUtils.equals("i", type)) {
            Set<Class<?>> classes = loadedClassDataSource.find(new InterfaceNameRegexFilter(cnPattern, ".*", true, true));
            List<String> classNames = new ArrayList<String>();
            for (Class<?> clazz : classes) {
                String name = clazz.getCanonicalName() + " " + clazz.getClassLoader().toString();
                classNames.add(name);
            }
            return CommandResponse.success(classNames);
        }
        return CommandResponse.failure("Unsupported type value:" + type);
    } catch (Throwable e) {
        return CommandResponse.failure(e);
    }
}
Also used : SuperNameRegexFilter(com.shulie.instrument.simulator.module.util.SuperNameRegexFilter) SuperNameRegexFilter(com.shulie.instrument.simulator.module.util.SuperNameRegexFilter) InterfaceNameRegexFilter(com.shulie.instrument.simulator.module.util.InterfaceNameRegexFilter) NameRegexFilter(com.shulie.instrument.simulator.api.filter.NameRegexFilter) Set(java.util.Set) ArrayList(java.util.ArrayList) InterfaceNameRegexFilter(com.shulie.instrument.simulator.module.util.InterfaceNameRegexFilter) ArrayList(java.util.ArrayList) List(java.util.List) Command(com.shulie.instrument.simulator.api.annotation.Command)

Aggregations

Command (com.shulie.instrument.simulator.api.annotation.Command)1 NameRegexFilter (com.shulie.instrument.simulator.api.filter.NameRegexFilter)1 InterfaceNameRegexFilter (com.shulie.instrument.simulator.module.util.InterfaceNameRegexFilter)1 SuperNameRegexFilter (com.shulie.instrument.simulator.module.util.SuperNameRegexFilter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1