java.lang.reflect.Method.getModifiers()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(267)

本文整理了Java中java.lang.reflect.Method.getModifiers()方法的一些代码示例,展示了Method.getModifiers()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Method.getModifiers()方法的具体详情如下:
包路径:java.lang.reflect.Method
类名称:Method
方法名:getModifiers

Method.getModifiers介绍

[英]Returns the Java language modifiers for the method represented by this Method object, as an integer. The Modifier class should be used to decode the modifiers.
[中]

代码示例

代码示例来源: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: spring-projects/spring-framework

public static boolean isCandidateWriteMethod(Method method) {
  String methodName = method.getName();
  Class<?>[] parameterTypes = method.getParameterTypes();
  int nParams = parameterTypes.length;
  return (methodName.length() > 3 && methodName.startsWith("set") && Modifier.isPublic(method.getModifiers()) &&
      (!void.class.isAssignableFrom(method.getReturnType()) || Modifier.isStatic(method.getModifiers())) &&
      (nParams == 1 || (nParams == 2 && int.class == parameterTypes[0])));
}

代码示例来源:origin: spring-projects/spring-framework

public Object run() throws Exception {
    Method[] methods = Object.class.getDeclaredMethods();
    for (Method method : methods) {
      if ("finalize".equals(method.getName())
          || (method.getModifiers() & (Modifier.FINAL | Modifier.STATIC)) > 0) {
        continue;
      }
      OBJECT_METHODS.add(method);
    }
    return null;
  }
});

代码示例来源:origin: apache/incubator-dubbo

public static boolean isBeanPropertyWriteMethod(Method method) {
  return method != null
      && Modifier.isPublic(method.getModifiers())
      && !Modifier.isStatic(method.getModifiers())
      && method.getDeclaringClass() != Object.class
      && method.getParameterTypes().length == 1
      && method.getName().startsWith("set")
      && method.getName().length() > 3;
}

代码示例来源:origin: apache/incubator-dubbo

public static boolean isBeanPropertyWriteMethod(Method method) {
  return method != null
      && Modifier.isPublic(method.getModifiers())
      && !Modifier.isStatic(method.getModifiers())
      && method.getDeclaringClass() != Object.class
      && method.getParameterTypes().length == 1
      && method.getName().startsWith("set")
      && method.getName().length() > 3;
}

代码示例来源:origin: apache/incubator-dubbo

public static boolean isBeanPropertyReadMethod(Method method) {
  return method != null
      && Modifier.isPublic(method.getModifiers())
      && !Modifier.isStatic(method.getModifiers())
      && method.getReturnType() != void.class
      && method.getDeclaringClass() != Object.class
      && method.getParameterTypes().length == 0
      && ((method.getName().startsWith("get") && method.getName().length() > 3)
      || (method.getName().startsWith("is") && method.getName().length() > 2));
}

代码示例来源:origin: apache/incubator-dubbo

