Package org.reflections

Examples of org.reflections.Reflections


            LOG.warn("Did not find key '" + PACKAGE_PREFIX_KEY + "' and so entities will not be eagerly registered in the Isis metamodel");
            return;
        }
       
        for (String packagePrefix : Splitter.on(",").split(packagePrefixes)) {
            Reflections reflections = new Reflections(packagePrefix);
           
            Set<Class<?>> entityTypes =
                    reflections.getTypesAnnotatedWith(PersistenceCapable.class);
           
            if(noEntitiesIn(entityTypes)) {
                LOG.error("Could not locate any PersistenceCapable entities in " + packagePrefix);
            }
            for (Class<?> entityType : entityTypes) {


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

        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),

        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;
    }

    public static final String PROP_EXTRA_CLASSES = "jaxb.additionalContextClasses";

    public static Class<?>[] findExtraClasses(Class<?> type) {
        String prefix = type.getPackage().getName();
        Reflections reflections = new Reflections(prefix);
        Set<Class<?>> extraClasses = reflections.getTypesAnnotatedWith(XmlRootElement.class);
        return extraClasses.toArray(new Class<?>[extraClasses.size()]);
    }

    this.catalog = new HashMap<String, Class<?>>();
    loadSubclasses(PLUGTEST_2_SUPERCLASS);
  }
 
  public void loadSubclasses(Class<?> superclass) {
    Reflections reflections = new Reflections("ch.ethz.inf.vs.californium");
    for (Class<?> clazz:reflections.getSubTypesOf(superclass))
      loadClass(clazz);
  }

            }

            // 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();

     * default implementation or for some reason the reflection approach is unable to properly get all of the
     * classes required.  It should be clear that a custom implementation of this method is required if there are
     * failures in the GroovyEnvironmentSuite.
     */
    public default Set<Class> getImplementations() {
        final Reflections reflections = new Reflections(this.getClass().getPackage().getName());

        final Set<Class> implementations = new HashSet<>();
        reflections.getSubTypesOf(Graph.class).forEach(implementations::add);
        reflections.getSubTypesOf(Property.class).forEach(implementations::add);
        reflections.getSubTypesOf(Element.class).forEach(implementations::add);
        reflections.getSubTypesOf(Traversal.class).forEach(implementations::add);
        reflections.getSubTypesOf(Traverser.class).forEach(implementations::add);
        reflections.getSubTypesOf(GraphTraversal.class).forEach(implementations::add);
        reflections.getSubTypesOf(DefaultGraphTraversal.class).forEach(implementations::add);

        return implementations.stream()
                .filter(c -> !c.isInterface())
                .collect(Collectors.toSet());
    }

        return (T) jaxbProvider.deserialize(xmlObject);
    }

    @Test
    public void uniqueRootElementTest() throws Exception {
        Reflections reflections = new Reflections(
                ClasspathHelper.forPackage("org.kie.services"),
                new TypeAnnotationsScanner(), new FieldAnnotationsScanner(), new MethodAnnotationsScanner());
        Set<String> idSet = new HashSet<String>();
        Map<String, Class> idClassMap = new HashMap<String, Class>();
        for (Class<?> jaxbClass : reflections.getTypesAnnotatedWith(XmlRootElement.class)) {
            if( ! jaxbClass.getPackage().getName().startsWith("org.kie") ) {
                continue;
            }
            XmlRootElement rootElemAnno = jaxbClass.getAnnotation(XmlRootElement.class);
            String id = rootElemAnno.name();

        testRoundTripClassesSet(extraJaxbClasses);
    }

    @Test
    public void processInstanceIdFieldInCommands() throws Exception {
        Reflections cmdReflections = new Reflections(
                ClasspathHelper.forPackage("org.drools.command.*"),
                new TypeAnnotationsScanner(), new FieldAnnotationsScanner(), new MethodAnnotationsScanner(), new SubTypesScanner());

        Set<Class<?>> classes = cmdReflections.getTypesAnnotatedWith(XmlRootElement.class);
        Set<Class> cmdClasses = new HashSet<Class>();
        for (Class<?> jaxbClass : classes ) {
            if( jaxbClass.getSimpleName().endsWith("Command") ) {
                cmdClasses.add(jaxbClass);
            }

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.