public Set<Class<?>> getAnnotatedClasses() { return reflections.getTypesAnnotatedWith(Api.class); }
/** * get types annotated with a given annotation, both classes and annotations * <p>{@link java.lang.annotation.Inherited} is not honored by default. * <p>when honoring @Inherited, meta-annotation should only effect annotated super classes and its sub types * <p><i>Note that this (@Inherited) meta-annotation type has no effect if the annotated type is used for anything other then a class. * Also, this meta-annotation causes annotations to be inherited only from superclasses; annotations on implemented interfaces have no effect.</i> * <p/>depends on TypeAnnotationsScanner and SubTypesScanner configured */ public Set<Class<?>> getTypesAnnotatedWith(final Class<? extends Annotation> annotation) { return getTypesAnnotatedWith(annotation, false); }
/** * get types annotated with a given annotation, both classes and annotations, including annotation member values matching * <p>{@link java.lang.annotation.Inherited} is not honored by default * <p/>depends on TypeAnnotationsScanner configured */ public Set<Class<?>> getTypesAnnotatedWith(final Annotation annotation) { return getTypesAnnotatedWith(annotation, false); }
/** * get types annotated with a given annotation, both classes and annotations, including annotation member values matching * <p>{@link java.lang.annotation.Inherited} is not honored by default * <p/>depends on TypeAnnotationsScanner configured */ public Set<Class<?>> getTypesAnnotatedWith(final Annotation annotation) { return getTypesAnnotatedWith(annotation, false); }
/** * get types annotated with a given annotation, both classes and annotations * <p>{@link java.lang.annotation.Inherited} is not honored by default. * <p>when honoring @Inherited, meta-annotation should only effect annotated super classes and its sub types * <p><i>Note that this (@Inherited) meta-annotation type has no effect if the annotated type is used for anything other then a class. * Also, this meta-annotation causes annotations to be inherited only from superclasses; annotations on implemented interfaces have no effect.</i> * <p/>depends on TypeAnnotationsScanner and SubTypesScanner configured */ public Set<Class<?>> getTypesAnnotatedWith(final Class<? extends Annotation> annotation) { return getTypesAnnotatedWith(annotation, false); }
Reflections reflections = new Reflections("my.project.prefix"); Set<Class<? extends SomeType>> subTypes = reflections.getSubTypesOf(SomeType.class); Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(SomeAnnotation.class);
private static Collection<Class<?>> getClassesInPackageAnnotatedBy( String thePackage, Reflections reflections, Class<? extends Annotation> annotation) { // Filter classes actually in subpackages return reflections.getTypesAnnotatedWith(annotation).stream(). filter(c -> c.getPackage().getName().equals(thePackage)). collect(Collectors.toList()); }
private void loadSpiderBean(Reflections reflections) { Set<Class<?>> spiderBeanClasses = reflections.getTypesAnnotatedWith(Gecco.class); for (Class<?> spiderBeanClass : spiderBeanClasses) { addSpiderBean(spiderBeanClass); } }
Reflections reflections = new Reflections("my.project.prefix"); Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Controller.class); for (Class<?> controller : annotated) { RequestMapping request = controller.getAnnotation(RequestMapping.class); String mapping = request.name(); }
public CustomFieldRenderFactory(Reflections reflections) { this.map = new HashMap<String, CustomFieldRender>(); Set<Class<?>> classes = reflections.getTypesAnnotatedWith(FieldRenderName.class); for(Class<?> clazz : classes) { FieldRenderName fieldRenderName = (FieldRenderName)clazz.getAnnotation(FieldRenderName.class); try { map.put(fieldRenderName.value(), (CustomFieldRender)clazz.newInstance()); } catch(Exception ex) { ex.printStackTrace(); } } }
Reflections reflections = new Reflections( new ConfigurationBuilder() .setUrls(ClasspathHelper.forJavaClassPath()) ); Set<Class<?>> types = reflections.getTypesAnnotatedWith(Scannable.class);
@SuppressWarnings({ "unchecked" }) public DefaultPipelineFactory(Reflections reflections) { this.pipelines = new HashMap<String, Pipeline<? extends SpiderBean>>(); Set<Class<?>> pipelineClasses = reflections.getTypesAnnotatedWith(PipelineName.class); for (Class<?> pipelineClass : pipelineClasses) { PipelineName spiderFilter = pipelineClass.getAnnotation(PipelineName.class); try { pipelines.put(spiderFilter.value(), (Pipeline<? extends SpiderBean>) pipelineClass.newInstance()); } catch (Exception ex) { ex.printStackTrace(); } } }
public static void export(String classpath) { Reflections reflections = new Reflections("com.geccocrawler.gecco.monitor"); Set<Class<?>> mbeanClasses = reflections.getTypesAnnotatedWith(MBean.class); for(Class<?> mbeanClass : mbeanClasses) { MBean mbean = (MBean)mbeanClass.getAnnotation(MBean.class); String name = mbean.value(); try { exporter.export(classpath+":name="+name, mbeanClass.newInstance()); } catch (Exception e) { e.printStackTrace(); } } }
protected List<Class<?>> loadEntityClassList(Reflections reflections) { Set<Class<?>> entityClassSet = reflections.getTypesAnnotatedWith(PlanningEntity.class); retainOnlyClassesWithDeclaredAnnotation(entityClassSet, PlanningEntity.class); if (ConfigUtils.isEmptyCollection(entityClassSet)) { throw new IllegalStateException("The scanAnnotatedClasses (" + this + ") did not find any classes with a " + PlanningEntity.class.getSimpleName() + " annotation."); } return new ArrayList<>(entityClassSet); }
public DownloaderFactory(Reflections reflections) { this.downloaders = new HashMap<String, Downloader>(); Set<Class<?>> classes = reflections.getTypesAnnotatedWith(com.geccocrawler.gecco.annotation.Downloader.class); for(Class<?> downloaderClass : classes) { com.geccocrawler.gecco.annotation.Downloader downloader = (com.geccocrawler.gecco.annotation.Downloader)downloaderClass.getAnnotation(com.geccocrawler.gecco.annotation.Downloader.class); try { Object o = createDownloader(downloaderClass); if(o instanceof Downloader) { Downloader downloaderInstance = (Downloader)o; String name = downloader.value(); downloaders.put(name, downloaderInstance); } } catch(Exception ex) { ex.printStackTrace(); } } }
@SuppressWarnings("rawtypes") @Override public List<Job> getSysCronClazz(Job job) { Reflections reflections = new Reflections("cc.mrbird.job.task"); List<Job> jobList = new ArrayList<>(); Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(CronTag.class); for (Class cls : annotated) { String clsSimpleName = cls.getSimpleName(); Method[] methods = cls.getDeclaredMethods(); for (Method method : methods) { Job job1 = new Job(); String methodName = method.getName(); Parameter[] methodParameters = method.getParameters(); String params = String.format("%s(%s)", methodName, Arrays.stream(methodParameters).map(item -> item.getType().getSimpleName() + " " + item.getName()).collect(Collectors.joining(", "))); job1.setBeanName(StringUtils.uncapitalize(clsSimpleName)); job1.setMethodName(methodName); job1.setParams(params); jobList.add(job1); } } return jobList; }
for (Class<?> c : reflections.getTypesAnnotatedWith(PreInitializeConfigOptions.class)) { try { loadCount += loadSingleClassUnsafe(c);
/** * Searches for Methods that have either a Path Annotation or a HTTP-Method Annotation */ @SuppressWarnings("unchecked") private Set<Method> findControllerMethods() { Set<Method> methods = Sets.newLinkedHashSet(); methods.addAll(reflections.getMethodsAnnotatedWith(Path.class)); Reflections annotationReflections = new Reflections("", new TypeAnnotationsScanner(), new SubTypesScanner()); for (Class<?> httpMethod : annotationReflections.getTypesAnnotatedWith(HttpMethod.class)) { if (httpMethod.isAnnotation()) { methods.addAll(reflections.getMethodsAnnotatedWith((Class<? extends Annotation>) httpMethod)); } } return methods; }
Set<Class<?>> findAllMessageDrivenClasses() { final StopWatch sw = new StopWatch(); sw.start(); final Reflections reflections = new Reflections("org.projectx", new TypeAnnotationsScanner()); Set<Class<?>> allMessageDrivens = reflections.getTypesAnnotatedWith(MyMessageDriven.class); // NOTE HERE sw.stop(); return allMessageDrivens; }
@Test public void taskCmdUniqueRootElementTest() throws Exception { Set<String> uniqueRootElemSet = new HashSet<String>(); for (Class<?> jaxbClass : reflections.getTypesAnnotatedWith(XmlRootElement.class) ) { XmlRootElement xmlRootElemAnno = jaxbClass.getAnnotation(XmlRootElement.class); assertTrue( xmlRootElemAnno.name() + " is not a unique @XmlRootElement value!", uniqueRootElemSet.add(xmlRootElemAnno.name())); } }