Package org.reflections

Examples of org.reflections.Reflections


            SortedMap<String, SortedSet<String>> positionedServices) {
        initIfRequired();

        for (final String packagePrefix : Iterables.transform(Splitter.on(",").split(packagePrefixes), trim())) {
            Vfs.setDefaultURLTypes(ClassDiscoveryServiceUsingReflections.getUrlTypes());
            Reflections reflections = new Reflections(packagePrefix);

            final Iterable<Class<?>> classes = Iterables.filter(
                    reflections.getTypesAnnotatedWith(DomainService.class), instantiatable());
            for (final Class<?> cls : classes) {

                final DomainService domainService = cls.getAnnotation(DomainService.class);
                final String order = domainService.menuOrder();
                final String serviceName = cls.getName();


    @Override
    public <T> Set<Class<? extends T>> findSubTypesOfClasses(Class<T> type) {
        Vfs.setDefaultURLTypes(getUrlTypes());

        final Reflections reflections = new Reflections(
                ClasspathHelper.forClassLoader(Thread.currentThread().getContextClassLoader()),
                ClasspathHelper.forClass(Object.class),
                new SubTypesScanner(false)
        );
        return reflections.getSubTypesOf(type);
    }

    @Override
    public <T> Set<Class<? extends T>> findSubTypesOfClasses(Class<T> type, String packagePrefix) {
        Vfs.setDefaultURLTypes(getUrlTypes());

        final Reflections reflections = new Reflections(
                ClasspathHelper.forClassLoader(Thread.currentThread().getContextClassLoader()),
                ClasspathHelper.forClass(Object.class),
                ClasspathHelper.forPackage(packagePrefix),
                new SubTypesScanner(false)
        );
        return reflections.getSubTypesOf(type);
    }

      cp.importPackage("org.zkoss.cdi.util");
     
      CtClass mainclas = cp.makeClass("org.zkoss.zkplus.cdi.ZKComponentProducerMethods");
      final List<URL> l = getUrlsForCurrentClasspath();
     
      Reflections reflections = new Reflections(
          new ConfigurationBuilder().setUrls(l)
          .setScanners(new FieldAnnotationsScanner()));
     
      Set<Field> fields = reflections.getFieldsAnnotatedWith(ComponentId.class);
      for (Iterator iterator2 = fields.iterator(); iterator2
          .hasNext();) {
        Field field = (Field) iterator2.next();
        CtClass cls = cp.get(field.getType().getName());
        String pckgName = cls.getPackageName();

    }

    // Gets all classes with some annotation from a package
    public static Set<Class<?>> getClassesWithAnnotation(Class<? extends Annotation> annotation,
                                                         String[] packageNames) {
        Reflections reflections;
        Set<Class<?>> classes = new HashSet<Class<?>>();
        for(String packageName: packageNames) {
            reflections = new Reflections(packageName);
            classes.addAll(reflections.getTypesAnnotatedWith(annotation));
        }
        return classes;
    }

    return map;
  }

  private static Reflections getReflections(){
    if(REFLECTIONS == null){
      REFLECTIONS = new Reflections(new ConfigurationBuilder().setUrls(getMarkedPaths()).setScanners(subTypeScanner, annotationsScanner, resourcesScanner));
    }
    return REFLECTIONS;
  }

      }else{
        urlSet.addAll(getClasspathUrlsByManifest());
        //above procedure doesn't ensure to obtain 'WEB-INF/classes'
        urlSet.add(ClasspathHelper.getUrlForServletContextClasses(sce.getServletContext()));
      }
      Reflections reflections = new Reflections(
          new ConfigurationBuilder().setUrls(urlSet)
          .setScanners(new FieldAnnotationsScanner()));
     
      Set<Field> fields = reflections.getFieldsAnnotatedWith(Autowired.class);
      int methodCounter = 0;
      for (Iterator<Field> iterator2 = fields.iterator(); iterator2.hasNext();) {
        Field mField = (Field) iterator2.next();
        CtClass cls = cp.get(mField.getType().getName());
        String pckgName = cls.getPackageName();

            jarURLs.add(jar.toURI().toURL());
        }

        // Scan classes and all jars
        final List<String> candidates = new ArrayList<String>();
        new Reflections(new ConfigurationBuilder().
                addUrls(jarURLs).setScanners(new AbstractScanner() {
            @Override
            public void scan(Object cls) {
                if ((cls instanceof ClassFile)) {
                    ClassFile classFile = (ClassFile) cls;

      this.addModuleMethods(modulePrefix, documentation.methods);

      // 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<java.lang.reflect.Method> annotated = reflections
              .getMethodsAnnotatedWith(ar.com.jmfsg.documentation.annotation.Documentation.class);

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

            jarURLs.add(jar.toURI().toURL());
        }

        final List<String> injectableClassNames = new ArrayList<String>();
        // Scan classes only
        new Reflections(new ConfigurationBuilder().
                addUrls(classesDirectory.toURI().toURL()).setScanners(new AbstractScanner() {
            @Override
            public void scan(Object cls) {
                if ((cls instanceof ClassFile) && isInjectable((ClassFile) cls, getLog())) {
                    injectableClassNames.add(((ClassFile) cls).getName());

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.