Example usage for java.lang.reflect Modifier NATIVE

List of usage examples for java.lang.reflect Modifier NATIVE

Introduction

In this page you can find the example usage for java.lang.reflect Modifier NATIVE.

Prototype

int NATIVE

To view the source code for java.lang.reflect Modifier NATIVE.

Click Source Link

Document

The int value representing the native modifier.

Usage

From source file:Main.java

public static void main(String... args) throws Exception {
    Class<?> c = Class.forName("java.lang.String");
    Constructor[] allConstructors = c.getDeclaredConstructors();
    for (Constructor ctor : allConstructors) {
        int searchMod = Modifier.NATIVE;
        int mods = accessModifiers(ctor.getModifiers());
        if (searchMod == mods) {
            System.out.println(ctor);
        }//from w  w w .j a  v  a2s  . c  o  m
    }
}

From source file:Main.java

private static int accessModifiers(int m) {
    return m & Modifier.NATIVE;
}

From source file:hu.bme.mit.sette.common.model.snippet.SnippetInputFactoryContainer.java

/**
 * Validates methods of the class.//from w w w  .j  ava2  s  .co m
 *
 * @param validator
 *            a validator
 * @return a map containing the input factory methods by their name
 */
private Map<String, Method> validateMethods(final AbstractValidator<?> validator) {
    // check: only "public static" or synthetic methods
    Map<String, Method> factoryMethods = new HashMap<String, Method>();

    for (Method method : javaClass.getDeclaredMethods()) {
        if (method.isSynthetic()) {
            // skip synthetic methods
            continue;
        }

        MethodValidator v = new MethodValidator(method);

        if (factoryMethods.get(method.getName()) != null) {
            v.addException("The method must have a unique name");
        }

        v.withModifiers(Modifier.PUBLIC | Modifier.STATIC);
        v.withoutModifiers(Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE | Modifier.SYNCHRONIZED);

        factoryMethods.put(method.getName(), method);

        validator.addChildIfInvalid(v);
    }

    return factoryMethods;
}

From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java

@Test
public void defaultAccessMethodsWithStaticNativeOnly() {
    memberCriteria.membersOfType(Method.class);
    memberCriteria.withAccess(AccessType.DEFAULT);
    memberCriteria.withModifiers(Modifier.STATIC | Modifier.NATIVE);
    ClassCriteria classCriteria = new ClassCriteria();
    Iterable<Class<?>> classIterable = classCriteria.getIterable(Class.class);
    Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable);
    assertTrue(memberIterable.iterator().hasNext());
    for (Member member : memberIterable) {
        assertTrue("member must be a method", member instanceof Method);
        int modifiers = member.getModifiers();
        assertFalse(Modifier.isPublic(modifiers));
        assertFalse(Modifier.isProtected(modifiers));
        assertFalse(Modifier.isPrivate(modifiers));
        assertTrue(Modifier.isStatic(modifiers));
        assertTrue(Modifier.isNative(modifiers));
    }/* w w  w. java2s . c o m*/
}

From source file:hu.bme.mit.sette.common.model.snippet.SnippetContainer.java

/**
 * Validates methods of the class./*from  w w w . j  a  v  a  2s.c  o  m*/
 *
 * @param validator
 *            a validator
 * @return a map containing the snippet methods by their name
 */
private Map<String, Method> validateMethods(final AbstractValidator<?> validator) {
    // check: only "[public|private] static" or synthetic methods
    Map<String, Method> snippetMethods = new HashMap<String, Method>();

    for (Method method : javaClass.getDeclaredMethods()) {
        if (method.isSynthetic()) {
            // skip synthetic methods
            continue;
        }

        MethodValidator v = new MethodValidator(method);

        if (snippetMethods.get(method.getName()) != null) {
            v.addException("The method must have a unique name");
        }

        int methodModifiers = method.getModifiers();

        if (!Modifier.isPublic(methodModifiers) && !Modifier.isPrivate(methodModifiers)) {
            v.addException("The method must be public or private");
        }

        v.withModifiers(Modifier.STATIC);
        v.withoutModifiers(Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE | Modifier.SYNCHRONIZED);

        AnnotationMap methodAnns = SetteAnnotationUtils.getSetteAnnotations(method);

        if (Modifier.isPublic(methodModifiers)) {
            if (methodAnns.get(SetteNotSnippet.class) == null) {
                // should be snippet, validated by Snippet class and added
                // later
                snippetMethods.put(method.getName(), method);
            } else {
                // not snippet
                snippetMethods.put(method.getName(), null);

                if (methodAnns.size() != 1) {
                    v.addException("The method must not have " + "any other SETTE annotations "
                            + "if it is not a snippet.");
                }
            }
        } else {
            // method is private
            if (methodAnns.size() != 0) {
                v.addException("The method must not have " + "any SETTE annotations");
            }
        }

        validator.addChildIfInvalid(v);
    }

    return snippetMethods;
}

From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteria.java

/**
 * Set the criterion that selects only {@link Member}s that exactly have the
 * specified modifiers. The access modifiers are set separately. Use
 * {@link #withAccess(AccessType...)} to set access modifiers.
 *
 * @param modifiers/*from w w  w  .  j  a  v a  2s  .  co m*/
 * @since 1.0.0.0
 */
public void withModifiers(int modifiers) {
    if (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers) || Modifier.isPrivate(modifiers)) {
        throw new IllegalArgumentException(
                "access modifiers are not allowed as argument. Use withAccess() instead.");
    }
    int allowedModifiers = Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT
            | Modifier.VOLATILE | Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT
            | Modifier.INTERFACE;

    if ((modifiers & allowedModifiers) == 0) {
        throw new IllegalArgumentException(
                "modifiers must be one of [" + Modifier.toString(allowedModifiers) + "]");
    }

    this.modifiers = modifiers;
}