本文整理了Java中java.lang.reflect.Method.getDeclaringClass()
方法的一些代码示例,展示了Method.getDeclaringClass()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Method.getDeclaringClass()
方法的具体详情如下:
包路径:java.lang.reflect.Method
类名称:Method
方法名:getDeclaringClass
[英]Returns the Class object representing the class or interface that declares the method represented by this Method object.
[中]
代码示例来源:origin: spring-projects/spring-framework
@Override
protected boolean isCandidateForProperty(Method method, Class<?> targetClass) {
Class<?> clazz = method.getDeclaringClass();
return (clazz != Object.class && clazz != Class.class && !ClassLoader.class.isAssignableFrom(targetClass));
}
代码示例来源:origin: square/retrofit
@Override public String toString() {
return String.format("%s.%s() %s",
method.getDeclaringClass().getName(), method.getName(), arguments);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected boolean isCandidateForInvocation(Method method, Class<?> targetClass) {
if (Modifier.isStatic(method.getModifiers())) {
return false;
}
Class<?> clazz = method.getDeclaringClass();
return (clazz != Object.class && clazz != Class.class && !ClassLoader.class.isAssignableFrom(targetClass));
}
代码示例来源:origin: square/retrofit
static RuntimeException methodError(Method method, @Nullable Throwable cause, String message,
Object... args) {
message = String.format(message, args);
return new IllegalArgumentException(message
+ "\n for method "
+ method.getDeclaringClass().getSimpleName()
+ "."
+ method.getName(), cause);
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
protected CacheDefaults getCacheDefaults(Method method, @Nullable Class<?> targetType) {
CacheDefaults annotation = method.getDeclaringClass().getAnnotation(CacheDefaults.class);
if (annotation != null) {
return annotation;
}
return (targetType != null ? targetType.getAnnotation(CacheDefaults.class) : null);
}
代码示例来源:origin: spring-projects/spring-framework
public static boolean isSetBeanFactory(Method candidateMethod) {
return (candidateMethod.getName().equals("setBeanFactory") &&
candidateMethod.getParameterCount() == 1 &&
BeanFactory.class == candidateMethod.getParameterTypes()[0] &&
BeanFactoryAware.class.isAssignableFrom(candidateMethod.getDeclaringClass()));
}
}
代码示例来源:origin: spring-projects/spring-framework
public CglibMethodInvocation(Object proxy, @Nullable Object target, Method method,
Object[] arguments, @Nullable Class<?> targetClass,
List<Object> interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) {
super(proxy, target, method, arguments, targetClass, interceptorsAndDynamicMethodMatchers);
// Only use method proxy for public methods not derived from java.lang.Object
this.methodProxy = (Modifier.isPublic(method.getModifiers()) &&
method.getDeclaringClass() != Object.class && !AopUtils.isEqualsMethod(method) &&
!AopUtils.isHashCodeMethod(method) && !AopUtils.isToStringMethod(method) ?
methodProxy : null);
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
private SendTo getSendTo(Method specificMethod) {
SendTo ann = AnnotatedElementUtils.findMergedAnnotation(specificMethod, SendTo.class);
if (ann == null) {
ann = AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), SendTo.class);
}
return ann;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public Collection<CacheOperation> parseCacheAnnotations(Method method) {
DefaultCacheConfig defaultConfig = new DefaultCacheConfig(method.getDeclaringClass());
return parseCacheAnnotations(defaultConfig, method);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
Method method = this.method;
Assert.state(method != null, "No method handle");
String classDesc = method.getDeclaringClass().getName().replace('.', '/');
generateCodeForArguments(mv, cf, method, this.children);
mv.visitMethodInsn(INVOKESTATIC, classDesc, method.getName(),
CodeFlow.createSignatureDescriptor(method), false);
cf.pushDescriptor(this.exitTypeDescriptor);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean isMatch(Method candidateMethod) {
return (candidateMethod.getDeclaringClass() != Object.class &&
!BeanFactoryAwareMethodInterceptor.isSetBeanFactory(candidateMethod) &&
BeanAnnotationHelper.isBeanAnnotated(candidateMethod));
}
代码示例来源:origin: spring-projects/spring-framework
private Method getGetterFromSetter(Method setter) {
String getterName = setter.getName().replaceFirst("set", "get");
try {
return setter.getDeclaringClass().getMethod(getterName);
}
catch (NoSuchMethodException ex) {
// must be write only
return null;
}
}
代码示例来源:origin: google/guava
/**
* Verifies that {@code method} produces a {@link NullPointerException} or {@link
* UnsupportedOperationException} when the parameter in position {@code paramIndex} is null. If
* this parameter is marked nullable, this method does nothing.
*
* @param instance the instance to invoke {@code method} on, or null if {@code method} is static
*/
public void testMethodParameter(
@Nullable final Object instance, final Method method, int paramIndex) {
method.setAccessible(true);
testParameter(instance, invokable(instance, method), paramIndex, method.getDeclaringClass());
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
if (mi.getMethod().getDeclaringClass().equals(AddedGlobalInterface.class)) {
return new Integer(-1);
}
return mi.proceed();
}
}
代码示例来源:origin: square/retrofit
@Override public Object invoke(Object proxy, Method method, @Nullable Object[] args)
throws Throwable {
// If the method is a method from Object then defer to normal invocation.
if (method.getDeclaringClass() == Object.class) {
return method.invoke(this, args);
}
if (platform.isDefaultMethod(method)) {
return platform.invokeDefaultMethod(method, service, proxy, args);
}
return loadServiceMethod(method).invoke(args != null ? args : emptyArgs);
}
});
代码示例来源:origin: ReactiveX/RxJava
static void scan(Class<?> clazz) {
for (Method m : clazz.getMethods()) {
if (m.getDeclaringClass() == clazz) {
if ((m.getModifiers() & Modifier.STATIC) == 0) {
if ((m.getModifiers() & (Modifier.PUBLIC | Modifier.FINAL)) == Modifier.PUBLIC) {
fail("Not final: " + m);
}
}
}
}
}
代码示例来源:origin: google/guava
private static void doTestMocking(RateLimiter mock) throws Exception {
for (Method method : RateLimiter.class.getMethods()) {
if (!isStatic(method.getModifiers())
&& !NOT_WORKING_ON_MOCKS.contains(method.getName())
&& !method.getDeclaringClass().equals(Object.class)) {
method.invoke(mock, arbitraryParameters(method));
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void assertions(MethodInvocation invocation) {
assertTrue(invocation.getThis() == this);
assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(),
ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass()));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void assertions(MethodInvocation invocation) {
assertSame(this, invocation.getThis());
assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(),
ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass()));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void assertions(MethodInvocation invocation) {
assertEquals(this, invocation.getThis());
assertEquals("Invocation should be on ITestBean: " + invocation.getMethod(),
ITestBean.class, invocation.getMethod().getDeclaringClass());
}
};
内容来源于网络,如有侵权,请联系作者删除!