Java Code Examples for java.lang.reflect.Modifier#isNative()

The following examples show how to use java.lang.reflect.Modifier#isNative() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassUtils.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
/**
 * 迭代查询全部方法,包括本类和父类
 *
 * @param clazz 对象类
 * @return 所有字段列表
 */
public static List<Method> getAllMethods(Class clazz) {
    List<Method> all = new ArrayList<Method>();
    for (Class<?> c = clazz; c != Object.class && c != null; c = c.getSuperclass()) {
        Method[] methods = c.getDeclaredMethods(); // 所有方法,不包含父类
        for (Method method : methods) {
            int mod = method.getModifiers();
            // native的不要
            if (Modifier.isNative(mod)) {
                continue;
            }
            method.setAccessible(true); // 不管private还是protect都可以
            all.add(method);
        }
    }
    return all;
}
 
Example 2
Source File: MethodReflect.java    From hy.common.base with Apache License 2.0 6 votes vote down vote up
/**
 * 获取前缀相同,入参参数匹配的方法
 * 
 * 只获取"本类自己"的方法
 * 
 * @param i_Class
 * @param i_MethodPrefixName  参数名称前缀 
 * @param i_ParamSize         参数个数
 * @return
 */
public static List<Method> getStartMethods(Class<?> i_Class ,String i_MethodPrefixName ,int i_ParamSize)
{
    List<Method> v_Ret     = new ArrayList<Method>();
    Method []    v_Methods = i_Class.getMethods();
    
    
    for (int i=0; i<v_Methods.length; i++)
    {
        // 只获取"本类自己"的方法
        if ( !Modifier.isNative(v_Methods[i].getModifiers()) )
        {
            if ( v_Methods[i].getParameterTypes().length == i_ParamSize )
            {
                if ( v_Methods[i].getName().startsWith(i_MethodPrefixName) )
                {
                    v_Ret.add(v_Methods[i]);
                }
            }
        }
    }
    
    return v_Ret;
}
 
Example 3
Source File: MethodReflect.java    From hy.common.base with Apache License 2.0 6 votes vote down vote up
/**
 * 获取前缀相同的方法
 * 
 * 只获取"本类自己"的方法
 * 
 * @param i_Class
 * @param i_MethodPrefixName
 * @return
 */
public static List<Method> getStartMethods(Class<?> i_Class ,String i_MethodPrefixName)
{
    List<Method> v_Ret     = new ArrayList<Method>();
    Method []    v_Methods = i_Class.getMethods();
    
    for (int i=0; i<v_Methods.length; i++)
    {
        // 只获取"本类自己"的方法
        if ( !Modifier.isNative(v_Methods[i].getModifiers()) )
        {
            if ( v_Methods[i].getName().startsWith(i_MethodPrefixName) )
            {
                v_Ret.add(v_Methods[i]);
            }
        }
    }
    
    return v_Ret;
}
 
Example 4
Source File: TypeUtils.java    From tangyuan2 with GNU General Public License v3.0 6 votes vote down vote up
private static boolean checkSetter(Method method, Field field) {
	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 != 1) {
		return true;
	}
	if (!method.getParameterTypes()[0].equals(field.getType())) {
		return true;
	}
	return false;
}
 
Example 5
Source File: XsonTypeUtils.java    From xson with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: HookInfo.java    From MobileInfo with Apache License 2.0 5 votes vote down vote up
/**
 * 新增判断系统方法调用钩子
 * 方法参考自<url>https://github.com/w568w/XposedChecker/</url>
 *
 * @return 是否安装了Xposed
 */
private static boolean checkNativeMethod() {
    try {
        Method method = Throwable.class.getDeclaredMethod("getStackTrace");
        return Modifier.isNative(method.getModifiers());
    } catch (NoSuchMethodException e) {
        e.printStackTrace();


    }
    return false;
}
 
