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

The following are Jave code examples for showing how to use isNative() of the java.lang.reflect.Modifier class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: hy.common.base   File: MethodReflect.java   Source Code and License Vote up 6 votes
/**
 * 获取前缀相同的方法
 * 
 * 只获取"本类自己"的方法
 * 
 * @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 2
Project: hy.common.base   File: MethodReflect.java   Source Code and License Vote up 6 votes
/**
 * 获取前缀相同,入参参数匹配的方法
 * 
 * 只获取"本类自己"的方法
 * 
 * @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
Project: MaxSim   File: CompileTheWorld.java   Source Code and License Vote up 6 votes
/**
 * Helper method for CompileTheWorld to determine if a method should be compiled (Cf.
 * CompilationPolicy::can_be_compiled).
 * 
 * @return true if it can be compiled, false otherwise
 */
private static boolean canBeCompiled(HotSpotResolvedJavaMethod javaMethod, int modifiers) {
    if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) {
        return false;
    }
    // This number is from HotSpot:
    final int hugeMethodLimit = 8000;
    if (javaMethod.getCodeSize() > hugeMethodLimit) {
        return false;
    }
    // Skip @Snippets for now
    if (javaMethod.getAnnotation(Snippet.class) != null) {
        return false;
    }
    return true;
}
 
Example 4
Project: tangyuan2   File: TypeUtils.java   Source Code and License Vote up 6 votes
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 5
Project: tangyuan2   File: TypeUtils.java   Source Code and License Vote up 6 votes
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 6
Project: openjdk-jdk10   File: VerifyBailoutUsageTest.java   Source Code and License Vote up 6 votes
@SuppressWarnings("try")
private static void testBailoutUsage(Class<?> c) {
    RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
    Providers providers = rt.getHostBackend().getProviders();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
    Plugins plugins = new Plugins(new InvocationPlugins());
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
    graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
    HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
    OptionValues options = getInitialOptions();
    DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
    for (Method m : c.getDeclaredMethods()) {
        if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
            ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
            StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
            graphBuilderSuite.apply(graph, context);
            try (DebugCloseable s = debug.disableIntercept()) {
                new VerifyBailoutUsage().apply(graph, context);
            }
        }
    }
}
 
Example 7
Project: openjdk-jdk10   File: CompileTheWorld.java   Source Code and License Vote up 6 votes
/**
 * Determines if a method should be compiled (Cf. CompilationPolicy::can_be_compiled).
 *
 * @return true if it can be compiled, false otherwise
 */
private boolean canBeCompiled(HotSpotResolvedJavaMethod javaMethod, int modifiers) {
    if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) {
        return false;
    }
    GraalHotSpotVMConfig c = compiler.getGraalRuntime().getVMConfig();
    if (c.dontCompileHugeMethods && javaMethod.getCodeSize() > c.hugeMethodLimit) {
        println(verbose || methodFilters != null,
                        String.format("CompileTheWorld (%d) : Skipping huge method %s (use -XX:-DontCompileHugeMethods or -XX:HugeMethodLimit=%d to include it)", classFileCounter,
                                        javaMethod.format("%H.%n(%p):%r"),
                                        javaMethod.getCodeSize()));
        return false;
    }
    // Allow use of -XX:CompileCommand=dontinline to exclude problematic methods
    if (!javaMethod.canBeInlined()) {
        return false;
    }
    // Skip @Snippets for now
    for (Annotation annotation : javaMethod.getAnnotations()) {
        if (annotation.annotationType().equals(Snippet.class)) {
            return false;
        }
    }
    return true;
}
 
Example 8
Project: hy.common.base   File: MethodReflect.java   Source Code and License Vote up 5 votes
/**
 * 获取多个前缀相同,入参参数匹配的方法
 * 
 * 只获取"本类自己"的方法
 * 
 * @param i_Class
 * @param i_MethodPrefixName  参数名称前缀 
 * @param i_ParamSize         参数个数
 * @return
 */
public static List<Method> getStartMethods(Class<?> i_Class ,String [] i_MethodPrefixNames ,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 )
            {
                for (int x=0; x<i_MethodPrefixNames.length; x++)
                {
                    if ( v_Methods[i].getName().startsWith(i_MethodPrefixNames[x]) )
                    {
                        v_Ret.add(v_Methods[i]);
                        break;
                    }
                }
            }
        }
    }
    
    return v_Ret;
}
 
