Refine search
Reflections reflections = new Reflections("my.project.prefix"); Set<Class<? extends Object>> allClasses = reflections.getSubTypesOf(Object.class);
Reflections reflections = new Reflections("com.mycompany"); Set<Class<? extends MyInterface>> classes = reflections.getSubTypesOf(MyInterface.class);
Reflections reflections = new Reflections("my.project.prefix"); Set<Class<? extends SomeType>> subTypes = reflections.getSubTypesOf(SomeType.class); Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(SomeAnnotation.class);
Reflections reflections = new Reflections("com.mycompany"); Set<Class<? extends MyInterface>> classes = reflections.getSubTypesOf(MyInterface.class);
public static Set<Class<? extends ObjectPayload>> getPayloadClasses () { final Reflections reflections = new Reflections(ObjectPayload.class.getPackage().getName()); final Set<Class<? extends ObjectPayload>> payloadTypes = reflections.getSubTypesOf(ObjectPayload.class); for ( Iterator<Class<? extends ObjectPayload>> iterator = payloadTypes.iterator(); iterator.hasNext(); ) { Class<? extends ObjectPayload> pc = iterator.next(); if ( pc.isInterface() || Modifier.isAbstract(pc.getModifiers()) ) { iterator.remove(); } } return payloadTypes; }
private static ObjectMapper newMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false); mapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE); mapper.disable(SerializationFeature.CLOSE_CLOSEABLE); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); Reflections reflections = new Reflections("com.twitter.ambrose"); Set<Class<? extends Job>> jobSubTypes = reflections.getSubTypesOf(Job.class); mapper.registerSubtypes(jobSubTypes.toArray(new Class<?>[jobSubTypes.size()])); return mapper; } }
/** * Get instances of all subclasses of {@link Command} in a sub-package called "command" the given * package. * * @param pkgName package prefix to look in * @param classArgs type of args to instantiate the class * @param objectArgs args to instantiate the class * @return a mapping from command name to command instance */ public static Map<String, Command> loadCommands(String pkgName, Class[] classArgs, Object[] objectArgs) { Map<String, Command> commandsMap = new HashMap<>(); Reflections reflections = new Reflections(Command.class.getPackage().getName()); for (Class<? extends Command> cls : reflections.getSubTypesOf(Command.class)) { // Add commands from <pkgName>.command.* if (cls.getPackage().getName().equals(pkgName + ".command") && !Modifier.isAbstract(cls.getModifiers())) { // Only instantiate a concrete class Command cmd = CommonUtils.createNewClassInstance(cls, classArgs, objectArgs); commandsMap.put(cmd.getCommandName(), cmd); } } return commandsMap; }
private Set<Class<? extends BeakerxWidget>> getAllInternalWidget() { Reflections reflections = new Reflections(PATH_TO_SCAN); return reflections.getSubTypesOf(BeakerxWidget.class); }
@Provides private EventHubHandler getEventHubHandler(Injector injector, EventHub eventHub) throws ClassNotFoundException { Map<String, Provider<Command>> commandsMap = Maps.newHashMap(); Reflections reflections = new Reflections(PACKAGE_NAME); Set<Class<? extends Command>> commandClasses = reflections.getSubTypesOf(Command.class); for (Class<? extends Command> commandClass : commandClasses) { String path = commandClass.getAnnotation(Path.class).value(); //noinspection unchecked commandsMap.put(path, (Provider<Command>) injector.getProvider(commandClass)); } return new EventHubHandler(eventHub, commandsMap); }
/** * Compute set of canonical names of classes implementing ComputationStep in the specified package using reflection. */ private static Set<Object> retrieveStepPackageStepsCanonicalNames(String packageName) { Reflections reflections = new Reflections(packageName); return reflections.getSubTypesOf(ComputationStep.class).stream() .filter(input -> !Modifier.isAbstract(input.getModifiers())) .map(Class::getCanonicalName) .filter(Objects::nonNull) .collect(Collectors.toSet()); }
protected static Class<?>[] allSuiteClasses() { Reflections reflections = new Reflections("org.cloudfoundry.identity.uaa"); Set<Class<? extends InjectedMockContextTest>> subTypes = reflections.getSubTypesOf(InjectedMockContextTest.class).stream().filter( c -> !Modifier.isAbstract(c.getModifiers()) ).collect(Collectors.toSet()); return subTypes.toArray(new Class[subTypes.size()]); }
@Test public void testTypeInfoTestCoverage() { Reflections reflections = new Reflections("org.apache.flink"); Set<Class<? extends TypeInformation>> typeInfos = reflections.getSubTypesOf(TypeInformation.class); Set<String> typeInfoTestNames = reflections.getSubTypesOf(TypeInformationTestBase.class) .stream().map(Class::getName).collect(Collectors.toSet()); // check if a test exists for each type information for (Class<? extends TypeInformation> typeInfo : typeInfos) { // we skip abstract classes and inner classes to skip type information defined in test classes if (Modifier.isAbstract(typeInfo.getModifiers()) || Modifier.isPrivate(typeInfo.getModifiers()) || typeInfo.getName().contains("Test$") || typeInfo.getName().contains("TestBase$") || typeInfo.getName().contains("ITCase$") || typeInfo.getName().contains("$$anon") || typeInfo.getName().contains("queryablestate")) { continue; } final String testToFind = typeInfo.getName() + "Test"; if (!typeInfoTestNames.contains(testToFind)) { fail("Could not find test '" + testToFind + "' that covers '" + typeInfo.getName() + "'."); } } } }
public static void main(String[] args) { Set<Class<? extends Serializable>> subTypesOfSerializable = new Reflections("org.apache.kylin").getSubTypesOf(Serializable.class); String begin = "kyroClasses.add("; String end = ".class);"; TreeSet<String> sortedSet = new TreeSet(); for (Class clazz : subTypesOfSerializable) { if (clazz.getCanonicalName() != null) sortedSet.add(clazz.getCanonicalName()); } Set<Class<? extends BytesSerializer>> subTypesOfBytes = new Reflections("org.apache.kylin.metadata.datatype").getSubTypesOf(BytesSerializer.class); for (Class clazz : subTypesOfBytes) { if (clazz.getCanonicalName() != null) sortedSet.add(clazz.getCanonicalName()); } Set<Class<? extends MeasureIngester>> subTypesOfMeasure = new Reflections("org.apache.kylin.measure").getSubTypesOf(MeasureIngester.class); for (Class clazz : subTypesOfMeasure) { if (clazz.getCanonicalName() != null) sortedSet.add(clazz.getCanonicalName()); } for (String className : sortedSet) { System.out.println(begin + className + end); } } }
@Test public void ensureStateHandlesHaveSerialVersionUID() { try { Reflections reflections = new Reflections("org.apache.flink"); // check all state handles @SuppressWarnings("unchecked") Set<Class<?>> stateHandleImplementations = (Set<Class<?>>) (Set<?>) reflections.getSubTypesOf(StateObject.class); for (Class<?> clazz : stateHandleImplementations) { validataSerialVersionUID(clazz); } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
testPackages = config.testPackages.toArray(new String[config.testPackages.size()]); Reflections reflections = new Reflections(testPackages, new SubTypesScanner(), new TypeAnnotationsScanner(), new MethodAnnotationsScanner(), new MethodParameterScanner()); Set<Class<? extends AbstractSmackIntegrationTest>> inttestClasses = reflections.getSubTypesOf(AbstractSmackIntegrationTest.class); Set<Class<? extends AbstractSmackLowLevelIntegrationTest>> lowLevelInttestClasses = reflections.getSubTypesOf(AbstractSmackLowLevelIntegrationTest.class);
args.put(String.class, "obj"); Reflections reflections = new Reflections(); Set<Class<? extends Expression>> types = reflections.getSubTypesOf(Expression.class); for (Class<?> type : types) { if (!type.isInterface() && !type.isMemberClass() && !Modifier.isAbstract(type.getModifiers())) {
private static synchronized void load() { LOG.debug("Starting Parser Index Load"); ClassLoader classLoader = ParserIndex.class.getClassLoader(); Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(effectiveClassPathUrls(classLoader))); Set<Class<? extends MessageParser>> indexLoc = reflections.getSubTypesOf(MessageParser.class); Map<String, String> availableParsersLoc = new HashMap<>(); indexLoc.forEach(parserClass -> { if (!"BasicParser".equals(parserClass.getSimpleName())) { availableParsersLoc.put(parserClass.getSimpleName().replaceAll("Basic|Parser", ""), parserClass.getName()); } }); LOG.debug("Finished Parser Index Load; found {} parsers, indexed {} parsers", indexLoc.size(), availableParsersLoc.size()); index = indexLoc; availableParsers = availableParsersLoc; } }
private void init() { providers = Maps.newConcurrentMap(); // use reflection to load providers final Set<Class<? extends IRealizationProvider>> realizationProviders = new Reflections("org.apache.kylin", new SubTypesScanner()).getSubTypesOf(IRealizationProvider.class); List<Throwable> es = Lists.newArrayList(); for (Class<? extends IRealizationProvider> cls : realizationProviders) { try { IRealizationProvider p = (IRealizationProvider) cls.getMethod("getInstance", KylinConfig.class).invoke(null, config); providers.put(p.getRealizationType(), p); } catch (Exception | NoClassDefFoundError e) { es.add(e); } if (es.size() > 0) { for (Throwable exceptionOrError : es) { logger.error("Create new store instance failed ", exceptionOrError); } throw new IllegalArgumentException("Failed to find metadata store by url: " + config.getMetadataUrl()); } } logger.info("RealizationRegistry is " + providers); }
public KVMStoragePoolManager(StorageLayer storagelayer, KVMHAMonitor monitor) { this._haMonitor = monitor; this._storageMapper.put("libvirt", new LibvirtStorageAdaptor(storagelayer)); // add other storage adaptors here // this._storageMapper.put("newadaptor", new NewStorageAdaptor(storagelayer)); this._storageMapper.put(StoragePoolType.ManagedNFS.toString(), new ManagedNfsStorageAdaptor(storagelayer)); // add any adaptors that wish to register themselves via annotation Reflections reflections = new Reflections("com.cloud.hypervisor.kvm.storage"); Set<Class<? extends StorageAdaptor>> storageAdaptors = reflections.getSubTypesOf(StorageAdaptor.class); for (Class<? extends StorageAdaptor> storageAdaptor : storageAdaptors) { StorageAdaptorInfo info = storageAdaptor.getAnnotation(StorageAdaptorInfo.class); if (info != null && info.storagePoolType() != null) { if (this._storageMapper.containsKey(info.storagePoolType().toString())) { s_logger.error("Duplicate StorageAdaptor type " + info.storagePoolType().toString() + ", not loading " + storageAdaptor.getName()); } else { try { this._storageMapper.put(info.storagePoolType().toString(), storageAdaptor.newInstance()); } catch (Exception ex) { throw new CloudRuntimeException(ex.toString()); } } } } for (Map.Entry<String, StorageAdaptor> adaptors : this._storageMapper.entrySet()) { s_logger.debug("Registered a StorageAdaptor for " + adaptors.getKey()); } }
@Override @SuppressWarnings("unchecked") public Set<Class> load(Class key) throws Exception { Reflections reflections = new Reflections(PACKAGES_PREFIX); return reflections.getSubTypesOf(key); } });