本文整理汇总了Java中org.reflections.Reflections类的典型用法代码示例。如果您正苦于以下问题:Java Reflections类的具体用法?Java Reflections怎么用?Java Reflections使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Reflections类属于org.reflections包,在下文中一共展示了Reflections类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.reflections.Reflections; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Reflections reflections = new Reflections();
LukkitPlus.BUKKIT_EVENTS = reflections.getSubTypesOf(Event.class);
ClassPool classpath = ClassPool.getDefault();
CtClass eventClass = classpath.makeClass("online.pizzacrust.lukkitplus" +
".EventCallback");
for (Class<? extends Event> event : LukkitPlus.BUKKIT_EVENTS) {
CtMethod eventMethod = CtNewMethod.make(CtClass.voidType, "on" + event.getSimpleName
(), new CtClass[] { classpath.get(event.getName()) }, new CtClass[0], "online" +
".pizzacrust.lukkitplus.EventCallbackGenerator.call($1);", eventClass);
eventClass.addMethod(eventMethod);
AnnotationsAttribute attribute = new AnnotationsAttribute(eventClass.getClassFile()
.getConstPool(), AnnotationsAttribute.visibleTag);
Annotation eventHandlerAnnt = new Annotation(EventHandler.class.getName(), eventClass
.getClassFile().getConstPool());
attribute.addAnnotation(eventHandlerAnnt);
eventMethod.getMethodInfo().addAttribute(attribute);
}
System.out.println("Done!");
eventClass.writeFile();
}
示例2: registerAnnotations
import org.reflections.Reflections; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void registerAnnotations() {
final Reflections reflections = new Reflections(packagePrefix);
final Set<Class<?>> namedClasses = reflections.getTypesAnnotatedWith(Named.class);
for (final Class<?> namedClass : namedClasses) {
final ServiceReference reference = namedClassReference(namedClass);
final Constructor<?> namedConstructor = constructorFinder.apply(namedClass);
final ServiceReference<?>[] parameters = stream(namedConstructor.getParameterTypes())
.map(NamedClassReference::namedClassReference)
.toArray(ServiceReference<?>[]::new);
accept(serviceDefinition(
namedClassReference(namedClass),
constructor(reference, namedConstructor, parameters),
postConstructDependencyFinder.apply(namedClass)
));
stream(serviceFromMethodFinder.apply(namedClass)).forEach(this);
}
}
示例3: GuiceApplication
import org.reflections.Reflections; //导入依赖的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);
}
示例4: loadSchemas
import org.reflections.Reflections; //导入依赖的package包/类
private static void loadSchemas() {
Set<String> scan = SchemaScanSettings.SCAN_CLASSPATH;
Map<Integer, NamedSchema> tmp = Maps.newHashMap();
for (String pkg : scan) {
Reflections reflections = new Reflections(pkg);
Set<Class<? extends CustomRecord>> classes = reflections.getSubTypesOf(CustomRecord.class);
for (Class<? extends CustomRecord> cls : classes) {
RecordSchema schema = getSchema(cls);
if (!schema.isIdSchema() && schema.getType() != Type.ENUM) {
System.out.println("Found schema " + schema.getName() + " with id " + schema.getShortId());
tmp.put(schema.getShortId(), schema);
}
}
}
idToName.putAll(tmp);
}
示例5: getRelationships
import org.reflections.Reflections; //导入依赖的package包/类
@Override
@RequestMapping(value = ApiConfig.PROVIDERS_BASE + "/schema", method = RequestMethod.GET,
headers = ApiConfig.API_HEADERS, produces = {ApiConfig.API_PRODUCES})
@ResponseBody
public String getRelationships(
@CookieValue(value = SessionManager.SESSION_COOKIE, required = false) final String sessionId,
final HttpServletResponse response) throws NoSuchProviderException, NoSuchSessionException {
GenerateSchema drawer = new GenerateSchema();
List<Class<? extends Item>> items = new ArrayList<>();
if (rateLimiter.tryAcquire()) {
Reflections reflections = new Reflections("com");
Set<Class<? extends Item>> subTypes = reflections.getSubTypesOf(Item.class);
for (Class<? extends Item> class1 : subTypes) {
items.add(class1);
}
}
Session session = modelValidator.validateSession(sessionId, response);
return drawer.process(stitcher, items, session.getProviders().keySet());
}
示例6: getMethodMap
import org.reflections.Reflections; //导入依赖的package包/类
/**
* 获取方法映射map
*
* @param reflections 反射类列表
* @return 方法映射map
*/
private Map<String, ServerMethod> getMethodMap(Reflections reflections)
throws IllegalAccessException, InstantiationException {
// 获取HermesService注解类
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(HermesService.class);
Map<String, ServerMethod> map = new TreeMap<>();
for (Class<?> c : classes) {
for (Method method : c.getDeclaredMethods()) {
Object object = c.newInstance();
HermesMapping hermesMapping = method.getAnnotation(HermesMapping.class);
if (hermesMapping != null) {
map.put(hermesMapping.value(), new ServerMethod(object, method));
}
}
}
return map;
}
示例7: searchRouters
import org.reflections.Reflections; //导入依赖的package包/类
private void searchRouters(RouteRegister register, String pacakge) {
Reflections reflections = new Reflections(pacakge);
Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Route.class);
for (Class<?> c : annotated) {
Route annotation = c.getAnnotation(Route.class);
try {
if (annotation.method().length > 0)
register.registerRouter(annotation.method()[0], annotation.path(),
(Handler<RoutingContext>) c.newInstance());
else
register.registerRouter(annotation.path(), (Handler<RoutingContext>) c.newInstance());
} catch (InstantiationException | IllegalAccessException | RegisterException e) {
e.printStackTrace();
}
}
}
示例8: autoRegister
import org.reflections.Reflections; //导入依赖的package包/类
/**
* Auto register classes annotated with `Service`
*/
private void autoRegister() {
Reflections reflections = ReflectKit.getReflections(appClass);
// scan inject annotated class
Set<Class<?>> types = reflections.getTypesAnnotatedWith(Service.class);
types.forEach(this::recursiveRegisterType);
// cache constructors
types.forEach(t -> {
try {
ConstructorWalker.findInjectConstructor(t);
} catch (Exception e) {
log.error(e.getMessage());
}
});
}
示例9: doGetClasses
import org.reflections.Reflections; //导入依赖的package包/类
private Set<Class<?>> doGetClasses() {
String packages =
servletContext.getInitParameter(OryxApplication.class.getName() + ".packages");
log.info("Creating JAX-RS from endpoints in package(s) {}", packages);
Objects.requireNonNull(packages);
Set<Class<?>> classes = new HashSet<>();
for (String thePackage : packages.split(",")) {
Reflections reflections = new Reflections(thePackage);
classes.addAll(getClassesInPackageAnnotatedBy(thePackage, reflections, Path.class));
classes.addAll(getClassesInPackageAnnotatedBy(thePackage, reflections, Produces.class));
classes.addAll(getClassesInPackageAnnotatedBy(thePackage, reflections, Provider.class));
}
// Want to configure these globally, but not depend on Jersey, even though it's
// what will be used in practice by the provided apps.
for (String optionalJerseyClass : new String[] {
"org.glassfish.jersey.message.DeflateEncoder",
"org.glassfish.jersey.message.GZipEncoder",
"org.glassfish.jersey.server.filter.EncodingFilter"}) {
if (ClassUtils.classExists(optionalJerseyClass)) {
classes.add(ClassUtils.loadClass(optionalJerseyClass));
}
}
log.debug("Found JAX-RS resources: {}", classes);
return classes;
}
示例10: generateReport
import org.reflections.Reflections; //导入依赖的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");
}
示例11: initImplements
import org.reflections.Reflections; //导入依赖的package包/类
/**
* Initialize customized implements of some features
*/
private void initImplements() {
Reflections reflections = ReflectKit.getReflections(appClass);
// Exception handler
Set<Class<? extends ExceptionHandler>> exceptionHandlers = reflections.getSubTypesOf(ExceptionHandler.class);
if (exceptionHandlers.size() > 0) {
this.exceptionHandler = ioc.resolve(exceptionHandlers.iterator().next());
}
// Session manager
Set<Class<? extends SessionManager>> sessionManagers = reflections.getSubTypesOf(SessionManager.class);
if (sessionManagers.size() > 0) {
this.sessionManager = ioc.resolve(sessionManagers.iterator().next());
}
}
示例12: start
import org.reflections.Reflections; //导入依赖的package包/类
public void start() {
Reflections reflections = new Reflections(packages);
Set<Class<? extends ConsumerAble>> subTypes = reflections.getSubTypesOf(ConsumerAble.class);
for(Class<? extends ConsumerAble> consumerAble : subTypes){
ConsumerAble consumer = ArgumentExtractors.instantiateComponent(beanFactory,consumerAble,null);
consumer.init(this);
}
consumerMap.forEach((cid, consumerId) -> {
Map<String, Tag> tagMap = consumerId.getTagMap();
for (Map.Entry<String, Tag> tagEntry : tagMap.entrySet()) {
Tag tag = tagEntry.getValue();
Object invokeObj = ArgumentExtractors.instantiateComponent(beanFactory, tag.getInvokeCls(), null);
tagEntry.getValue().setInvokeObject(invokeObj);
}
new ConsumerRun(accessKey, secretKey, suffix, consumerId).start();
});
}
示例13: populateMap
import org.reflections.Reflections; //导入依赖的package包/类
private static void populateMap(final Map<String, FsConnRuleCommand<FsConnRuleCmdParamBean, FsConnRuleCmdResultBean>> commands) {
final String commandPackage = "com.espirit.moddev.fstesttools.rules.firstspirit.commands";
LOGGER.info("Scanning class path in '{}' for command classes...", commandPackage);
Reflections reflections = new Reflections(commandPackage);
Set<Class<? extends FsConnRuleCommand>> commandsFromPackage = reflections.getSubTypesOf(FsConnRuleCommand.class);
int counter = 0;
for (Class<? extends FsConnRuleCommand> commandClass : commandsFromPackage) {
if (commandClass.isAnonymousClass()) {
continue;
}
LOGGER.debug("Processing '{}'...", commandClass.getSimpleName());
counter = handleEnumCommands(commands, counter, commandClass);
counter = handleSimpleCommands(commands, counter, commandClass);
}
LOGGER.info("Loaded {} commands!", counter);
}
示例14: getIncludeFields
import org.reflections.Reflections; //导入依赖的package包/类
/**
* Get fields for a type. It extracts all JsonProperty fields
* @param type
* @return
*/
public static String[] getIncludeFields(Class type) {
if (!fieldsCache.containsKey(type.getTypeName())) {
Reflections
reflections =
new Reflections(type.getCanonicalName(), new FieldAnnotationsScanner());
List<String> ret = new ArrayList<>();
for (Field field : reflections.getFieldsAnnotatedWith(JsonProperty.class)) {
JsonProperty property = field.getAnnotation(JsonProperty.class);
ret.add(property.value());
}
if (type.getSuperclass() != null) {
ret.addAll(Arrays.asList(getIncludeFields(type.getSuperclass())));
}
fieldsCache.putIfAbsent(type.getTypeName(), ret.toArray(new String[ret.size()]));
}
return fieldsCache.get(type.getTypeName());
}
示例15: load
import org.reflections.Reflections; //导入依赖的package包/类
public void load() {
Reflections reflect = new Reflections(new Object[]{Manager.class});
Set managers = reflect.getSubTypesOf(Manager.class);
float progress = 0;
for (Object obj : managers) {
Class objClass = (Class)obj;
try {
progress += 100.0f / managers.size();
Manager manager = (Manager)objClass.newInstance();
this.managers.add(manager);
ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft());
ProgressBar progressBar = new ProgressBar(scaledresolution.getScaledWidth() / 2, scaledresolution.getScaledHeight() / 2, 100, 10, progress, "Loading Managers " + this.managers.size() + " / " + managers.size(), -1);
ProgressBarList.addProgress(0, progressBar);
Thread.sleep(10);
} catch (Exception e) {;}
}
this.managers.sort((o2, o1) -> o2.getLoadLevel() - o1.getLoadLevel());
}