當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。