Package org.reflections

Examples of org.reflections.Reflections


        ScanStaticModel scanModel = new ScanStaticModel();

        //
        // 扫描对象
        //
        Reflections reflections = getReflection(packName);
        scanModel.setReflections(reflections);

        //
        // 获取DisconfFile class
        //
        Set<Class<?>> classdata = reflections
                .getTypesAnnotatedWith(DisconfFile.class);
        scanModel.setDisconfFileClassSet(classdata);

        //
        // 获取DisconfFileItem method
        //
        Set<Method> af1 = reflections
                .getMethodsAnnotatedWith(DisconfFileItem.class);
        scanModel.setDisconfFileItemMethodSet(af1);

        //
        // 获取DisconfItem method
        //
        af1 = reflections.getMethodsAnnotatedWith(DisconfItem.class);
        scanModel.setDisconfItemMethodSet(af1);

        //
        // 获取DisconfActiveBackupService
        //
        classdata = reflections
                .getTypesAnnotatedWith(DisconfActiveBackupService.class);
        scanModel.setDisconfActiveBackupServiceClassSet(classdata);

        //
        // 获取DisconfUpdateService
        //
        classdata = reflections
                .getTypesAnnotatedWith(DisconfUpdateService.class);
        scanModel.setDisconfUpdateService(classdata);

        return scanModel;
    }


        ConfigurationBuilder configuration = new ConfigurationBuilder()
                .setScanners(new SubTypesScanner(false), new ResourcesScanner())
                .setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[classLoadersList.size()])))
                .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(inputPackage)));

        Reflections reflections = new Reflections(configuration);

        return reflections.getSubTypesOf(Object.class);
    }

            }

            // Check if there are complements via annotations
            if (d.getPackagesToScan() != null) {
                for (String pack : d.getPackagesToScan()) {
                    Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(
                        ClasspathHelper.forPackage(pack)).setScanners(new MethodAnnotationsScanner()));

                    Set<Method> annotated = reflections.getMethodsAnnotatedWith(Documentation.class);

                    Iterator<Method> it = annotated.iterator();

                    while (it.hasNext()) {
                        Method m = it.next();

   *            upon
   * @return The constructed Reflections object
   */
  public static Reflections getReflections(ClassLoader classLoader) {
    Reflections.log=null;
    Reflections reflections = new Reflections(new ConfigurationBuilder().addClassLoader(classLoader)
      .setUrls(ClasspathHelper.forClassLoader(new ClassLoader[] { classLoader }))
      .setScanners(new TypeAnnotationsScanner()));
    return reflections;
  }

            }

            // Check if there are complements via annotations
            if (d.getPackagesToScan() != null) {
                for (String pack : d.getPackagesToScan()) {
                    Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(
                        ClasspathHelper.forPackage(pack)).setScanners(new MethodAnnotationsScanner()));

                    Set<Method> annotated = reflections.getMethodsAnnotatedWith(Documentation.class);

                    Iterator<Method> it = annotated.iterator();

                    while (it.hasNext()) {
                        Method m = it.next();

    /**
     * Generates a new instance of ReflectionsTypeScanner.
     */
    public ReflectionsTypeScanner() {
        reflections = new Reflections(ClasspathHelper.forJavaClassPath());
    }

    private final List<Runner> runners = new ArrayList<Runner>();
    private final ContextRunnerBuilder builder;

    public CompatibilitySuite(Class<?> clazz) throws Throwable {
        super(clazz, new Class<?>[]{});
        Set<Class<? extends JongoTestCase>> classes = new Reflections(SCANNED_PACKAGE).getSubTypesOf(JongoTestCase.class);
        TestContext testContext = getParameter(getTestClass());
        builder = new ContextRunnerBuilder(testContext);
        runners.addAll(builder.runners(clazz, getTestClassesToRun(classes, testContext.getIgnoredTests())));
    }

        ConfigurationBuilder configuration = new ConfigurationBuilder()
                .setScanners(new SubTypesScanner(false), new ResourcesScanner())
                .setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[classLoadersList.size()])))
                .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(inputPackage)));

        Reflections reflections = new Reflections(configuration);

        Set<Class<?>> subTypesOf = reflections.getSubTypesOf(Object.class);
        return FluentIterable
                .from(subTypesOf)
                .filter(new Predicate<Class<?>>() {
                    @Override
                    public boolean apply(Class<?> input) {

    return packetSerializers;
  }

  private static <T> Set<Class<? extends T>> getPacketClasses(String packageName, Class<T> type) {
    // find the Packet classes inside the given package
    Reflections reflections = new Reflections(packageName);
    Set<Class<? extends T>> packetClasses = reflections.getSubTypesOf(type);

    Iterator<Class<? extends T>> i = packetClasses.iterator();
    while (i.hasNext()) {
      Class<? extends T> packetClass = i.next();

        H = new HashMap<Class<?>, Handler<?>>();
        registerHandlersFromPackage(DemFileHeaderHandler.class.getPackage().getName());
    }
   
    public static void registerHandlersFromPackage(String packageName) {
        Reflections reflections = new Reflections(new ConfigurationBuilder()
            .setUrls(ClasspathHelper.forPackage(packageName))
            .setScanners(new TypeAnnotationsScanner())
            );

        for (Class<?> clazz : reflections.getTypesAnnotatedWith(RegisterHandler.class)) {
            RegisterHandler mb = clazz.getAnnotation(RegisterHandler.class);
            try {
                H.put(mb.value(), (Handler<?>) clazz.newInstance());
            } catch (Exception e) {
                throw new RuntimeException(e);

TOP

Related Classes of org.reflections.Reflections

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.