private static Set<Class> findFunctionCollections(String packageName) { return ClassUtil.findClasses(null, packageName, new Predicate() { @Override public boolean evaluate(Object object) { return ((Class)object).getAnnotation(FunctionCollection.class) != null; } }); }
@Override public Class deserialize(JsonElement json, Type type, JsonDeserializationContext ctx) throws JsonParseException { try { return ClassUtil.forName(json.getAsString()); } catch (ClassNotFoundException e) { e.printStackTrace(); } return null; } }
private static boolean isTestClass(String qualifiedClassName) { String className = getSimpleClassName(qualifiedClassName); if(className == null) { return false; } return className.startsWith("Test"); }
if (file.isDirectory()) { for (File child : file.listFiles()) { findClasses(matchedClassSet, root, child, includeJars, type, packageFilter, predicate); if (extIndex > 0) { String qualifiedClassName = name.substring(0, extIndex).replace("/", "."); if (qualifiedClassName.indexOf(packageFilter) >= 0 && !isTestClass(qualifiedClassName)) { try { Class clazz = Class.forName(qualifiedClassName); if (isMatched(clazz, type, predicate)) { matchedClassSet.add(clazz); String qualifiedClassName = createClassName(root, file); if (qualifiedClassName.indexOf(packageFilter) >= 0 && !isTestClass(qualifiedClassName)) { try { Class clazz = Class.forName(qualifiedClassName); if (isMatched(clazz, type, predicate)) { matchedClassSet.add(clazz);
private static boolean isClassMatched(Class targetClass, Class loadedClass) { if (targetClass.equals(loadedClass)) { return true; } Class[] classInterfaces = loadedClass.getInterfaces(); if (classInterfaces != null) { for (Class eachInterfaceClass : classInterfaces) { if (eachInterfaceClass.equals(targetClass)) { return true; } if (isClassMatched(targetClass, eachInterfaceClass)) { return true; } } } Class superClass = loadedClass.getSuperclass(); if (superClass != null) { if (isClassMatched(targetClass, superClass)) { return true; } } return false; }
if (children != null) { for (File child : children) { findClasses(matchedClassSet, root, child, includeJars, type, packageFilter, predicate); if (extIndex > 0) { String qualifiedClassName = name.substring(0, extIndex).replace("/", "."); if (qualifiedClassName.indexOf(packageFilter) >= 0 && !isTestClass(qualifiedClassName)) { try { Class clazz = Class.forName(qualifiedClassName); if (isMatched(clazz, type, predicate)) { matchedClassSet.add(clazz); String qualifiedClassName = createClassName(root, file); if (qualifiedClassName.indexOf(packageFilter) >= 0 && !isTestClass(qualifiedClassName)) { try { Class clazz = Class.forName(qualifiedClassName); if (isMatched(clazz, type, predicate)) { matchedClassSet.add(clazz);
private static boolean isMatched(Class clazz, Class targetClass, Predicate predicate) { return !clazz.isInterface() && (targetClass == null || isClassMatched(targetClass, clazz)) && (predicate == null || predicate.evaluate(clazz)); }
private static Set<Class> findFunctionCollections(String packageName) { return ClassUtil.findClasses(null, packageName, (Object object) -> ((Class)object).getAnnotation(FunctionCollection.class) != null); }
@Override public Class deserialize(JsonElement json, Type type, JsonDeserializationContext ctx) throws JsonParseException { try { return ClassUtil.forName(json.getAsString()); } catch (ClassNotFoundException e) { e.printStackTrace(); } return null; } }
private static boolean isClassMatched(Class targetClass, Class loadedClass) { if (targetClass.equals(loadedClass)) { return true; } Class[] classInterfaces = loadedClass.getInterfaces(); if (classInterfaces != null) { for (Class eachInterfaceClass : classInterfaces) { if (eachInterfaceClass.equals(targetClass)) { return true; } if (isClassMatched(targetClass, eachInterfaceClass)) { return true; } } } Class superClass = loadedClass.getSuperclass(); if (superClass != null) { if (isClassMatched(targetClass, superClass)) { return true; } } return false; }
private static boolean isTestClass(String qualifiedClassName) { String className = getSimpleClassName(qualifiedClassName); if(className == null) { return false; } return className.startsWith("Test"); }
public static Set<Class> findClasses(@Nullable Class targetClass, String packageFilter, Predicate predicate) { Set<Class> classSet = new HashSet<Class>(); String classpath = System.getProperty("java.class.path"); String[] paths = classpath.split(System.getProperty("path.separator")); for (String path : paths) { File file = new File(path); if (file.exists()) { findClasses(classSet, file, file, true, targetClass, packageFilter, predicate); } } return classSet; }
public StaticMethodInvocationDesc(StaticMethodInvocationDescProto proto) { try { baseClassName = Class.forName(proto.getClassName()); methodName = proto.getMethodName(); returnClass = ClassUtil.forName(proto.getReturnClass()); paramClasses = new Class[proto.getParamClassesCount()]; for (int i = 0; i < proto.getParamClassesCount(); i++) { paramClasses[i] = ClassUtil.forName(proto.getParamClasses(i)); } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
private static boolean isMatched(Class clazz, Class targetClass, Predicate predicate) { return !clazz.isInterface() && (targetClass == null || isClassMatched(targetClass, clazz)) && (predicate == null || predicate.evaluate(clazz)); }
public static Set<Class> findClasses(@Nullable Class targetClass, String packageFilter, Predicate predicate) { Set<Class> classSet = new HashSet<>(); String classpath = System.getProperty("java.class.path"); String[] paths = classpath.split(System.getProperty("path.separator")); for (String path : paths) { File file = new File(path); if (file.exists()) { findClasses(classSet, file, file, true, targetClass, packageFilter, predicate); } } return classSet; }
public StaticMethodInvocationDesc(StaticMethodInvocationDescProto proto) { try { baseClassName = Class.forName(proto.getClassName()); methodName = proto.getMethodName(); returnClass = ClassUtil.forName(proto.getReturnClass()); paramClasses = new Class[proto.getParamClassesCount()]; for (int i = 0; i < proto.getParamClassesCount(); i++) { paramClasses[i] = ClassUtil.forName(proto.getParamClasses(i)); } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public List<SelfDiagnosisRule> getDefinedRules() { Set<Class> classSet = ClassUtil.findClasses(SelfDiagnosisRule.class, getClass().getPackage().getName()); List<SelfDiagnosisRule> ruleList = new ArrayList<SelfDiagnosisRule>(classSet.size()); for (Class<SelfDiagnosisRule> ruleClazz: classSet) { try { ruleList.add(ruleClazz.newInstance()); } catch (Exception e) { LOG.warn("Cannot instantiate " + ruleClazz.getName() + " class."); continue; } } return ruleList; }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public List<SelfDiagnosisRule> getDefinedRules() { Set<Class> classSet = ClassUtil.findClasses(SelfDiagnosisRule.class, getClass().getPackage().getName()); List<SelfDiagnosisRule> ruleList = new ArrayList<SelfDiagnosisRule>(classSet.size()); for (Class<SelfDiagnosisRule> ruleClazz: classSet) { try { ruleList.add(ruleClazz.newInstance()); } catch (Exception e) { LOG.warn("Cannot instantiate " + ruleClazz.getName() + " class.", e); continue; } } return ruleList; }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public List<SelfDiagnosisRule> getDefinedRules() { Set<Class> classSet = ClassUtil.findClasses(SelfDiagnosisRule.class, getClass().getPackage().getName()); List<SelfDiagnosisRule> ruleList = new ArrayList<>(classSet.size()); for (Class<SelfDiagnosisRule> ruleClazz: classSet) { try { ruleList.add(ruleClazz.newInstance()); } catch (Exception e) { LOG.warn("Cannot instantiate " + ruleClazz.getName() + " class."); continue; } } return ruleList; }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public List<SelfDiagnosisRule> getDefinedRules() { Set<Class> classSet = ClassUtil.findClasses(SelfDiagnosisRule.class, getClass().getPackage().getName()); List<SelfDiagnosisRule> ruleList = new ArrayList<>(classSet.size()); for (Class<SelfDiagnosisRule> ruleClazz: classSet) { try { ruleList.add(ruleClazz.newInstance()); } catch (Exception e) { LOG.warn("Cannot instantiate " + ruleClazz.getName() + " class."); continue; } } return ruleList; }