Example 7
Source File: Utils.java    From apkfile with Apache License 2.0 5 votes vote down vote up
public static void updateAccessorCounts(TObjectIntMap<String> counts, int[] accessFlags) {
    for (int accessFlag : accessFlags) {
        if (Modifier.isPublic(accessFlag)) {
            counts.adjustOrPutValue("public", 1, 1);
        }
        if (Modifier.isProtected(accessFlag)) {
            counts.adjustOrPutValue("protected", 1, 1);
        }
        if (Modifier.isPrivate(accessFlag)) {
            counts.adjustOrPutValue("private", 1, 1);
        }
        if (Modifier.isFinal(accessFlag)) {
            counts.adjustOrPutValue("final", 1, 1);
        }
        if (Modifier.isInterface(accessFlag)) {
            counts.adjustOrPutValue("interface", 1, 1);
        }
        if (Modifier.isNative(accessFlag)) {
            counts.adjustOrPutValue("native", 1, 1);
        }
        if (Modifier.isStatic(accessFlag)) {
            counts.adjustOrPutValue("static", 1, 1);
        }
        if (Modifier.isStrict(accessFlag)) {
            counts.adjustOrPutValue("strict", 1, 1);
        }
        if (Modifier.isSynchronized(accessFlag)) {
            counts.adjustOrPutValue("synchronized", 1, 1);
        }
        if (Modifier.isTransient(accessFlag)) {
            counts.adjustOrPutValue("transient", 1, 1);
        }
        if (Modifier.isVolatile(accessFlag)) {
            counts.adjustOrPutValue("volatile", 1, 1);
        }
        if (Modifier.isAbstract(accessFlag)) {
            counts.adjustOrPutValue("abstract", 1, 1);
        }
    }
}
 
Example 8
Source File: MethodSubstitutionPlugin.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the reflection API version of the substitution method.
 */
Method getJavaSubstitute() throws GraalError {
    Method substituteMethod = lookupSubstitute();
    int modifiers = substituteMethod.getModifiers();
    if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) {
        throw new GraalError("Substitution method must not be abstract or native: " + substituteMethod);
    }
    if (!Modifier.isStatic(modifiers)) {
        throw new GraalError("Substitution method must be static: " + substituteMethod);
    }
    return substituteMethod;
}
 
Example 9
Source File: MemberName.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/** Utility method to query the modifier flags of this member. */
public boolean isNative() {
    return Modifier.isNative(flags);
}
 
Example 10
Source File: WeavingClassVisitor.java    From glowroot with Apache License 2.0 4 votes vote down vote up
private static boolean isAbstractOrNativeOrSynthetic(int access) {
    return Modifier.isAbstract(access) || Modifier.isNative(access)
            || (access & ACC_SYNTHETIC) != 0;
}
 
Example 11
Source File: MemberName.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/** Utility method to query the modifier flags of this member. */
public boolean isNative() {
    return Modifier.isNative(flags);
}
 
Example 12
Source File: Element.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns true if the element is native. */
public final boolean isNative() {
  return Modifier.isNative(getModifiers());
}
 
Example 13
Source File: ReflectionPredicates.java    From raistlic-lib-commons-core with Apache License 2.0 4 votes vote down vote up
@Override
public boolean test(Member member) {
  return Modifier.isNative(member.getModifiers());
}
 
