当前位置: 首页>>代码示例>>Java>>正文


Java Method.getModifiers方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ReflectionFactory.java

示例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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ObjectStreamClass.java

示例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());
}
 
开发者ID:hsllany,项目名称:HtmlNative,代码行数:25,代码来源:LuajavaLib.java

示例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) {
	}
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:17,代码来源:LuaClass.java

示例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 ;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ServerMain.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:Introspector.java

示例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;
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:26,代码来源:TypeUtils.java

示例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()]);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:46,代码来源:ParamsMethod.java

示例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)));
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:29,代码来源:NbtFactory.java

示例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());
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:17,代码来源:InjectionPoint.java

示例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());
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:14,代码来源:ProviderMethodsModule.java

示例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);
                }
            }
        }
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:14,代码来源:BaseVarArgCreator.java

示例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
	);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:MockHelper.java

示例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) {
	}
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:10,代码来源:JavaMethod.java

示例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;
	}
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:16,代码来源:Reflections.java


注:本文中的java.lang.reflect.Method.getModifiers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。