本文整理汇总了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);
}
示例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");
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
}
示例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();
}
示例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;
}
示例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 );
}
}
}
示例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);
}
}
}
示例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();
}
示例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()));
}
示例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);
}
示例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;
}