本文整理匯總了Java中org.reflections.ReflectionUtils.getAllMethods方法的典型用法代碼示例。如果您正苦於以下問題:Java ReflectionUtils.getAllMethods方法的具體用法?Java ReflectionUtils.getAllMethods怎麽用?Java ReflectionUtils.getAllMethods使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.reflections.ReflectionUtils
的用法示例。
在下文中一共展示了ReflectionUtils.getAllMethods方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
示例2: 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);
}
示例3: 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);
}
示例4: JavaAssistInterceptorInstance
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
public JavaAssistInterceptorInstance(final Class<? extends Annotation> annotationClass, final Object interceptorImpl)
{
super();
Check.assumeNotNull(annotationClass, "annotationClass not null");
this.annotationClass = annotationClass;
Check.assumeNotNull(interceptorImpl, "interceptorImpl not null");
this.interceptorImpl = interceptorImpl;
final Class<? extends Object> interceptorImplClass = interceptorImpl.getClass();
@SuppressWarnings("unchecked")
final Set<Method> aroundInvokeMethods = ReflectionUtils.getAllMethods(interceptorImplClass, ReflectionUtils.withAnnotation(AroundInvoke.class));
Check.errorIf(aroundInvokeMethods.size() != 1, "Class {} needs to have exactly one method annotated with @AroundInvoke. It has:{}", interceptorImpl, aroundInvokeMethods);
this.aroundInvokeMethod = aroundInvokeMethods.iterator().next();
Check.assumeNotNull(aroundInvokeMethod, "aroundInvokeMethod not null for {}", interceptorImplClass);
}
示例5: getAddMethod
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
private Method getAddMethod(Class clazz, TypeToken typeToken, Field field, String javaFieldNameUpperCased, Method getMethod) {
Method addMethod = null;
if (Collection.class.isAssignableFrom(getMethod.getReturnType())) {
Type[] typeArguments = ((ParameterizedType) getMethod.getGenericReturnType()).getActualTypeArguments();
if (typeArguments.length == 1) {
TypeToken singularParameter = typeToken.resolveType(typeArguments[0]);
//TODO: does this work or should we use the typeArguments[0].getSomething?
String addMethodName = "add" + toSingular(javaFieldNameUpperCased);
addMethod = getMethod(clazz, addMethodName, singularParameter.getRawType());
if (addMethod == null) {
//Due to generics, this does not always work
Set<Method> allAddMethods = ReflectionUtils.getAllMethods(clazz, ReflectionUtils.withName(addMethodName));
if (allAddMethods.size() == 1) {
addMethod = allAddMethods.iterator().next();
} else {
logger.warn("strange number of add methods for field {} on class {}", field.getName(), clazz.getSimpleName());
}
}
}
}
return addMethod;
}
示例6: getCompleteness
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
/**
* Obtain the "completeness" (i.e. "empty", "id and type", "it, type and label", "id only" or "complex") of
* a IIIF resource. Can be useful for determining how to serialize the resource, e.g. often resources with only
* an id are serialized as a string.
*
* @param res The IIIF resource to check the completeness of
* @param type The type of the IIIF resource
* @return The completeness
*/
public static Completeness getCompleteness(Object res, Class<?> type) {
Set<Method> getters = ReflectionUtils.getAllMethods(
type,
ReflectionUtils.withModifier(Modifier.PUBLIC),
ReflectionUtils.withPrefix("get"));
Set<String> gettersWithValues = getters.stream()
.filter(g -> g.getAnnotation(JsonIgnore.class) == null) // Only JSON-serializable fields
.filter(g -> returnsValue(g, res))
.map(Method::getName)
.collect(Collectors.toSet());
boolean hasOnlyTypeAndId = (
gettersWithValues.size() == 2 &&
Stream.of("getType", "getIdentifier").allMatch(gettersWithValues::contains));
if (gettersWithValues.isEmpty()) {
return Completeness.EMPTY;
} else if (containsOnly(gettersWithValues, "getType", "getIdentifier")) {
return Completeness.ID_AND_TYPE;
} else if (containsOnly(gettersWithValues, "getType", "getIdentifier", "getLabels")) {
return Completeness.ID_AND_TYPE_AND_LABEL;
} else if (containsOnly(gettersWithValues, "getIdentifier")) {
return Completeness.ID_ONLY;
} else {
return Completeness.COMPLEX;
}
}
示例7: CCOWHandler
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
public CCOWHandler(final ContextManagementRegistryServlet cmrs, final ContextManagerServlet cms, final ContextDataServlet cds) {
this.cmrs = cmrs;
this.cms = cms;
this.cds = cds;
// Reflections helper = new Reflections("ccow");
// Set<Class<?>> servlets = helper.getTypesAnnotatedWith(Path.class);
servletsToObjects = Maps.newHashMap();
servletsToObjects.put(cmrs.getClass(), cmrs);
servletsToObjects.put(cms.getClass(), cms);
servletsToObjects.put(cds.getClass(), cds);
stringToClass = FluentIterable.from(servletsToObjects.keySet()).uniqueIndex(new Function<Class<?>, String>() {
@Override
public String apply(final Class<?> input) {
return input.getAnnotation(Path.class).value();
}
});
classToMethods = Maps.newHashMap();
for (final Class<?> s : servletsToObjects.keySet()) {
final Set<Method> ms = ReflectionUtils.getAllMethods(s, ReflectionUtils.withAnnotation(Path.class));
for (final Method m : ms) {
final Set<Method> c = classToMethods.get(m.getDeclaringClass());
if (c == null)
classToMethods.put(m.getDeclaringClass(), Sets.newHashSet(m));
else
c.add(m);
}
}
}
示例8: isRunOutOfTrx
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
private static final boolean isRunOutOfTrx(final Class<?> processClass, final Class<?> returnType, final String methodName)
{
// Get all methods with given format,
// from given processClass and it's super classes,
// ordered by methods of processClass first, methods from super classes after
@SuppressWarnings("unchecked")
final Set<Method> methods = ReflectionUtils.getAllMethods(processClass, ReflectionUtils.withName(methodName), ReflectionUtils.withParameters(), ReflectionUtils.withReturnType(returnType));
// No methods of given format were found.
// This could be OK in case our process is NOT extending JavaProcess but the IProcess interface.
if (methods.isEmpty())
{
logger.info("Method {} with return type {} was not found in {} or in its inerited types. Ignored.", methodName, returnType, processClass);
// throw new IllegalStateException("Method " + methodName + " with return type " + returnType + " was not found in " + processClass + " or in its inerited types");
return false;
}
// Iterate all methods and return on first RunOutOfTrx annotation found.
for (final Method method : methods)
{
final RunOutOfTrx runOutOfTrxAnnotation = method.getAnnotation(RunOutOfTrx.class);
if (runOutOfTrxAnnotation != null)
{
return true;
}
}
// Fallback: no RunOutOfTrx annotation found
return false;
}
示例9: getEndpointResources
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private Map<String, EndpointResource> getEndpointResources(Set<Class<?>> resources) {
Map<String, EndpointResource> endpointResources = new HashMap<String, EndpointResource>();
for (Class<?> type : resources) {
Set<Method> resourceMethods = ReflectionUtils.getAllMethods(type,
ReflectionUtils.withAnnotation(ResourceMethod.class));
if (resourceMethods.isEmpty()) {
getLog().warn(
"No methods annotated with @Resource found in type: "
+ type.getName());
continue;
}
for (Method method : resourceMethods) {
Resource methodResource = method.getAnnotation(Resource.class);
String resourceName = type.getAnnotationsByType(Resource.class)[0].name();
if(methodResource != null) {
resourceName = resourceName + "/" + methodResource.name();
}
EndpointResourceMethod endpointMethod = createMethodResource(method, resourceName);
EndpointResource endpointResource = endpointResources.get(resourceName);
if (endpointResource == null) {
endpointResource = new EndpointResource();
endpointResource.setName(resourceName);
endpointResource.setMethods(new ArrayList<EndpointResourceMethod>());
endpointResources.put(resourceName, endpointResource);
}
endpointResource.getMethods().add(endpointMethod);
}
}
return endpointResources;
}
示例10: testGetInstanceGetAndPost
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
/**
* Test method for
* {@link com.strandls.alchemy.rest.client.AlchemyRestClientFactory#getInstance(java.lang.Class, java.lang.String, javax.ws.rs.client.Client)}
* .
*
* Test get and post methods with a combination of parameter types (query,
* path, header, cookie, matrix)
*
* @throws Exception
*/
@Test
public void testGetInstanceGetAndPost() throws Exception {
final TestWebserviceWithPath service =
clientFactory.getInstance(TestWebserviceWithPath.class);
final Random r = new Random();
final int[] args = new int[] { r.nextInt(), r.nextInt(), r.nextInt() };
@SuppressWarnings("unchecked")
final Set<Method> methods =
ReflectionUtils.getAllMethods(TestWebserviceWithPath.class,
new Predicate<Method>() {
@Override
public boolean apply(final Method input) {
return Modifier.isPublic(input.getModifiers());
}
});
for (final Method method : methods) {
System.out.println("Invoking : " + method);
if (method.getParameterTypes().length == 3) {
assertArrayEquals("Invocation failed on " + method, args,
(int[]) method.invoke(service, args[0], args[1], args[2]));
} else if (method.getParameterTypes().length == 0) {
method.invoke(service);
} else {
assertArrayEquals("Invocation failed on " + method, args,
(int[]) method.invoke(service, args));
}
System.out.println("Done invoking : " + method);
}
}
示例11: testGetInstanceStub
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
/**
* Test method for
* {@link com.strandls.alchemy.rest.client.AlchemyRestClientFactory#getInstance(java.lang.Class, java.lang.String, javax.ws.rs.client.Client)}
* .
*
* Test get and post methods with a combination of parameter types (query,
* path, header, cookie, matrix)
*
* @throws Exception
*/
@Test
public void testGetInstanceStub() throws Exception {
final TestWebserviceWithPathStub service =
clientFactory.getInstance(TestWebserviceWithPathStub.class);
final Random r = new Random();
final int[] args = new int[] { r.nextInt(), r.nextInt(), r.nextInt() };
@SuppressWarnings("unchecked")
final Set<Method> methods =
ReflectionUtils.getAllMethods(TestWebserviceWithPathStub.class,
new Predicate<Method>() {
@Override
public boolean apply(final Method input) {
return Modifier.isPublic(input.getModifiers());
}
});
for (final Method method : methods) {
System.out.println("Invoking : " + method);
if (method.getParameterTypes().length == 3) {
assertArrayEquals("Invocation failed on " + method, args,
(int[]) method.invoke(service, args[0], args[1], args[2]));
} else {
assertArrayEquals("Invocation failed on " + method, args,
(int[]) method.invoke(service, args));
}
System.out.println("Done invoking : " + method);
}
}
示例12: getMappedMethods
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
public static final Map<Method, TableCellMapping> getMappedMethods(Class<?> clazz, final Class<?> group) {
Set<Method> cellMappingMethods = ReflectionUtils.getAllMethods(clazz, ReflectionUtils.withAnnotation(TableCellMapping.class));
cellMappingMethods.addAll(ReflectionUtils.getAllMethods(clazz, ReflectionUtils.withAnnotation(TableCellMappings.class)));
Multimap<Method, Optional<TableCellMapping>> tableCellMappingByMethod = FluentIterable.from(cellMappingMethods)
.index(new Function<Method, Optional<TableCellMapping>>() {
@Override
public Optional<TableCellMapping> apply(Method method) {
checkNotNull(method);
return Optional.fromNullable(method.getAnnotation(TableCellMapping.class))
.or(getFirstTableCellMapping(method.getAnnotation(TableCellMappings.class), group));
}
})
.inverse();
tableCellMappingByMethod = filterEntries(tableCellMappingByMethod, new Predicate<Entry<Method, Optional<TableCellMapping>>>() {
@Override
public boolean apply(Entry<Method, Optional<TableCellMapping>> entry) {
checkNotNull(entry);
return entry.getValue().isPresent()
&& any(Lists.newArrayList(entry.getValue().get().groups()), assignableTo(group));
}
});
Multimap<Method, TableCellMapping> methodByTableCellMapping = transformValues(tableCellMappingByMethod, new Function<Optional<TableCellMapping>, TableCellMapping>() {
@Override
public TableCellMapping apply(Optional<TableCellMapping> tcmOptional) {
checkNotNull(tcmOptional);
return tcmOptional.get();
}
});
return Maps.transformValues(methodByTableCellMapping.asMap(), new Function<Collection<TableCellMapping>, TableCellMapping>() {
@Override
public TableCellMapping apply(Collection<TableCellMapping> tcms) {
checkNotNull(tcms);
return Iterables.getFirst(tcms, null);
}
});
}
示例13: execute
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage(basePackage)).setScanners(
new SubTypesScanner()));
Set<Class<?>> lambdaTypes = reflections
.getTypesAnnotatedWith(Lambda.class);
AWSLambdaClient lambdaClient = new AWSLambdaClient();
for (Class<?> type : lambdaTypes) {
Set<Method> lambdaHandlers = ReflectionUtils.getAllMethods(type,
ReflectionUtils.withAnnotation(LambdaHandler.class));
if (lambdaHandlers.isEmpty()) {
getLog().warn(
"No methods annotated with @LambdaHandler found in type: "
+ type.getName());
continue;
}
if (lambdaHandlers.size() > 1) {
getLog().warn(
"More than one method annotated with @LambdaHandler found in type: "
+ type.getName());
continue;
}
String handlerMethod = type.getName() + ":"
+ lambdaHandlers.iterator().next().getName();
Lambda lambdaData = type.getAnnotation(Lambda.class);
GetFunctionRequest getFunctionReq = new GetFunctionRequest();
GetFunctionResult getFunctionRes = lambdaClient
.getFunction(getFunctionReq);
if (getFunctionRes != null) {
if (needsConfigurationUpdate(getFunctionRes, lambdaData.name(),
handlerMethod)) {
updateLambdaConfiguration(lambdaClient, lambdaData.name(),
lambdaData.description(), handlerMethod);
} else if (needsCodeUpdate(getFunctionRes)) {
updateLambdaCode(lambdaClient, lambdaData.name());
} else {
getLog().warn(
"Configuration and code is up to date, nothing to change.");
}
} else {
createLambda(lambdaClient, handlerMethod, lambdaData.name(),
lambdaData.description());
}
}
}
示例14: reload
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@Override
@SuppressWarnings("squid:S1166") // Exception caught and handled
public MrsPyramidMetadata reload() throws IOException
{
if (metadata == null)
{
return read();
}
if (dataProvider == null)
{
throw new IOException("DataProvider not set!");
}
String name = dataProvider.getResourceName();
if (name == null || name.length() == 0)
{
throw new IOException("Can not load metadata, resource name is empty!");
}
MrsPyramidMetadata copy = loadMetadata();
Set<Method> getters = ReflectionUtils.getAllMethods(MrsPyramidMetadata.class,
Predicates.<Method>and(
Predicates.<AnnotatedElement>not(ReflectionUtils.withAnnotation(JsonIgnore.class)),
ReflectionUtils.withModifier(Modifier.PUBLIC),
ReflectionUtils.withPrefix("get"),
ReflectionUtils.withParametersCount(0)));
Set<Method> setters = ReflectionUtils.getAllMethods(MrsPyramidMetadata.class,
Predicates.<Method>and(
Predicates.<AnnotatedElement>not(ReflectionUtils.withAnnotation(JsonIgnore.class)),
ReflectionUtils.withModifier(Modifier.PUBLIC),
ReflectionUtils.withPrefix("set"),
ReflectionUtils.withParametersCount(1)));
// System.out.println("getters");
// for (Method m: getters)
// {
// System.out.println(" " + m.getName());
// }
// System.out.println();
//
// System.out.println("setters");
// for (Method m: setters)
// {
// System.out.println(" " + m.getName());
// }
// System.out.println();
for (Method getter : getters)
{
String gettername = getter.getName();
String settername = gettername.replaceFirst("get", "set");
for (Method setter : setters)
{
if (setter.getName().equals(settername))
{
// System.out.println("found setter: " + setter.getName() + " for " + getter.getName() );
try
{
setter.invoke(metadata, getter.invoke(copy, new Object[]{}));
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignore)
{
}
break;
}
}
}
return metadata;
}
示例15: reload
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
/**
* Reload the metadata. Uses the existing object and sets all the parameters (getters/setters) to the
* new values. This allows anyone holding a reference to an existing metadata object to see the
* updated values without having to reload the metadata themselves.
*/
@SuppressWarnings({"unchecked", "squid:S1166"}) // Exception caught and handled
@Override
public MrsPyramidMetadata reload() throws IOException
{
if (metadata == null)
{
return read();
}
if (dataProvider == null)
{
throw new IOException("DataProvider not set!");
}
String name = dataProvider.getResourceName();
if (name == null || name.length() == 0)
{
throw new IOException("Can not load metadata, resource name is empty!");
}
MrsPyramidMetadata copy = loadMetadata();
Set<Method> getters = ReflectionUtils.getAllMethods(MrsPyramidMetadata.class,
Predicates.<Method>and(
Predicates.<AnnotatedElement>not(ReflectionUtils.withAnnotation(JsonIgnore.class)),
ReflectionUtils.withModifier(Modifier.PUBLIC),
ReflectionUtils.withPrefix("get"),
ReflectionUtils.withParametersCount(0)));
Set<Method> setters = ReflectionUtils.getAllMethods(MrsPyramidMetadata.class,
Predicates.<Method>and(
Predicates.<AnnotatedElement>not(ReflectionUtils.withAnnotation(JsonIgnore.class)),
ReflectionUtils.withModifier(Modifier.PUBLIC),
ReflectionUtils.withPrefix("set"),
ReflectionUtils.withParametersCount(1)));
// System.out.println("getters");
// for (Method m: getters)
// {
// System.out.println(" " + m.getName());
// }
// System.out.println();
//
// System.out.println("setters");
// for (Method m: setters)
// {
// System.out.println(" " + m.getName());
// }
// System.out.println();
for (Method getter : getters)
{
String gettername = getter.getName();
String settername = gettername.replaceFirst("get", "set");
for (Method setter : setters)
{
if (setter.getName().equals(settername))
{
// System.out.println("found setter: " + setter.getName() + " for " + getter.getName() );
try
{
setter.invoke(metadata, getter.invoke(copy, new Object[]{}));
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignore)
{
}
break;
}
}
}
return metadata;
}