Package org.reflections

Examples of org.reflections.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();


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

public class RequestUrlActivityMapperImpl implements RequestUrlActivityMapper
{
  public String getActivityClassNameFromUrl(String uri)
  {
    Reflections reflections= new Reflections("");
    Set<Class<? extends VisualActivity>> modules= reflections.getSubTypesOf(VisualActivity.class);
    Set<Class<?>> aliases= reflections.getTypesAnnotatedWith(PageAlias.class);

    for (Class<?> type : aliases)
    {
      PageAlias pageAlias= type.getAnnotation(PageAlias.class);
      if (pageAlias != null && uri.contains(pageAlias.alias()))

    return null;
  }

  public List<Class<? extends DragomeVisualActivity>> getExistingVisualActivities()
  {
    Reflections reflections= new Reflections("");
    Set<Class<? extends DragomeVisualActivity>> classes= reflections.getSubTypesOf(DragomeVisualActivity.class);
    return new ArrayList<Class<? extends DragomeVisualActivity>>(classes);
  }

public class ServerReflectionServiceImpl extends ReflectionServiceImpl
{
  public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type)
  {
    Reflections reflections= new Reflections("");
    Set<Class<? extends T>> implementations= reflections.getSubTypesOf(type);
    return implementations;
  }

  public DragomeConfigurator getConfigurator()
  {
    try
    {
      DragomeConfigurator foundConfigurator= null;
      Reflections reflections= new Reflections("");
      Set<Class<? extends DragomeConfigurator>> configurators= reflections.getSubTypesOf(DragomeConfigurator.class);
      for (Class<? extends DragomeConfigurator> class1 : configurators)
        if (!class1.equals(DefaultDragomeConfigurator.class))
          foundConfigurator= class1.newInstance();

      if (foundConfigurator == null)
      {
        Set<Class<?>> typesAnnotatedWith= reflections.getTypesAnnotatedWith(DragomeConfiguratorImplementor.class);
        if (typesAnnotatedWith.isEmpty())
          foundConfigurator= new DefaultDragomeConfigurator();
        else
          foundConfigurator= (DragomeConfigurator) typesAnnotatedWith.iterator().next().newInstance();
      }

      ClassLoader classLoader = ComponentMojoUtil.getClassLoader(classpathElements, this.getClass()
        .getClassLoader());

      ClassPool classPool = ComponentMojoUtil.getClassPool(classLoader);

      Reflections reflections = ComponentMojoUtil.getReflections(classLoader);

      List<CtClass> classList = ComponentMojoUtil.getAllComponentAnnotations(classPool, reflections, getExcludedClasses());

      WidgetRegistry widgetRegistry = new DefaultWidgetRegistry(classPool, classLoader, reflections);

      if (excludedDependencyPaths != null) {
          ClassLoader exclusionClassLoader = ComponentMojoUtil.getClassLoader(excludedDependencyPaths, this
                .getClass().getClassLoader());

          Reflections reflections = ComponentMojoUtil.getReflections(exclusionClassLoader);

          Set<String> excludedClassNames = reflections.getStore().getTypesAnnotatedWith(Component.class.getName());

          return excludedClassNames;
      }

      return null;

  public static void scanClassPathForFormattingAnnotations() {

    ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);

    // scan classpath and filter out classes that don't begin with "com.nds"
    Reflections reflections = new Reflections("com.nds","com.cisco");

    Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(DefaultFormat.class);

//        Reflections ciscoReflections = new Reflections("com.cisco");
//
//        annotated.addAll(ciscoReflections.getTypesAnnotatedWith(DefaultFormat.class));


        Predicate<String> filter = new FilterBuilder().includePackage(
                Constants.DISCONF_PACK_NAME).includePackage(packName);

        //
        Reflections reflections = new Reflections(new ConfigurationBuilder()
                .filterInputsBy(filter)
                .setScanners(new SubTypesScanner().filterResultsBy(filter),
                        new TypeAnnotationsScanner().filterResultsBy(filter),
                        new FieldAnnotationsScanner().filterResultsBy(filter),
                        new MethodAnnotationsScanner().filterResultsBy(filter),

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.