本文整理汇总了Java中org.reflections.scanners.TypeAnnotationsScanner类的典型用法代码示例。如果您正苦于以下问题:Java TypeAnnotationsScanner类的具体用法?Java TypeAnnotationsScanner怎么用?Java TypeAnnotationsScanner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TypeAnnotationsScanner类属于org.reflections.scanners包,在下文中一共展示了TypeAnnotationsScanner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GuiceApplication
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的package包/类
protected GuiceApplication(String... basePackages) {
final ConfigurationBuilder confBuilder = new ConfigurationBuilder();
final FilterBuilder filterBuilder = new FilterBuilder();
if (basePackages.length == 0) {
basePackages = new String[] {};
}
logger.info("op=create, auto_scan_packages={}", (Object[]) basePackages);
for (String pkg : basePackages) {
confBuilder.addUrls(ClasspathHelper.forPackage(pkg));
filterBuilder.include(FilterBuilder.prefix(pkg));
}
confBuilder.filterInputsBy(filterBuilder)
.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
this.reflections = new Reflections(confBuilder);
}
示例2: fromConfigWithPackage
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的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);
}
示例3: generateReport
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的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");
}
示例4: ReflectionsServiceDiscovery
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的package包/类
public ReflectionsServiceDiscovery(String resourceSearchPackages, JsonServiceLocator locator) {
this.locator = locator;
ConfigurationBuilder builder = new ConfigurationBuilder();
PreconditionUtil.assertNotNull("no resourceSearchPackage configured", resourceSearchPackages);
FilterBuilder filter = new FilterBuilder();
for (String resourceSearchPackage : resourceSearchPackages.split(",")) {
builder = builder.addUrls(ClasspathHelper.forPackage(resourceSearchPackage));
filter.includePackage(resourceSearchPackage);
}
filter.includePackage(Repository.class.getPackage().getName());
filter.includePackage(ResourceRepository.class.getPackage().getName());
builder = builder.filterInputsBy(filter);
builder = builder.addUrls(ClasspathHelper.forClass(Repository.class));
builder = builder.addUrls(ClasspathHelper.forClass(ResourceRepository.class));
builder = builder.addUrls(ClasspathHelper.forClass(ResourceRepositoryV2.class));
builder = builder.setScanners(new SubTypesScanner(false), new TypeAnnotationsScanner());
reflections = new Reflections(builder);
}
示例5: addLoader
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的package包/类
public void addLoader(ClassLoader loader) {
if (builder == null) {
this.builder = new ConfigurationBuilder();
builder.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
}
builder.addClassLoader(loader);
builder.addUrls(ClasspathHelper.forClassLoader(loader));
if(loader instanceof JoinClassLoader) {
// When the object "reflections" is created in the method scanClassPath(), are scanned the URLs so
// it is necessary to add the URLs from the enclosing class loader in the JoinClassLoader that it
// contains the fixture classpath (see org.reflections.Reflections.scan()).
builder.addUrls(ClasspathHelper.forClassLoader(((JoinClassLoader) loader).getEnclosingClassLoader()));
}
scanClassPath(builder);
}
示例6: getReflected
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的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;
}
}
示例7: init
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的package包/类
public synchronized void init(ServletContext context) {
if (HANDLERS != null) {
return;
}
LOG.info("Initializing output handlers...");
Map<String, Class<? extends IOutputHandler>> handlers = new HashMap<>();
Reflections reflections = new Reflections(new ConfigurationBuilder()
.addUrls(ClasspathHelper.forWebInfLib(context))
.setScanners(new TypeAnnotationsScanner(), new SubTypesScanner(false)));
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(OutputHandler.class);
for (Class<?> clazz : classes) {
LOG.info("Found annotated output handler class: " + clazz.getName());
if (IOutputHandler.class.isAssignableFrom(clazz)) {
String id = clazz.getAnnotation(OutputHandler.class).id();
//noinspection unchecked
handlers.put(id, (Class<? extends IOutputHandler>)clazz);
LOG.info("Added output handler " + id + " in class: " + clazz.getName());
}
}
HANDLERS = handlers;
LOG.info("Initialization of output handlers completed.");
}
示例8: test
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的package包/类
public void test()
{
final Reflections reflections = new Reflections(new ConfigurationBuilder()
.addUrls(ClasspathHelper.forClassLoader())
.setScanners(new TypeAnnotationsScanner(), new SubTypesScanner())
);
final Set<Class<?>> classes_withValidator = reflections.getTypesAnnotatedWith(Validator.class);
System.out.println("Found " + classes_withValidator.size() + " classes annotated with " + Validator.class);
final Set<Class<?>> classes_withInterceptor = reflections.getTypesAnnotatedWith(Interceptor.class);
System.out.println("Found " + classes_withInterceptor.size() + " classes annotated with " + Interceptor.class);
final Set<Class<?>> classes = ImmutableSet.<Class<?>> builder()
.addAll(classes_withValidator)
.addAll(classes_withInterceptor)
.build();
System.out.println("=> " + classes.size() + " classes to test");
for (final Class<?> clazz : classes)
{
testClass(clazz);
}
assertNoExceptions();
}
示例9: scanConceptsWithReflections
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的package包/类
private void scanConceptsWithReflections() throws ObjectStoreConfigException {
logger.debug("Search for concepts with reflections");
Set<URL> classpath = new HashSet<>();
classpath.addAll(ClasspathHelper.forClassLoader());
classpath.addAll(ClasspathHelper.forJavaClassPath());
classpath.addAll(ClasspathHelper.forManifest());
classpath.addAll(ClasspathHelper.forPackage(""));
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(classpath)
.useParallelExecutor()
.filterInputsBy(FilterBuilder.parsePackages("-java, -javax, -sun, -com.sun"))
.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner()));
Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Iri.class, true);
logger.debug("Search for concepts with reflections resulted in " + annotated.size() + " classes");
for (Class clazz : annotated) {
logger.debug("Found concept class: " + clazz.getCanonicalName());
roleMapper.addConcept(clazz);
}
}
示例10: init
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的package包/类
/**
* Init stuff is responsible to grab all DTOs found in classpath (classloader) and setup model for
* String Template
*/
protected void init() {
ConfigurationBuilder configurationBuilder =
new ConfigurationBuilder().setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
if (useClassPath) {
configurationBuilder.setUrls(forJavaClassPath());
} else {
configurationBuilder.setUrls(forClassLoader());
}
// keep only DTO interfaces
Reflections reflections = new Reflections(configurationBuilder);
List<Class<?>> annotatedWithDtos =
new ArrayList<>(reflections.getTypesAnnotatedWith(DTO.class));
List<Class<?>> interfacesDtos =
annotatedWithDtos
.stream()
.filter(clazz -> clazz.isInterface())
.collect(Collectors.toList());
interfacesDtos.stream().forEach(this::analyze);
}
示例11: execute
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的package包/类
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage(basePackage)).setScanners(
new SubTypesScanner(), new TypeAnnotationsScanner()));
Set<Class<?>> resources = reflections
.getTypesAnnotatedWith(Resource.class);
Set<Class<?>> apis = reflections
.getTypesAnnotatedWith(ApiGateway.class);
Map<String, EndpointResource> endpointResources = getEndpointResources(resources);
String apiName = getApiName(apis);
fileWriter.createSwaggerFile(new ArrayList<EndpointResource>(endpointResources.values()), apiName);
}
示例12: registerScriptEngineFactories
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void registerScriptEngineFactories() {
List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))
.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("com.jsen"))));
Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(ScriptEngineFactory.class);
for (Class<?> clazz : annotated) {
if (AbstractScriptEngineFactory.class.isAssignableFrom(clazz)) {
registerMimeContentFactory((Class<AbstractScriptEngineFactory>)clazz);
}
}
}
示例13: createReflections
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的package包/类
/**
* Creates a {@link org.reflections.Reflections} with the given packages (configuration)
*
* @param scanPackages
*/
private void createReflections(String[] scanPackages) {
if (scanPackages.length < 1) {
LOGGER.warn("No package defined in configuration (scanPackages)!");
return;
}
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
FilterBuilder filterBuilder = new FilterBuilder();
for (String packageName : scanPackages) {
configurationBuilder.addUrls(ClasspathHelper.forPackage(packageName));
filterBuilder.include(FilterBuilder.prefix(packageName));
}
configurationBuilder.filterInputsBy(filterBuilder).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
this.reflections = new Reflections(configurationBuilder);
}
示例14: init
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的package包/类
public void init() {
packages = config.getConfig().getString("fuse.scan.packages");
verbose = config.getConfig().getBoolean("fuse.scan.verbose");
if (!StringUtils.isEmpty(packages)) {
// prepare reflections config builder
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addScanners(new TypeAnnotationsScanner());
// add packages to scan
Arrays.stream(packages.split(","))
.forEach(
name -> builder.addUrls(ClasspathHelper.forPackage(name))
);
reflections = new Reflections(builder);
}
}
示例15: buildReflections
import org.reflections.scanners.TypeAnnotationsScanner; //导入依赖的package包/类
private Reflections buildReflections(String packages) {
String[] packagesArray = packages.replaceAll(" ", "").split(",");
FilterBuilder filter = new FilterBuilder();
Set<URL> urls = new HashSet();
for (String packageStr : packagesArray) {
urls.addAll(ClasspathHelper.forPackage(packageStr));
filter.include(FilterBuilder.prefix(packageStr));
}
return new Reflections(new ConfigurationBuilder()
.addUrls(urls)
.filterInputsBy(filter)
.setScanners(new TypeAnnotationsScanner(), new SubTypesScanner()));
}