public Set<Class<?>> scanClasspathForAnnotation(Class<?> annotation, String... onlyFromPackages) { ClassInfoList classInfoList = scanResult.getClassesWithAnnotation(annotation.getName()); classInfoList = classInfoList .filter(ci -> Arrays.stream(onlyFromPackages) .anyMatch(p -> classMatchesPackage(ci.getName(), p))); return classInfoList.loadClasses().stream().collect(toSet()); }
result.getClassesWithAnnotation(Path.class.getName()) .stream() .filter(once) .forEach(a -> result.getClassesWithAnnotation(a.getName()) .stream() .filter(once)
scanResult.getClassesWithAnnotation(AtomixResource.class.getName()).forEach(classInfo -> { deployment.getRegistry().addPerInstanceResource(classInfo.loadClass(), "/v1"); });
@Override public void handle(ScanResult scanResult, File joinfacesBaseDir) throws IOException { if (scanResult.getClassInfo(MYFACES_ANNOTATION_PROVIDER) == null) { return; } Map<String, List<String>> result = new LinkedHashMap<>(); for (String myfacesAnnotation : MYFACES_ANNOTATIONS) { result.put(myfacesAnnotation, scanResult.getClassesWithAnnotation(myfacesAnnotation).getNames()); } File resultFile = new File(joinfacesBaseDir, MYFACES_ANNOTATION_PROVIDER + ".classes"); writeClassMap(resultFile, result); } }
@Override protected void handleScanResult(ScanResult scanResult) { super.handleScanResult(scanResult); Map<Class<? extends Annotation>, Set<Class<?>>> annotatedClasses = new HashMap<>(); Arrays.asList( ManagedBean.class, FacesComponent.class, FacesBehavior.class, FacesConverter.class, NamedEvent.class, FacesRenderer.class, FacesBehaviorRenderer.class, FacesValidator.class ).forEach(annotationClass -> { List<Class<?>> classes = scanResult.getClassesWithAnnotation(annotationClass.getName()).loadClasses(); annotatedClasses.put(annotationClass, new HashSet<>(classes)); }); JoinFacesAnnotationProvider.setAnnotatedClasses(annotatedClasses); } }
/** * Returns all the class types annotated with an annotation * * @param annotation * The given annotations to find * * @return The set of classes that have the types annotated */ @NotNull @SuppressWarnings({"unchecked", "WeakerAccess"}) public Set<Class> getTypesAnnotatedWith(Class<? extends Annotation> annotation) { ClassInfoList subtypes = GuiceContext.instance() .getScanResult() .getClassesWithAnnotation(annotation.getCanonicalName()); return new HashSet(subtypes.loadClasses()); }
/** * Returns all the class types annotated with an annotation * * @param annotation * The given annotations to find * * @return The set of classes that have the types annotated */ @NotNull @SuppressWarnings({"unchecked", "WeakerAccess"}) public Set<Class> getTypesAnnotatedWith(Class<? extends Annotation> annotation) { ClassInfoList subtypes = GuiceContext.instance() .getScanResult() .getClassesWithAnnotation(annotation.getCanonicalName()); return new HashSet(subtypes.loadClasses()); }
/** * Returns all the class types annotated with an annotation * * @param annotation * The given annotations to find * * @return The set of classes that have the types annotated */ @NotNull @SuppressWarnings({"unchecked", "WeakerAccess"}) public Set<Class> getTypesAnnotatedWith(Class<? extends Annotation> annotation) { ClassInfoList subtypes = GuiceContext.instance() .getScanResult() .getClassesWithAnnotation(annotation.getCanonicalName()); return new HashSet(subtypes.loadClasses()); }
public static List<SourceType<Type>> scanAutomaticJaxrsApplication(ScanResult scanResult, Predicate<String> isClassNameExcluded) { final List<String> namesOfResourceClasses = scanResult.getClassesWithAnnotation(Path.class.getName()).getNames(); final List<Class<?>> resourceClasses = Input.loadClasses(namesOfResourceClasses); TypeScriptGenerator.getLogger().info(String.format("Found %d root resources.", resourceClasses.size())); return new JaxrsApplicationScanner().scanJaxrsApplication(null, resourceClasses, isClassNameExcluded); }
result.addAll(scanResult.getClassesWithAnnotation(annotationClassName).getNames()); result.addAll(scanResult.getClassesWithFieldAnnotation(annotationClassName).getNames()); result.addAll(scanResult.getClassesWithMethodAnnotation(annotationClassName).getNames());
public Validators(final String packageName) { this.validatorTypes = new EnumMap<>(Validation.class); this.validators = new ValidatorMap(); fillValidatorTypes(this.validatorTypes); final List<Class<?>> klasses = new ArrayList<>(); // Scan all classes in the given package with the Tag annotation try (ScanResult scanResult = new ClassGraph().enableAllInfo().whitelistPackages(packageName) .scan()) { final ClassInfoList tagClassInfoList = scanResult .getClassesWithAnnotation("org.openstreetmap.atlas.tags.annotations.Tag"); tagClassInfoList.loadClasses().forEach(klasses::add); } klasses.stream().forEach(this::processClass); }
private Set<Class<?>> scanClasses(final Set<Class<? extends Annotation>> supportedAnnotations) { Set<Class<?>> result = new LinkedHashSet<>(); ClassGraph classGraph = new ClassGraph() .enableAllInfo() .enableExternalClasses(); List<String> basePackages = this.properties.getBasePackages(); if (basePackages != null && !basePackages.isEmpty()) { classGraph = classGraph.whitelistPackages(basePackages.toArray(new String[0])); } try (ScanResult scanResult = classGraph.scan()) { for (final Class<? extends Annotation> supportedAnnotation : supportedAnnotations) { result.addAll(scanResult.getClassesWithAnnotation(supportedAnnotation.getName()).loadClasses(true)); result.addAll(scanResult.getClassesWithMethodAnnotation(supportedAnnotation.getName()).loadClasses(true)); result.addAll(scanResult.getClassesWithFieldAnnotation(supportedAnnotation.getName()).loadClasses(true)); } } return result; }
public static void checkInitByAnnotatedClass() { if (!annotatedClassInitialized) { // look for classes annotated with @Properties try (ScanResult scanResult = new ClassGraph().enableAllInfo().scan()) { ClassInfoList classInfoList = scanResult.getClassesWithAnnotation(io.github.thingersoft.pm.api.annotations.Properties.class.getName()); for (ClassInfo mappedClassInfo : classInfoList) { Class<?> mappedClass = mappedClassInfo.loadClass(); initByAnnotatedClass(mappedClass); } } catch (IllegalArgumentException e) { throw new RuntimeException("Properties injection mapping failed", e); } } }
.overrideClasspath(fin) .scan()) { ClassInfoList csvList = scanResult.getClassesWithAnnotation(CsvMarshaller.class.getCanonicalName()); for (ClassInfo csvClassInfo : csvList) { final Class<?> csvClass = csvClassInfo.loadClass();
scanResult.getClassesWithAnnotation(Entity.class.getName()); entities.addAll(scanResult.getClassesWithAnnotation(Embedded.class.getName())); logger.info("Found " + entities.size() + " entities in classpath"); for (String cn : entities.getNames()) {
.getClassesWithAnnotation("org.openstreetmap.atlas.tags.annotations.Tag");
public static List<Class<?>> findClasses(Class<? extends Annotation> annotation, String... packages) { Validate.argumentsAreNotNull(annotation, packages); return new ClassGraph() .whitelistPackages(packages) .enableAnnotationInfo() .scan() .getClassesWithAnnotation(annotation.getName()) .loadClasses(); }
final ScanResult scanResult = classpathScanner.getScanResult(); types.addAll(fromClassNames(classesWithAnnotations.stream() .flatMap(annotation -> scanResult.getClassesWithAnnotation(annotation).getNames().stream()) .distinct() .collect(Collectors.toList())
classes.addAll(scanResult.getClassesWithAnnotation(name).getNames()); classes.addAll(scanResult.getClassesWithMethodAnnotation(name).getNames()); classes.addAll(scanResult.getClassesWithFieldAnnotation(name).getNames());
scanResult.getClassesWithAnnotation(AtomixResource.class.getName()).forEach(classInfo -> { deployment.getRegistry().addPerInstanceResource(classInfo.loadClass(), "/v1"); });