本文整理匯總了Java中org.reflections.ReflectionUtils類的典型用法代碼示例。如果您正苦於以下問題:Java ReflectionUtils類的具體用法?Java ReflectionUtils怎麽用?Java ReflectionUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ReflectionUtils類屬於org.reflections包,在下文中一共展示了ReflectionUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: EsPropertyNamingStrategy
import org.reflections.ReflectionUtils; //導入依賴的package包/類
public EsPropertyNamingStrategy(Class type, Class<? extends EsStore> store) {
this.effectiveType = type;
for (Field field : ReflectionUtils.getAllFields(type)) {
JsonProperty jsonProperty = field.getAnnotation(JsonProperty.class);
EsStoreMappingProperty
storeSpecificProperty =
field.getAnnotation(EsStoreMappingProperty.class);
if ((jsonProperty == null && storeSpecificProperty == null)
|| (storeSpecificProperty != null && storeSpecificProperty.ignore())) {
continue;
}
if (storeSpecificProperty == null || storeSpecificProperty.store() != store) {
fieldToJsonMapping.put(jsonProperty.value(), jsonProperty.value());
} else if (storeSpecificProperty.value().indexOf('.') < 0) {
fieldToJsonMapping.put(jsonProperty.value(), storeSpecificProperty.value());
}
}
}
示例2: getDeclaredFilters
import org.reflections.ReflectionUtils; //導入依賴的package包/類
private static<T> List<T> getDeclaredFilters(Class<?> suiteClass, Class<T> returnType) {
final Set<Method> methods = ReflectionUtils.getAllMethods(suiteClass,
withAnnotation(TestFilterMethod.class),
withModifier(Modifier.STATIC),
withParametersCount(0),
withReturnTypeAssignableTo(returnType));
return methods.stream().flatMap(m -> {
try {
final T filter = (T) m.invoke(null);
if (filter != null) {
return Stream.of(filter);
}
} catch (final Exception ex) {
log.warn("Unable to construct test filter ", ex);
}
return Stream.of();
}).collect(Collectors.toList());
}
示例3: invokeLambdaFunction_testFunction2_method1
import org.reflections.ReflectionUtils; //導入依賴的package包/類
@Test
public void invokeLambdaFunction_testFunction2_method1() throws Exception {
MockHttpServletRequest req = new MockHttpServletRequest();
req.setContent("tempo".getBytes());
MockHttpServletResponse resp = new MockHttpServletResponse();
lambdaLocalServlet.invokeLambdaFunction(req,
resp,
new LambdaFunction("/testPath2",
TestFunction2.class,
ReflectionUtils.getMethods(TestFunction2.class,
method -> method.getName().equals("method1")).stream()
.findFirst()
.get(),
new StringDeserializer(),
new StringSerializer()));
assertThat(resp.getContentAsString()).isEqualTo("hello tempo");
}
示例4: invokeLambdaFunction_testFunction2_method2
import org.reflections.ReflectionUtils; //導入依賴的package包/類
@Test
public void invokeLambdaFunction_testFunction2_method2() throws Exception {
MockHttpServletRequest req = new MockHttpServletRequest();
req.setContent("tempo".getBytes());
MockHttpServletResponse resp = new MockHttpServletResponse();
lambdaLocalServlet.invokeLambdaFunction(req,
resp,
new LambdaFunction("/testPath3",
TestFunction2.class,
ReflectionUtils.getMethods(TestFunction2.class,
method -> method.getName().equals("method2")).stream()
.findFirst()
.get(),
new StringDeserializer(),
new StringSerializer()));
assertThat(resp.getContentAsString()).isEqualTo("hi tempo");
}
示例5: createClassViewDescriptor
import org.reflections.ReflectionUtils; //導入依賴的package包/類
private static ClassViewDescriptor createClassViewDescriptor(final Class<?> dataType)
{
@SuppressWarnings("unchecked")
final Set<Field> fields = ReflectionUtils.getAllFields(dataType, ReflectionUtils.withAnnotations(ViewColumn.class));
final ImmutableList<ClassViewColumnDescriptor> columns = fields.stream()
.map(field -> createClassViewColumnDescriptor(field))
.collect(ImmutableList.toImmutableList());
if (columns.isEmpty())
{
return ClassViewDescriptor.EMPTY;
}
return ClassViewDescriptor.builder()
// .className(dataType.getName())
.columns(columns)
.build();
}
示例6: createWebuiProcessClassInfo
import org.reflections.ReflectionUtils; //導入依賴的package包/類
private static WebuiProcessClassInfo createWebuiProcessClassInfo(final Class<?> processClass) throws Exception
{
final ProcessClassInfo processClassInfo = ProcessClassInfo.of(processClass);
final WebuiProcess webuiProcessAnn = processClass.getAnnotation(WebuiProcess.class);
@SuppressWarnings("unchecked")
final Set<Method> lookupValuesProviderMethods = ReflectionUtils.getAllMethods(processClass, ReflectionUtils.withAnnotation(ProcessParamLookupValuesProvider.class));
final ImmutableMap<String, LookupDescriptorProvider> paramLookupValuesProviders = lookupValuesProviderMethods.stream()
.map(method -> createParamLookupValuesProvider(method))
.collect(GuavaCollectors.toImmutableMap());
//
// Check is there were no settings at all so we could return our NULL instance
if (ProcessClassInfo.isNull(processClassInfo)
&& paramLookupValuesProviders.isEmpty())
{
return NULL;
}
return new WebuiProcessClassInfo(processClassInfo, webuiProcessAnn, paramLookupValuesProviders);
}
示例7: createFromClass
import org.reflections.ReflectionUtils; //導入依賴的package包/類
private static final ViewActionDescriptorsList createFromClass(@NonNull final Class<?> clazz)
{
final ActionIdGenerator actionIdGenerator = new ActionIdGenerator();
@SuppressWarnings("unchecked")
final Set<Method> viewActionMethods = ReflectionUtils.getAllMethods(clazz, ReflectionUtils.withAnnotation(ViewAction.class));
final List<ViewActionDescriptor> viewActions = viewActionMethods.stream()
.map(viewActionMethod -> {
try
{
return createViewActionDescriptor(actionIdGenerator.getActionId(viewActionMethod), viewActionMethod);
}
catch (final Throwable ex)
{
logger.warn("Failed creating view action descriptor for {}. Ignored", viewActionMethod, ex);
return null;
}
})
.filter(actionDescriptor -> actionDescriptor != null)
.collect(Collectors.toList());
return ViewActionDescriptorsList.of(viewActions);
}
示例8: invokableCopy
import org.reflections.ReflectionUtils; //導入依賴的package包/類
/**
* Creates a copy of this Rule with a new instance of the generated rule class if present.
*
* This prevents sharing instances across threads, which is not supported for performance reasons.
* Otherwise the generated code would need to be thread safe, adding to the runtime overhead.
* Instead we buy speed by spending more memory.
*
* @param functionRegistry the registered functions of the system
* @return a copy of this rule with a new instance of its generated code
*/
public Rule invokableCopy(FunctionRegistry functionRegistry) {
final Builder builder = toBuilder();
final Class<? extends GeneratedRule> ruleClass = generatedRuleClass();
if (ruleClass != null) {
try {
//noinspection unchecked
final Set<Constructor> constructors = ReflectionUtils.getConstructors(ruleClass);
final Constructor onlyElement = Iterables.getOnlyElement(constructors);
final GeneratedRule instance = (GeneratedRule) onlyElement.newInstance(functionRegistry);
builder.generatedRule(instance);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
LOG.warn("Unable to generate code for rule {}: {}", id(), e);
}
}
return builder.build();
}
示例9: scan
import org.reflections.ReflectionUtils; //導入依賴的package包/類
Set<Class<? extends T>> scan(Class<? extends T> aClass) {
Configuration configuration = ConfigurationBuilder.build((Object[]) packages).addClassLoaders(classLoaders)
.addScanners(new AssignableScanner(aClass));
Reflections reflections = new Reflections(configuration);
Predicate<Class<? extends T>> classPredicate = klass ->
Modifier.isPublic(klass.getModifiers()) &&
(!klass.isMemberClass() || (klass.isMemberClass() && Modifier
.isStatic(klass.getModifiers()))) &&
!Modifier.isInterface(klass.getModifiers()) &&
!Modifier.isAbstract(klass.getModifiers());
HashSet<Class<? extends T>> subtypes = Sets.newHashSet(
ReflectionUtils.forNames(
reflections.getStore()
.getAll(AssignableScanner.class.getSimpleName(),
Collections.singletonList(aClass.getName())), classLoaders));
return subtypes.stream().filter(classPredicate).collect(Collectors.toSet());
}
示例10: resolveQueryParams
import org.reflections.ReflectionUtils; //導入依賴的package包/類
@SneakyThrows
private WebTarget resolveQueryParams(WebTarget target, SchemaLink link, String method) {
UriTemplate uriTemplate = link.getHref();
if (method.equalsIgnoreCase("get") && requestObject != null) {
List<String> vars = uriTemplate.getTemplateVariables();
Set<Field> matchingFields = ReflectionUtils.getAllFields(requestObject.getClass(),
f -> !vars.contains(f.getName()));
for (Field field : matchingFields) {
field.setAccessible(true);
if (field.get(requestObject) != null) {
if (Collection.class.isAssignableFrom(field.getType())) {
Collection<?> value = (Collection<?>) field.get(requestObject);
String[] values = value.stream().map(Object::toString).collect(Collectors.toList())
.toArray(new String[0]);
target = target.queryParam(field.getName(), values);
} else {
target = target.queryParam(field.getName(), field.get(requestObject).toString());
}
}
}
}
return target;
}
示例11: getFieldDefinition
import org.reflections.ReflectionUtils; //導入依賴的package包/類
public GraphQLFieldDefinition getFieldDefinition(DfsContext dfsContext, Class<?> implClass, Field field) {
GraphQLFieldDefinition graphQLFieldDefinition = null;
ResolvableTypeAccessor resolvableTypeAccessor =
ResolvableTypeAccessor.forField(field, implClass);
if (resolvableTypeAccessor.isNotIgnorable()) {
GraphQLOutputType graphQLOutputType = (GraphQLOutputType) createGraphQLFieldType(dfsContext, resolvableTypeAccessor, true);
GraphQLFieldDefinition.Builder graphQLFieldDefinitionBuilder = GraphQLFieldDefinition.newFieldDefinition()
.name(resolvableTypeAccessor.getName())
.type(graphQLOutputType)
.deprecate(resolvableTypeAccessor.getGraphQLDeprecationReason())
.description(resolvableTypeAccessor.getDescription());
boolean isConstant = Modifier.isFinal(field.getModifiers()) && Modifier.isStatic(field.getModifiers());
if (isConstant) {
graphQLFieldDefinitionBuilder.staticValue(org.springframework.util.ReflectionUtils.getField(field, null));
}
graphQLFieldDefinition = graphQLFieldDefinitionBuilder.build();
addToFieldDefinitionResolverMap(dfsContext, graphQLFieldDefinition, resolvableTypeAccessor.getGraphQLComplexitySpelExpression());
}
return graphQLFieldDefinition;
}
示例12: invokeMethodByName
import org.reflections.ReflectionUtils; //導入依賴的package包/類
public Object invokeMethodByName(DfsContext dfsContext, Class<?> implClass, String methodName, Object... args) {
Object defaultValue = null;
if (StringUtils.hasText(methodName)) {
Object object = null;
if (getGraphQLSchemaBeanFactory().containsBean(implClass))
object = getGraphQLSchemaBeanFactory().getBeanByType(implClass);
Method defaultValueProviderMethod = args == null ?
org.springframework.util.ReflectionUtils.findMethod(implClass, methodName) :
org.springframework.util.ReflectionUtils.findMethod(implClass, methodName, getArgumentClasses(args));
if (defaultValueProviderMethod != null) {
defaultValue = org.springframework.util.ReflectionUtils.invokeMethod(defaultValueProviderMethod, object, args);
}
}
return defaultValue;
}
示例13: scanAndBind
import org.reflections.ReflectionUtils; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public Set<FlagField<?>> scanAndBind() {
Set<FlagField<?>> fields = new HashSet<>();
for (Object obj : objectsToScan) {
ReflectionUtils.getAllFields(
obj.getClass(),
ReflectionUtils.withTypeAssignableTo(Flag.class),
ReflectionUtils.withAnnotation(FlagInfo.class),
ReflectionUtils.withModifier(Modifier.FINAL),
not(ReflectionUtils.withModifier(Modifier.STATIC)))
.stream()
.map(f -> boundFlagField(f, obj))
.forEach(fields::add);
}
return fields;
}
示例14: lookingForConstructor
import org.reflections.ReflectionUtils; //導入依賴的package包/類
private Constructor<? extends Resource> lookingForConstructor(Class<? extends Resource> resourceClass) {
LOGGER.debug("Looking for a constructor to inject resource configuration");
Constructor <? extends Resource> constructor = null;
Set<Constructor> resourceConstructors =
ReflectionUtils.getConstructors(resourceClass,
withModifier(Modifier.PUBLIC),
withParametersAssignableFrom(ResourceConfiguration.class),
withParametersCount(1));
if (resourceConstructors.isEmpty()) {
LOGGER.debug("No configuration can be injected for {} because there is no valid constructor. " +
"Using default empty constructor.", resourceClass.getName());
try {
constructor = resourceClass.getConstructor();
} catch (NoSuchMethodException nsme) {
LOGGER.error("Unable to find default empty constructor for {}", resourceClass.getName(), nsme);
}
} else if (resourceConstructors.size() == 1) {
constructor = resourceConstructors.iterator().next();
} else {
LOGGER.info("Too much constructors to instantiate resource {}", resourceClass.getName());
}
return constructor;
}
示例15: findDefinedColumnNames
import org.reflections.ReflectionUtils; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private final Set<String> findDefinedColumnNames()
{
//
// Collect all columnnames
final ImmutableSet.Builder<String> columnNamesBuilder = ImmutableSet.builder();
ReflectionUtils.getAllFields(modelClass, new Predicate<Field>()
{
@Override
public boolean apply(final Field field)
{
final String fieldName = field.getName();
if (fieldName.startsWith("COLUMNNAME_"))
{
final String columnName = fieldName.substring("COLUMNNAME_".length());
columnNamesBuilder.add(columnName);
}
return false;
}
});
return columnNamesBuilder.build();
}