當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodAnnotationsScanner類代碼示例

本文整理匯總了Java中org.reflections.scanners.MethodAnnotationsScanner的典型用法代碼示例。如果您正苦於以下問題:Java MethodAnnotationsScanner類的具體用法?Java MethodAnnotationsScanner怎麽用?Java MethodAnnotationsScanner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MethodAnnotationsScanner類屬於org.reflections.scanners包,在下文中一共展示了MethodAnnotationsScanner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fromConfigWithPackage

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
/**
 * Scans the specified packages for annotated classes, and applies Config values to them.
 * 
 * @param config the Config to derive values from
 * @param packageNamePrefix the prefix to limit scanning to - e.g. "com.github"
 * @return The constructed TypesafeConfigModule.
 */
public static TypesafeConfigModule fromConfigWithPackage(Config config, String packageNamePrefix) {
	 ConfigurationBuilder configBuilder = 
		 new ConfigurationBuilder()
         .filterInputsBy(new FilterBuilder().includePackage(packageNamePrefix))
         .setUrls(ClasspathHelper.forPackage(packageNamePrefix))
         .setScanners(
        	new TypeAnnotationsScanner(), 
        	new MethodParameterScanner(), 
        	new MethodAnnotationsScanner(), 
        	new FieldAnnotationsScanner()
         );
	Reflections reflections = new Reflections(configBuilder);
	
	return new TypesafeConfigModule(config, reflections);
}
 
開發者ID:racc,項目名稱:typesafeconfig-guice,代碼行數:23,代碼來源:TypesafeConfigModule.java

示例2: generateReport

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
public void generateReport(String packageName,List<String> flagList) throws IOException
{

    URL testClassesURL = Paths.get("target/test-classes").toUri().toURL();

    URLClassLoader classLoader = URLClassLoader.newInstance(new URL[]{testClassesURL},
            ClasspathHelper.staticClassLoader());

    reflections = new Reflections(new ConfigurationBuilder()
            .setUrls(ClasspathHelper.forPackage(packageName,classLoader))
            .addClassLoader(classLoader)
            .filterInputsBy(new FilterBuilder().includePackage(packageName))
            .setScanners(new MethodAnnotationsScanner(), new TypeAnnotationsScanner(), new SubTypesScanner())
    );


    List<Map<String, TestClass>> list = new ArrayList<>();

    for (String flag : flagList)
    {
        list.add(printMethods(flag));
    }

    Gson gson = new Gson();
    String overviewTemplate = IOUtils.toString(getClass().getResourceAsStream("/index.tpl.html"));


    String editedTemplate = overviewTemplate.replace("##TEST_DATA##", gson.toJson(list));

    FileUtils.writeStringToFile(new File("target/test-list-html-report/index.html"), editedTemplate);
    logger.info("report file generated");
}
 
開發者ID:cyildirim,項目名稱:Lahiya,代碼行數:33,代碼來源:LahiyaTestCaseReport.java

