本文整理汇总了Java中java.lang.reflect.Method.getModifiers方法的典型用法代码示例。如果您正苦于以下问题:Java Method.getModifiers方法的具体用法?Java Method.getModifiers怎么用?Java Method.getModifiers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Method
的用法示例。
在下文中一共展示了Method.getModifiers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findReadWriteObjectForSerialization
import java.lang.reflect.Method; //导入方法依赖的package包/类
private final MethodHandle findReadWriteObjectForSerialization(Class<?> cl,
String methodName,
Class<?> streamClass) {
if (!Serializable.class.isAssignableFrom(cl)) {
return null;
}
try {
Method meth = cl.getDeclaredMethod(methodName, streamClass);
int mods = meth.getModifiers();
if (meth.getReturnType() != Void.TYPE ||
Modifier.isStatic(mods) ||
!Modifier.isPrivate(mods)) {
return null;
}
meth.setAccessible(true);
return MethodHandles.lookup().unreflect(meth);
} catch (NoSuchMethodException ex) {
return null;
} catch (IllegalAccessException ex1) {
throw new InternalError("Error", ex1);
}
}
示例2: getPrivateMethod
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Returns non-static private method with given signature defined by given
* class, or null if none found. Access checks are disabled on the
* returned method (if any).
*/
private static Method getPrivateMethod(Class<?> cl, String name,
Class<?>[] argTypes,
Class<?> returnType)
{
try {
Method meth = cl.getDeclaredMethod(name, argTypes);
meth.setAccessible(true);
int mods = meth.getModifiers();
return ((meth.getReturnType() == returnType) &&
((mods & Modifier.STATIC) == 0) &&
((mods & Modifier.PRIVATE) != 0)) ? meth : null;
} catch (NoSuchMethodException ex) {
return null;
}
}
示例3: invoke
import java.lang.reflect.Method; //导入方法依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String name = method.getName();
LuaValue func = lobj.get(name);
if ( func.isnil() )
return null;
boolean isvarargs = ((method.getModifiers() & METHOD_MODIFIERS_VARARGS) != 0);
int n = args!=null? args.length: 0;
LuaValue[] v;
if ( isvarargs ) {
Object o = args[--n];
int m = Array.getLength( o );
v = new LuaValue[n+m];
for ( int i=0; i<n; i++ )
v[i] = CoerceJavaToLua.coerce(args[i]);
for ( int i=0; i<m; i++ )
v[i+n] = CoerceJavaToLua.coerce(Array.get(o,i));
} else {
v = new LuaValue[n];
for ( int i=0; i<n; i++ )
v[i] = CoerceJavaToLua.coerce(args[i]);
}
LuaValue result = func.invoke(v).arg1();
return CoerceLuaToJava.coerce(result, method.getReturnType());
}
示例4: luaTableTry
import java.lang.reflect.Method; //导入方法依赖的package包/类
private LuaMethod luaTableTry(String s){
try {
Method[] methods = c.getMethods();
ArrayList<Method> validMethods = new ArrayList<Method>();
for (Method method : methods) {
int modifiers = method.getModifiers();
if (Modifier.isStatic(modifiers) && method.getAnnotation(LuaExclude.class) == null
&& method.getName().equals(s)) {
validMethods.add(method);
}
}
if (validMethods.size() > 0)
return new LuaMethod(validMethods, c, s);
} catch (Exception ignored) {
}
}
示例5: isPublicStaticVoid
import java.lang.reflect.Method; //导入方法依赖的package包/类
private boolean isPublicStaticVoid( Method method )
{
// check modifiers: public static
int modifiers = method.getModifiers ();
if (!Modifier.isPublic (modifiers) || !Modifier.isStatic (modifiers)) {
logError( method.getName() + " is not public static" ) ;
return false ;
}
// check return type and exceptions
if (method.getExceptionTypes ().length != 0) {
logError( method.getName() + " declares exceptions" ) ;
return false ;
}
if (!method.getReturnType().equals (Void.TYPE)) {
logError( method.getName() + " does not have a void return type" ) ;
return false ;
}
return true ;
}
示例6: isReadMethod
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Returns {@code true} if the given method is a "getter" method (where
* "getter" method is a public method of the form getXXX or "boolean
* isXXX")
*/
static boolean isReadMethod(Method method) {
// ignore static methods
int modifiers = method.getModifiers();
if (Modifier.isStatic(modifiers))
return false;
String name = method.getName();
Class<?>[] paramTypes = method.getParameterTypes();
int paramCount = paramTypes.length;
if (paramCount == 0 && name.length() > 2) {
// boolean isXXX()
if (name.startsWith(IS_METHOD_PREFIX))
return (method.getReturnType() == boolean.class);
// getXXX()
if (name.length() > 3 && name.startsWith(GET_METHOD_PREFIX))
return (method.getReturnType() != void.class);
}
return false;
}
示例7: checkGetter
import java.lang.reflect.Method; //导入方法依赖的package包/类
private static boolean checkGetter(Method method) {
int modifiers = method.getModifiers();
if (Modifier.isStatic(modifiers)) {
return true;
}
if (Modifier.isNative(modifiers)) {
return true;
}
if (Modifier.isAbstract(modifiers)) {
return true;
}
if (method.getReturnType().equals(Void.TYPE)) {
return true;
}
if (method.getParameterTypes().length != 0) {
return true;
}
if (method.getReturnType() == ClassLoader.class) {
return true;
}
if (method.getName().equals("getClass")) {
return true;
}
return false;
}
示例8: filterMethods
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Filter all methods to ensure following conditions:
*
* <ul><li>Method name is @name</li>
*
* <li>Method is <tt>public<tt></li>
*
* <li>Method is not <tt>abstract</tt></li>.
*
* <li>Method does not have variable number of arguments</li>
*
* <li>Return type of method is @returnType</li>
*
* <li>All parameter fields are of type {@link String}, {@link Integer} or {@link Double}</li>
*
* <li>All parameters are annotated with {@link Param}</li> </ul>
*
* @param methods Array of methods to be filtered.
* @param seekedName Name of the methods we are looking for.
* @param returnType Expected return type of filtered methods.
* @return Array of methods with @name.
*/
private Method[] filterMethods(Method[] methods, String seekedName, Class<?> returnType) {
List<Method> filteredMethods = new LinkedList<Method>();
for (Method testedMethod : methods) {
String testedMethodName = testedMethod.getName();
boolean methodIsPublic = (testedMethod.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC;
boolean methodIsAbstract = (testedMethod.getModifiers() & Modifier.ABSTRACT) == Modifier.ABSTRACT;
boolean correctReturnType = returnType.isAssignableFrom(testedMethod.getReturnType());
boolean acceptedParams = areParamsAcceptable(testedMethod, true, allowedParamClasses);
boolean annotatedParams = areParamsAnnotated(testedMethod);
if (testedMethodName.equals(seekedName)
&& methodIsPublic
&& !methodIsAbstract
&& !testedMethod.isVarArgs()
&& correctReturnType
&& acceptedParams
&& annotatedParams) {
filteredMethods.add(testedMethod);
}
}
return filteredMethods.toArray(new Method[filteredMethods.size()]);
}
示例9: getMethod
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Search for the first publically and privately defined method of the given name and parameter count.
* @param requireMod - modifiers that are required.
* @param bannedMod - modifiers that are banned.
* @param clazz - a class to start with.
* @param methodName - the method name, or NULL to skip.
* @param params - the expected parameters.
* @return The first method by this name.
* @throws IllegalStateException If we cannot find this method.
*/
private static Method getMethod(int requireMod, int bannedMod, Class<?> clazz, String methodName, Class<?>... params) {
for (Method method : clazz.getDeclaredMethods()) {
// Limitation: Doesn't handle overloads
if ((method.getModifiers() & requireMod) == requireMod &&
(method.getModifiers() & bannedMod) == 0 &&
(methodName == null || method.getName().equals(methodName)) &&
Arrays.equals(method.getParameterTypes(), params)) {
method.setAccessible(true);
return method;
}
}
// Search in every superclass
if (clazz.getSuperclass() != null)
return getMethod(requireMod, bannedMod, clazz.getSuperclass(), methodName, params);
throw new IllegalStateException(String.format(
"Unable to find method %s (%s).", methodName, Arrays.asList(params)));
}
示例10: overrides
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Returns true if a overrides b. Assumes signatures of a and b are the same and a's declaring
* class is a subclass of b's declaring class.
*/
private static boolean overrides(Method a, Method b) {
// See JLS section 8.4.8.1
int modifiers = b.getModifiers();
if (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers)) {
return true;
}
if (Modifier.isPrivate(modifiers)) {
return false;
}
// b must be package-private
return a.getDeclaringClass().getPackage().equals(b.getDeclaringClass().getPackage());
}
示例11: overrides
import java.lang.reflect.Method; //导入方法依赖的package包/类
/** Returns true if a overrides b, assumes that the signatures match */
private static boolean overrides(Method a, Method b) {
// See JLS section 8.4.8.1
int modifiers = b.getModifiers();
if (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers)) {
return true;
}
if (Modifier.isPrivate(modifiers)) {
return false;
}
// b must be package-private
return a.getDeclaringClass().getPackage().equals(b.getDeclaringClass().getPackage());
}
示例12: getMapperMethodsByClazz
import java.lang.reflect.Method; //导入方法依赖的package包/类
private void getMapperMethodsByClazz(final List<Method> result, final Class clazz) {
if (clazz != null && clazz.isAnnotationPresent(LuaViewLib.class)) {//XXXMapper
getMapperMethodsByClazz(result, clazz.getSuperclass());//处理super
final Method[] methods = clazz.getDeclaredMethods();
if (methods != null && methods.length > 0) {
for (final Method method : methods) {//add self
if (method.getModifiers() == Modifier.PUBLIC) {//public 方法才行
result.add(method);
}
}
}
}
}
示例13: getMethodInfo
import java.lang.reflect.Method; //导入方法依赖的package包/类
private static MethodInfo getMethodInfo(ClassInfo classInfo, Method method) {
Class returnTypeClass = method.getReturnType();
short access_flags = (short) method.getModifiers();
return MethodInfo.create(
classInfo,
method.getName(),
getTypes( method.getParameterTypes() ),
getType( returnTypeClass ),
access_flags
);
}
示例14: JavaMethod
import java.lang.reflect.Method; //导入方法依赖的package包/类
private JavaMethod(Method m) {
super( m.getParameterTypes(), m.getModifiers() ); //TODO 这里需要保护, m.getParameterTypes报错
this.method = m;
try {
if (!m.isAccessible())
m.setAccessible(true);
} catch (SecurityException s) {
}
}
示例15: matchInheritance
import java.lang.reflect.Method; //导入方法依赖的package包/类
public static boolean matchInheritance(final Method subclassMethod, final Method superclassMethod) {
if (Modifier.isStatic(superclassMethod.getModifiers()) || subclassMethod.equals(superclassMethod)) {
return false;
}
if (matchSignature(subclassMethod, superclassMethod)) {
final Package subclassPackage = subclassMethod.getDeclaringClass().getPackage();
final Package superclassPackage = superclassMethod.getDeclaringClass().getPackage();
final int superMethodModifiers = superclassMethod.getModifiers();
return isAccessable(subclassPackage, superclassPackage, superMethodModifiers);
} else {
return false;
}
}