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

The following examples show how to use java.lang.reflect.Modifier#isNative() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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 2
Source Project: hy.common.base   File: MethodReflect.java    License: 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 3
Source Project: xson   File: XsonTypeUtils.java    License: 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 4
Source Project: hy.common.base   File: MethodReflect.java    License: 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 5
Source Project: sofa-rpc   File: ClassUtils.java    License: 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 6
Source Project: MobileInfo   File: HookInfo.java    License: 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
/**
 * 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 8
Source Project: apkfile   File: Utils.java    License: 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 9
/** Utility method to query the modifier flags of this member. */
public boolean isNative() {
    return Modifier.isNative(flags);
}
 
Example 10
/** Utility method to query the modifier flags of this member. */
public boolean isNative() {
    return Modifier.isNative(flags);
}
 
Example 11
/**
 * Return true if this method is native
 */
public boolean isNative() {
    return Modifier.isNative(getModifiers());
}
 
Example 12
@Override
public boolean test(Member member) {
  return Modifier.isNative(member.getModifiers());
}
 
Example 13
Source Project: Java8CN   File: MemberName.java    License: 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 14
/** Utility method to query the modifier flags of this member. */
public boolean isNative() {
    return Modifier.isNative(flags);
}
 
Example 15
Source Project: glowroot   File: WeavingClassVisitor.java    License: 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 16
Source Project: codebuff   File: Element.java    License: 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 17
Source Project: RocooFix   File: HookManager.java    License: 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 18
Source Project: obfuscator   File: Utils.java    License: MIT License 4 votes vote down vote up
public static boolean notAbstractOrNative(MethodNode methodNode) {
    return !Modifier.isNative(methodNode.access) && !Modifier.isAbstract(methodNode.access);
}
 
Example 19
Source Project: codebuff   File: Element.java    License: 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 Project: codebuff   File: Element.java    License: 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());
  }