public static boolean isBeanPropertyReadMethod(Method method) {
  return method != null
      && Modifier.isPublic(method.getModifiers())
      && !Modifier.isStatic(method.getModifiers())
      && method.getReturnType() != void.class
      && method.getDeclaringClass() != Object.class
      && method.getParameterTypes().length == 0
      && ((method.getName().startsWith("get") && method.getName().length() > 3)
      || (method.getName().startsWith("is") && method.getName().length() > 2));
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Check to see if the {@code Method} is both public and declared in
 * one of the configured interfaces.
 * @param method the {@code Method} to check.
 * @param beanKey the key associated with the MBean in the beans map
 * @return {@code true} if the {@code Method} is declared in one of the
 * configured interfaces and is public, otherwise {@code false}.
 */
private boolean isPublicInInterface(Method method, String beanKey) {
  return ((method.getModifiers() & Modifier.PUBLIC) > 0) && isDeclaredInInterface(method, beanKey);
}

代码示例来源:origin: spring-projects/spring-framework

public LifecycleElement(Method method) {
  if (method.getParameterCount() != 0) {
    throw new IllegalStateException("Lifecycle method annotation requires a no-arg method: " + method);
  }
  this.method = method;
  this.identifier = (Modifier.isPrivate(method.getModifiers()) ?
      ClassUtils.getQualifiedMethodName(method) : method.getName());
}

代码示例来源:origin: apache/incubator-dubbo

public static boolean isGetter(Method method) {
  String name = method.getName();
  return (name.startsWith("get") || name.startsWith("is"))
      && !"get".equals(name) && !"is".equals(name)
      && !"getClass".equals(name) && !"getObject".equals(name)
      && Modifier.isPublic(method.getModifiers())
      && method.getParameterTypes().length == 0
      && isPrimitive(method.getReturnType());
}

代码示例来源:origin: apache/incubator-dubbo

public static boolean isSetter(Method method) {
  return method.getName().startsWith("set")
      && !"set".equals(method.getName())
      && Modifier.isPublic(method.getModifiers())
      && method.getParameterCount() == 1
      && isPrimitive(method.getParameterTypes()[0]);
}

代码示例来源:origin: spring-projects/spring-framework

@Nullable
private static Method determineToMethod(Class<?> targetClass, Class<?> sourceClass) {
  if (String.class == targetClass || String.class == sourceClass) {
    // Do not accept a toString() method or any to methods on String itself
    return null;
  }
  Method method = ClassUtils.getMethodIfAvailable(sourceClass, "to" + targetClass.getSimpleName());
  return (method != null && !Modifier.isStatic(method.getModifiers()) &&
      ClassUtils.isAssignable(targetClass, method.getReturnType()) ? method : null);
}

代码示例来源: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

@Override
  public boolean matches(Method m) {
    return Modifier.isProtected(m.getModifiers());
  }
});

代码示例来源:origin: square/retrofit

private void eagerlyValidateMethods(Class<?> service) {
 Platform platform = Platform.get();
 for (Method method : service.getDeclaredMethods()) {
  if (!platform.isDefaultMethod(method) && !Modifier.isStatic(method.getModifiers())) {
   loadServiceMethod(method);
  }
 }
}

代码示例来源: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

static ImmutableList<Method> getTestMethods(Class<?> testClass) {
  List<Method> result = Lists.newArrayList();
  for (Method method : testClass.getDeclaredMethods()) {
   if (Modifier.isPublic(method.getModifiers())
     && method.getReturnType() == void.class
     && method.getParameterTypes().length == 0
     && method.getName().startsWith("test")) {
    result.add(method);
   }
  }
  return ImmutableList.copyOf(result);
 }
}

代码示例来源:origin: google/guava

private static Set<MethodSignature> getPublicStaticMethods(Class<?> clazz) {
 Set<MethodSignature> publicStaticMethods = newHashSet();
 for (Method method : clazz.getDeclaredMethods()) {
  int modifiers = method.getModifiers();
  if (isPublic(modifiers) && isStatic(modifiers)) {
   publicStaticMethods.add(new MethodSignature(method));
  }
 }
 return publicStaticMethods;
}

代码示例来源: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: google/guava

public static TestSuite suite() {
 // we create a test suite containing a test for every AbstractFutureTest test method and we
 // set it as the name of the test.  Then in runTest we can reflectively load and invoke the
 // corresponding method on AbstractFutureTest in the correct classloader.
 TestSuite suite = new TestSuite(AbstractFutureFallbackAtomicHelperTest.class.getName());
 for (Method method : AbstractFutureTest.class.getDeclaredMethods()) {
  if (Modifier.isPublic(method.getModifiers()) && method.getName().startsWith("test")) {
   suite.addTest(
     TestSuite.createTest(AbstractFutureFallbackAtomicHelperTest.class, method.getName()));
  }
 }
 return suite;
}

相关文章

微信公众号

最新文章

更多