示例3: AlgorithmServiceImpl

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
public AlgorithmServiceImpl() {
	map = new HashMap<>();
	List<URL> urlList = new ArrayList<>();
	for(String f:System.getProperty("java.class.path").split(":")){
		System.err.println(f);
		try {
			urlList.add(new File(f).toURI().toURL());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	URL[] urls = urlList.toArray(new URL[0]);
	Reflections reflections = new Reflections("jobreading.algorithm.experiment",new MethodAnnotationsScanner(),urls);
	for(Method method : reflections.getMethodsAnnotatedWith(Algorithm.class)){
		final Algorithm my = method.getAnnotation(Algorithm.class);
		Class<?> clazz = method.getDeclaringClass();
		if (null != my) {
			map.put(my.name(), clazz);
		}
	}
}
 
開發者ID:kaichao,項目名稱:algorithm.annotation,代碼行數:22,代碼來源:AlgorithmServiceImpl.java

示例4: scanTypes

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
private Set<Class<?>> scanTypes(String packageName) {
    Reflections reflections = new Reflections(packageName,
            new MethodAnnotationsScanner());
    Set<Class<?>> types = new HashSet<>();
    types.addAll(typesAnnotatedWith(reflections, Given.class));
    types.addAll(typesAnnotatedWith(reflections, When.class));
    types.addAll(typesAnnotatedWith(reflections, Then.class));
    types.addAll(typesAnnotatedWith(reflections, Before.class));
    types.addAll(typesAnnotatedWith(reflections, After.class));
    types.addAll(typesAnnotatedWith(reflections, BeforeScenario.class));
    types.addAll(typesAnnotatedWith(reflections, AfterScenario.class));
    types.addAll(typesAnnotatedWith(reflections, BeforeStory.class));
    types.addAll(typesAnnotatedWith(reflections, AfterStory.class));
    types.addAll(typesAnnotatedWith(reflections, BeforeStories.class));
    types.addAll(typesAnnotatedWith(reflections, AfterStories.class));
    types.addAll(typesAnnotatedWith(reflections, AsParameterConverter
            .class));
    return types;
}
 
開發者ID:tapack,項目名稱:satisfy,代碼行數:20,代碼來源:ScanningStepsFactory.java

示例5: scan

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
public void scan(String base) {
	Reflections reflections = new Reflections(new ConfigurationBuilder()
		.setUrls(ClasspathHelper.forPackage(base))
		.setScanners(new MethodAnnotationsScanner())
	);

	Set<Method> predicateMethods = reflections.getMethodsAnnotatedWith(Predicate.class);

	for (Method method : predicateMethods) {
		String name = method.getAnnotation(Predicate.class).name();

		if (name.isEmpty()) {
			name = method.getName();
		}

		this.register(method, name);
	}
}
 
開發者ID:alpha-asp,項目名稱:Alpha,代碼行數:19,代碼來源:Alpha.java

示例6: getKeywordClassList

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
private String getKeywordClassList(URLClassLoader cl) throws Exception {
	URL url = cl.getURLs()[0];
	try {
		Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(url)
				.addClassLoader(cl).setScanners(new MethodAnnotationsScanner()));
		Set<Method> methods = reflections.getMethodsAnnotatedWith(Keyword.class);
		Set<String> kwClasses = new HashSet<>();
		for(Method method:methods) {
			kwClasses.add(method.getDeclaringClass().getName());
		}
		StringBuilder kwClassnamesBuilder = new StringBuilder();
		kwClasses.forEach(kwClassname->kwClassnamesBuilder.append(kwClassname+";"));
		return kwClassnamesBuilder.toString();
	} catch (Exception e) {
		String errorMsg = "Error while looking for methods annotated with @Keyword in "+url.toString();
		throw new Exception(errorMsg, e);
	}
}
 
開發者ID:denkbar,項目名稱:step,代碼行數:19,代碼來源:JavaJarHandler.java

示例7: getReflected

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
private static Set<Class<?>> getReflected() {
    synchronized (LOCK) {
        if (reflected != null) {
            return reflected;
        }
        Reflections reflections = new Reflections(new ConfigurationBuilder()
                .setUrls(ClasspathHelper.forPackage("com.jivesoftware"))
                .setScanners(new MethodAnnotationsScanner(), new TypeAnnotationsScanner()));
        Set<Class<?>> result = reflections.getTypesAnnotatedWith(Path.class);
        Set<Method> methods = reflections.getMethodsAnnotatedWith(Path.class);
        for (Method method : methods) {
            result.add(method.getDeclaringClass());
        }
        reflected = Collections.unmodifiableSet(result);
        return reflected;
    }
}
 
開發者ID:jivesoftware,項目名稱:routing-bird,代碼行數:18,代碼來源:RestfulHelpEndpoints.java

示例8: test

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
public void test()
{
	final Reflections reflections = new Reflections(new ConfigurationBuilder()
			.addUrls(ClasspathHelper.forClassLoader())
			.setScanners(new MethodAnnotationsScanner())
			);

	final Set<Method> methods = reflections.getMethodsAnnotatedWith(Cached.class);
	System.out.println("Found " + methods.size() + " methods annotated with " + Cached.class);

	for (final Method method : methods)
	{
		testMethod(method);
	}

	assertNoExceptions();
}
 
開發者ID:metasfresh,項目名稱:metasfresh,代碼行數:18,代碼來源:ClasspathCachedMethodsTester.java

示例9: getActionContext

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
private Set<ActionData> getActionContext(String controllerPackageScan) {
    Set<ActionData> resourceContext = new HashSet<ActionData>();

    if (controllerPackageScan.isEmpty()) return resourceContext;

    Reflections reflections = new Reflections(new ConfigurationBuilder()
            .addUrls(ClasspathHelper.forPackage(controllerPackageScan))
            .setScanners(new MethodAnnotationsScanner()));

    Set<Method> methodSet = reflections.getMethodsAnnotatedWith(Action.class);

    for (Method method : methodSet) {
        Secured authenticated = (Secured)method.getAnnotation(Secured.class);
        Action action = (Action)method.getAnnotation(Action.class);

        if (null != action) {
            resourceContext.add(new ActionData(action.uri(), action.method(), authenticated != null, method));
        }
    }

    return resourceContext;
}
 
開發者ID:hasanozgan,項目名稱:flex,代碼行數:23,代碼來源:FlexUrlResolver.java

示例10: invokeAnnotatedMethods

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
public void invokeAnnotatedMethods( Object inObject, Class<? extends Annotation> inAnnotation ) throws InvokeAnnotatedMethodException
{
	// Retrieve all methods annotated with the given annotation
	Reflections reflections = new Reflections( inObject.getClass().getName(), new MethodAnnotationsScanner() );
	Set<Method> methods = reflections.getMethodsAnnotatedWith( inAnnotation );
	
	// Invoke them
	for( Method method : methods )
	{
		try {
			method.invoke( inObject, new Object[]{} );
		} catch (IllegalAccessException | IllegalArgumentException
				| InvocationTargetException e) {
			throw new InvokeAnnotatedMethodException( method );
		}
	}
}
 
開發者ID:jbouny,項目名稱:EJBContainer,代碼行數:18,代碼來源:DynamicHelper.java

示例11: addUrlsTo

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
@Override
public void addUrlsTo(WebSitemapGenerator generator) {
  String baseUrl = configuration.getString("sitemap.baseUrl");

  ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  Reflections reflections = new Reflections("controllers", new MethodAnnotationsScanner());

  Set<Method> actions = reflections.getMethodsAnnotatedWith(SitemapItem.class);
  for(Method method : actions) {
    String actionUrl = actionUrl(classLoader, method);
    SitemapItem annotation = method.getAnnotation(SitemapItem.class);
    if(annotation != null) {
      WebSitemapUrl url = webSitemapUrl(baseUrl, actionUrl, annotation);
      generator.addUrl(url);
    }
  }
}
 
開發者ID:edulify,項目名稱:play-sitemap-module.edulify.com,代碼行數:18,代碼來源:AnnotationUrlProvider.java

示例12: init

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
private void init(String packageName) {
  FilterBuilder filters = new FilterBuilder().includePackage(packageName);

  Scanner[] scanners = {
      new TypeAnnotationsScanner(),
      new MethodAnnotationsScanner(),
      new MethodParameterScanner(),
      new FieldAnnotationsScanner(),
      new SubTypesScanner().filterResultsBy(filters)
  };

  reflections = new ConfigurationBuilder()
      .addUrls(ClasspathHelper.forPackage(packageName))
      .addScanners(scanners)
      .filterInputsBy(filters)
      .build();
}
 
開發者ID:hawky-4s-,項目名稱:restapidoc,代碼行數:18,代碼來源:ClassPathScanner.java

示例13: reflections

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
/**
 * {@link Reflections} bean.
 *
 * @return bean
 */
@Bean
public Reflections reflections() {
    return new Reflections(new ConfigurationBuilder()
                               .setUrls(ClasspathHelper.forPackage(SCAN_PACKAGE))
                               .setScanners(new MethodAnnotationsScanner()));
}
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:12,代碼來源:ReflectionConfig.java

示例14: findFunctions

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
@Override
public Set<Method> findFunctions(final URL url) {
    return new Reflections(
            new ConfigurationBuilder()
                    .addUrls(url)
                    .setScanners(new MethodAnnotationsScanner())
                    .addClassLoader(getClassLoader(url)))
            .getMethodsAnnotatedWith(FunctionName.class);
}
 
開發者ID:Microsoft,項目名稱:azure-maven-plugins,代碼行數:10,代碼來源:AnnotationHandlerImpl.java

示例15: configure

import org.reflections.scanners.MethodAnnotationsScanner; //導入依賴的package包/類
@Override
    public ReflectionsWrapper configure() {
        reflections = (Reflections) cache.get(Reflections.class.getName());

        if (reflections == null) {
            ConfigurationBuilder cb = new ConfigurationBuilder();

            Set<URL> classLocations = new LinkedHashSet<>();

            try {
                List<URL> urls = Collections.list(Thread.currentThread().getContextClassLoader().getResources(""));

                for (URL url : urls) {
                    if (url.getPath().contains("/geemvc/target/")) {
                        classLocations.add(url);
                    }
                }
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }

            cb = cb.addUrls(classLocations).addClassLoader(Thread.currentThread().getContextClassLoader());
            cb = cb.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new MethodAnnotationsScanner(), new SubTypesScanner());
            reflections = cb.build();

//            Reflections cachedReflections = (Reflections)
              cache.putIfAbsent(Reflections.class.getName(), reflections);

//            if (cachedReflections != null)
//                reflections = cachedReflections;
        }

        return this;
    }
 
開發者ID:geetools,項目名稱:geeMVC-Java-MVC-Framework,代碼行數:35,代碼來源:TestReflectionsWrapper.java


注:本文中的org.reflections.scanners.MethodAnnotationsScanner類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。