Example 9
Project: openjdk-jdk10   File: MethodSubstitutionPlugin.java   Source Code and License Vote up 5 votes
/**
 * 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 10
Project: openjdk-jdk10   File: GetStackTraceElementTest.java   Source Code and License Vote up 5 votes
private static void runSanityTest(Executable aMethod, int[] bcis) {
    HotSpotResolvedJavaMethod method = CTVMUtilities
            .getResolvedMethod(aMethod);
    String className = aMethod.getDeclaringClass().getName();
    String methodName = aMethod.getName().equals(className)
            ? "<init>"
            : aMethod.getName();
    String fileName = getFileName(className);
    Map<Integer, Integer> bciWithLineNumber = CTVMUtilities
            .getBciToLineNumber(aMethod);
    boolean isNative = Modifier.isNative(aMethod.getModifiers());
    int lineNumber = -1;
    for (int bci : bcis) {
        StackTraceElement ste = CompilerToVMHelper
                .getStackTraceElement(method, bci);
        Asserts.assertNotNull(ste, aMethod + " : got null StackTraceElement"
                + " at bci " + bci);
        Asserts.assertEQ(className, ste.getClassName(), aMethod
                + " : unexpected class name");
        Asserts.assertEQ(fileName, ste.getFileName(), aMethod
                + " : unexpected filename");
        Asserts.assertEQ(methodName, ste.getMethodName(), aMethod
                + " : unexpected method name");
        Asserts.assertEQ(isNative, ste.isNativeMethod(), aMethod
                + " : unexpected 'isNative' value");
        if (bciWithLineNumber.size() > 0) {
            if (bciWithLineNumber.containsKey(bci)) {
                lineNumber = bciWithLineNumber.get(bci);
            }
            Asserts.assertEQ(lineNumber, ste.getLineNumber(), aMethod
                    + " : unexpected line number");
        } else {
            // native and abstract function
            Asserts.assertGT(0, ste.getLineNumber(),
                    aMethod + " : unexpected line number for abstract "
                            + "or native method");
        }
    }

}
 
Example 11
Project: openjdk-jdk10   File: ModifiersProvider.java   Source Code and License Vote up 4 votes
/**
 * @see Modifier#isNative(int)
 */
default boolean isNative() {
    return Modifier.isNative(getModifiers());
}
 
Example 12
Project: googles-monorepo-demo   File: Element.java   Source Code and License Vote up 4 votes
/** Returns true if the element is native. */
public final boolean isNative() {
  return Modifier.isNative(getModifiers());
}
 
Example 13
Project: JavaRushTasks   File: Solution.java   Source Code and License Vote up 4 votes
public static boolean isAllModifiersContainSpecificModifier(int allModifiers, int specificModifier) {
    if (Modifier.isAbstract(allModifiers) && Modifier.isAbstract(specificModifier))
        return true;

    if (Modifier.isFinal(allModifiers) && Modifier.isFinal(specificModifier))
        return true;

    if (Modifier.isInterface(allModifiers) && Modifier.isInterface(specificModifier))
        return true;

    if (Modifier.isNative(allModifiers) && Modifier.isNative(specificModifier))
        return true;

    if (Modifier.isPrivate(allModifiers) && Modifier.isPrivate(specificModifier))
        return true;

    if (Modifier.isProtected(allModifiers) && Modifier.isProtected(specificModifier))
        return true;

    if (Modifier.isPublic(allModifiers) && Modifier.isPublic(specificModifier))
        return true;

    if (Modifier.isStatic(allModifiers) && Modifier.isStatic(specificModifier))
        return true;

    if (Modifier.isStrict(allModifiers) && Modifier.isStrict(specificModifier))
        return true;

    if (Modifier.isSynchronized(allModifiers) && Modifier.isSynchronized(specificModifier))
        return true;

    if (Modifier.isTransient(allModifiers) && Modifier.isTransient(specificModifier))
        return true;

    if (Modifier.isVolatile(allModifiers) && Modifier.isVolatile(specificModifier))
        return true;

    if (Modifier.isVolatile(allModifiers) && Modifier.isVolatile(specificModifier))
        return true;

    return false;
}
 
Example 14
Project: openjdk-jdk10   File: MemberName.java   Source Code and License Vote up 4 votes
/** Utility method to query the modifier flags of this member. */
public boolean isNative() {
    return Modifier.isNative(flags);
}
 
Example 15
Project: NanoUI   File: Method.java   Source Code and License Vote up 4 votes
/** Return true if the method includes the {@code native} modifier. */
public boolean isNative () {
	return Modifier.isNative(method.getModifiers());
}
 
Example 16
Project: OpenJSharp   File: ExecutableMemberDocImpl.java   Source Code and License Vote up 4 votes
/**
 * Return true if this method is native
 */
public boolean isNative() {
    return Modifier.isNative(getModifiers());
}
 
Example 17
Project: OpenJSharp   File: MemberName.java   Source Code and License Vote up 4 votes
/** Utility method to query the modifier flags of this member. */
public boolean isNative() {
    return Modifier.isNative(flags);
}
 
Example 18
Project: featurea   File: Method.java   Source Code and License Vote up 4 votes
/**
 * Return true if the method includes the {@code native} modifier.
 */
public boolean isNative() {
    return Modifier.isNative(method.getModifiers());
}
 
Example 19
Project: jdk8u-jdk   File: MemberName.java   Source Code and License Vote up 4 votes
/** Utility method to query the modifier flags of this member. */
public boolean isNative() {
    return Modifier.isNative(flags);
}
 
Example 20
Project: openjdk-jdk10   File: ExecutableMemberDocImpl.java   Source Code and License Vote up 4 votes
/**
 * Return true if this method is native
 */
public boolean isNative() {
    return Modifier.isNative(getModifiers());
}