Example 14
Source File: HookManager.java    From RocooFix with MIT License 4 votes vote down vote up
private static Method hookMethodArt(Method origin, Method hook) {
    ArtMethod artOrigin = ArtMethod.of(origin);
    ArtMethod artHook = ArtMethod.of(hook);
    Method backup = artOrigin.backup().getMethod();
    backup.setAccessible(true);


    long originPointFromQuickCompiledCode = artOrigin.getEntryPointFromQuickCompiledCode();
    long originEntryPointFromJni = artOrigin.getEntryPointFromJni();
    long originEntryPointFromInterpreter = artOrigin.getEntryPointFromInterpreter();
    long originDeclaringClass = artOrigin.getDeclaringClass();
    long originAccessFlags = artOrigin.getAccessFlags();
    long originDexCacheResolvedMethods = artOrigin.getDexCacheResolvedMethods();
    long originDexCacheResolvedTypes = artOrigin.getDexCacheResolvedTypes();
    long originDexCodeItemOffset = artOrigin.getDexCodeItemOffset();
    long originDexMethodIndex = artOrigin.getDexMethodIndex();

    long hookPointFromQuickCompiledCode = artHook.getEntryPointFromQuickCompiledCode();
    long hookEntryPointFromJni = artHook.getEntryPointFromJni();
    long hookEntryPointFromInterpreter = artHook.getEntryPointFromInterpreter();
    long hookDeclaringClass = artHook.getDeclaringClass();
    long hookAccessFlags = artHook.getAccessFlags();
    long hookDexCacheResolvedMethods = artHook.getDexCacheResolvedMethods();
    long hookDexCacheResolvedTypes = artHook.getDexCacheResolvedTypes();
    long hookDexCodeItemOffset = artHook.getDexCodeItemOffset();
    long hookDexMethodIndex = artHook.getDexMethodIndex();

    ByteBuffer hookInfo = ByteBuffer.allocate(ART_HOOK_INFO_SIZE);
    hookInfo.putLong(originPointFromQuickCompiledCode);
    hookInfo.putLong(originEntryPointFromJni);
    hookInfo.putLong(originEntryPointFromInterpreter);
    hookInfo.putLong(originDeclaringClass);
    hookInfo.putLong(originAccessFlags);
    hookInfo.putLong(originDexCacheResolvedMethods);
    hookInfo.putLong(originDexCacheResolvedTypes);
    hookInfo.putLong(originDexCodeItemOffset);
    hookInfo.putLong(originDexMethodIndex);

    hookInfo.putLong(hookPointFromQuickCompiledCode);
    hookInfo.putLong(hookEntryPointFromJni);
    hookInfo.putLong(hookEntryPointFromInterpreter);
    hookInfo.putLong(hookDeclaringClass);
    hookInfo.putLong(hookAccessFlags);
    hookInfo.putLong(hookDexCacheResolvedMethods);
    hookInfo.putLong(hookDexCacheResolvedTypes);
    hookInfo.putLong(hookDexCodeItemOffset);
    hookInfo.putLong(hookDexMethodIndex);

    artOrigin.setEntryPointFromQuickCompiledCode(hookPointFromQuickCompiledCode);
    artOrigin.setEntryPointFromInterpreter(hookEntryPointFromInterpreter);
    artOrigin.setDeclaringClass(hookDeclaringClass);
    artOrigin.setDexCacheResolvedMethods(hookDexCacheResolvedMethods);
    artOrigin.setDexCacheResolvedTypes(hookDexCacheResolvedTypes);
    artOrigin.setDexCodeItemOffset((int) hookDexCodeItemOffset);
    artOrigin.setDexMethodIndex((int) hookDexMethodIndex);


    int accessFlags = origin.getModifiers();
    if (Modifier.isNative(accessFlags)) {
        accessFlags &= ~Modifier.NATIVE;
        artOrigin.setAccessFlags(accessFlags);
    }
    long memoryAddress = Memory.alloc(ART_HOOK_INFO_SIZE);
    Memory.write(memoryAddress, hookInfo.array());
    artOrigin.setEntryPointFromJni(memoryAddress);

    return backup;
}
 
Example 15
Source File: ExecutableMemberDocImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if this method is native
 */
public boolean isNative() {
    return Modifier.isNative(getModifiers());
}
 
Example 16
Source File: Utils.java    From obfuscator with MIT License 4 votes vote down vote up
public static boolean notAbstractOrNative(MethodNode methodNode) {
    return !Modifier.isNative(methodNode.access) && !Modifier.isAbstract(methodNode.access);
}
 
Example 17
Source File: MemberName.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/** Utility method to query the modifier flags of this member. */
public boolean isNative() {
    return Modifier.isNative(flags);
}
 
Example 18
Source File: MemberName.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/** Utility method to query the modifier flags of this member. */
public boolean isNative() {
    return Modifier.isNative(flags);
}
 
Example 19
Source File: Element.java    From codebuff with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/** Returns true if the element is native. */


  public final boolean isNative() {
    return Modifier.isNative(getModifiers());
  }
 
Example 20
Source File: Element.java    From codebuff with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/** Returns true if the element is native. */


  public final boolean isNative() {
    return Modifier.isNative(getModifiers());
  }