Example usage for java.lang.reflect Modifier isNative

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

Introduction

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

Prototype

public static boolean isNative(int mod) 

Source Link

Document

Return true if the integer argument includes the native modifier, false otherwise.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Class<?> clazz = String.class;
    int modifier = clazz.getModifiers();

    if (Modifier.isNative(modifier)) {
        System.out.println("isNative");
    }//  w  w w .j a v  a 2 s .  c om
}

From source file:DeclarationInfoDemo.java

public static void printModifiers(final Class dataType) {
    final int modifiers = dataType.getModifiers();
    if (Modifier.isPrivate(modifiers)) {
        System.out.print("private ");
    }//  ww  w. j a  va2  s  . co m
    if (Modifier.isPrivate(modifiers)) {
        System.out.print("private ");
    }
    if (Modifier.isPublic(modifiers)) {
        System.out.print("private ");
    }
    if (Modifier.isAbstract(modifiers)) {
        System.out.print("abstract ");
    }
    if (Modifier.isFinal(modifiers)) {
        System.out.print("final ");
    }
    if (Modifier.isNative(modifiers)) {
        System.out.print("native ");
    }
    if (Modifier.isInterface(modifiers)) {
        System.out.print("interface ");
    }
    if (Modifier.isStatic(modifiers)) {
        System.out.print("static ");
    }
    if (Modifier.isStrict(modifiers)) {
        System.out.print("strict ");
    }
    if (Modifier.isSynchronized(modifiers)) {
        System.out.print("synchronized ");
    }
    if (Modifier.isTransient(modifiers)) {
        System.out.print("transient ");
    }
    if (Modifier.isVolatile(modifiers)) {
        System.out.print("volatile ");
    }
    System.out.println(dataType.getName());
}

From source file:ModifierUtil.java

public static boolean isNative(Member member) {
    return Modifier.isNative(member.getModifiers());
}

From source file:com.trafficspaces.api.model.Resource.java

public JSONObject getJSONObject() {
    JSONObject jsonObject = new JSONObject();
    Field[] fields = this.getClass().getFields();
    try {//from   ww w . j  av a  2  s .c  om
        for (int i = 0; i < fields.length; i++) {

            Object fieldValue = fields[i].get(this);
            int fieldModifiers = fields[i].getModifiers();
            //System.out.println("name=" + fields[i].getName() + ", value=" + fieldValue + ", type=" +fields[i].getType() + 
            //      ", ispublic="+Modifier.isPublic(fieldModifiers) + ", isstatic="+Modifier.isStatic(fieldModifiers) + ", isnative="+Modifier.isNative(fieldModifiers));
            if (fieldValue != null && Modifier.isPublic(fieldModifiers) && !Modifier.isStatic(fieldModifiers)
                    && !Modifier.isNative(fieldModifiers)) {

                String name = fields[i].getName();
                Class type = fields[i].getType();

                if (type.isPrimitive()) {
                    if (type.equals(int.class)) {
                        jsonObject.put(name, fields[i].getInt(this));
                    } else if (type.equals(double.class)) {
                        jsonObject.put(name, fields[i].getDouble(this));
                    }
                } else if (type.isArray()) {
                    JSONObject jsonSubObject = new JSONObject();
                    JSONArray jsonArray = new JSONArray();

                    jsonObject.put(name, jsonSubObject);
                    jsonSubObject.put(name.substring(0, name.length() - 1), jsonArray);

                    Object[] values = (Object[]) fieldValue;
                    for (int j = 0; j < values.length; j++) {
                        if (values[j] != null && values[j] instanceof Resource) {
                            jsonArray.put(((Resource) values[j]).getJSONObject());
                        }
                    }
                } else if (Resource.class.isAssignableFrom(type)) {
                    jsonObject.put(name, ((Resource) fieldValue).getJSONObject());
                } else if (type.equals(String.class) && fieldValue != null) {
                    jsonObject.put(name, String.valueOf(fieldValue));
                }
            }
        }
    } catch (Exception nsfe) {
        //
    }
    return jsonObject;
}

From source file:objenome.util.bytecode.SgUtils.java

private static void checkModifiers(int type, int modifiers) {
    for (int modifier = ABSTRACT; modifier <= STRICTFP; modifier++) {
        if (Modifier.isPrivate(modifiers) && !MODIFIERS_MATRIX[PRIVATE][type]) {
            throwIllegalArgument(type, PRIVATE);
        }/*from  ww  w.  j a  va  2 s  . co m*/
        if (Modifier.isProtected(modifiers) && !MODIFIERS_MATRIX[PROTECTED][type]) {
            throwIllegalArgument(type, PROTECTED);
        }
        if (Modifier.isPublic(modifiers) && !MODIFIERS_MATRIX[PUBLIC][type]) {
            throwIllegalArgument(type, PUBLIC);
        }
        if (Modifier.isStatic(modifiers) && !MODIFIERS_MATRIX[STATIC][type]) {
            throwIllegalArgument(type, STATIC);
        }
        if (Modifier.isAbstract(modifiers) && !MODIFIERS_MATRIX[ABSTRACT][type]) {
            throwIllegalArgument(type, ABSTRACT);
        }
        if (Modifier.isFinal(modifiers) && !MODIFIERS_MATRIX[FINAL][type]) {
            throwIllegalArgument(type, FINAL);
        }
        if (Modifier.isNative(modifiers) && !MODIFIERS_MATRIX[NATIVE][type]) {
            throwIllegalArgument(type, NATIVE);
        }
        if (Modifier.isSynchronized(modifiers) && !MODIFIERS_MATRIX[SYNCHRONIZED][type]) {
            throwIllegalArgument(type, SYNCHRONIZED);
        }
        if (Modifier.isTransient(modifiers) && !MODIFIERS_MATRIX[TRANSIENT][type]) {
            throwIllegalArgument(type, TRANSIENT);
        }
        if (Modifier.isVolatile(modifiers) && !MODIFIERS_MATRIX[VOLATILE][type]) {
            throwIllegalArgument(type, VOLATILE);
        }
        if (Modifier.isStrict(modifiers) && !MODIFIERS_MATRIX[STRICTFP][type]) {
            throwIllegalArgument(type, STRICTFP);
        }
    }
}

From source file:org.lmn.fc.common.utilities.pending.Utilities.java

/***********************************************************************************************
 * Show the Member Modifiers./* ww  w . ja  v  a2 s.  c om*/
 *
 * @param member
 *
 * @return String
 */

public static String showModifiers(final Member member) {
    final int modifiers;
    final StringBuffer buffer;

    buffer = new StringBuffer();

    if (member != null) {
        modifiers = member.getModifiers();

        if (Modifier.isAbstract(modifiers)) {
            buffer.append("Abstract ");
        }

        if (Modifier.isFinal(modifiers)) {
            buffer.append("Final ");
        }

        if (Modifier.isInterface(modifiers)) {
            buffer.append("Interface ");
        }

        if (Modifier.isNative(modifiers)) {
            buffer.append("Native ");
        }

        if (Modifier.isPrivate(modifiers)) {
            buffer.append("Private ");
        }

        if (Modifier.isProtected(modifiers)) {
            buffer.append("Protected ");
        }

        if (Modifier.isPublic(modifiers)) {
            buffer.append("Public ");
        }

        if (Modifier.isStatic(modifiers)) {
            buffer.append("Static ");
        }

        if (Modifier.isStrict(modifiers)) {
            buffer.append("Strict ");
        }

        if (Modifier.isSynchronized(modifiers)) {
            buffer.append("Synchronized ");
        }

        if (Modifier.isTransient(modifiers)) {
            buffer.append("Transient ");
        }

        if (Modifier.isVolatile(modifiers)) {
            buffer.append("Volatile ");
        }
    }

    return (buffer.toString().trim());
}

From source file:objenome.util.bytecode.SgUtils.java

/**
 * Checks if the modifiers are valid for a method. If any of the modifiers
 * is not valid an <code>IllegalArgumentException</code> is thrown.
 * /*from  w w  w .j  a v  a  2  s.c o  m*/
 * @param modifiers
 *            Modifiers.
 */
// CHECKSTYLE:OFF Cyclomatic complexity is OK
public static void checkMethodModifiers(int modifiers) {

    // Base check
    checkModifiers(METHOD, modifiers);

    // Check overlapping modifiers
    if (Modifier.isPrivate(modifiers)) {
        if (Modifier.isProtected(modifiers) || Modifier.isPublic(modifiers)) {
            throw new IllegalArgumentException(
                    METHOD_ACCESS_MODIFIER_ERROR + " [" + Modifier.toString(modifiers) + ']');
        }
    }
    if (Modifier.isProtected(modifiers)) {
        if (Modifier.isPrivate(modifiers) || Modifier.isPublic(modifiers)) {
            throw new IllegalArgumentException(
                    METHOD_ACCESS_MODIFIER_ERROR + " [" + Modifier.toString(modifiers) + ']');
        }
    }
    if (Modifier.isPublic(modifiers)) {
        if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
            throw new IllegalArgumentException(
                    METHOD_ACCESS_MODIFIER_ERROR + " [" + Modifier.toString(modifiers) + ']');
        }
    }

    // Check illegal abstract modifiers
    if (Modifier.isAbstract(modifiers)) {
        if (Modifier.isPrivate(modifiers) || Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers)
                || Modifier.isNative(modifiers) || Modifier.isStrict(modifiers)
                || Modifier.isSynchronized(modifiers)) {
            throw new IllegalArgumentException(
                    METHOD_ILLEGAL_ABSTRACT_MODIFIERS_ERROR + " [" + Modifier.toString(modifiers) + ']');
        }
    }

    // Check native and strictfp
    if (Modifier.isNative(modifiers) && Modifier.isStrict(modifiers)) {
        throw new IllegalArgumentException(
                METHOD_NATIVE_STRICTFP_ERROR + " [" + Modifier.toString(modifiers) + ']');
    }

}

From source file:org.lightjason.agentspeak.common.CCommon.java

/**
 * reads all methods by the action-annotations
 * for building agent-actions/*from  w w w . j av  a 2s  .c  om*/
 *
 * @param p_class class
 * @param p_root root class
 * @return stream of all methods with inheritance
 */
private static Stream<Method> methods(final Class<?> p_class, final Class<?> p_root) {
    final Pair<Boolean, IAgentAction.EAccess> l_classannotation = CCommon.isActionClass(p_class);
    if (!l_classannotation.getLeft())
        return p_class.getSuperclass() == null ? Stream.of() : methods(p_class.getSuperclass(), p_root);

    final Predicate<Method> l_filter = IAgentAction.EAccess.WHITELIST.equals(l_classannotation.getRight())
            ? i -> !CCommon.isActionFiltered(i, p_root)
            : i -> CCommon.isActionFiltered(i, p_root);

    return Stream.concat(Arrays.stream(p_class.getDeclaredMethods()).parallel().map(i -> {
        i.setAccessible(true);
        return i;
    }).filter(i -> !Modifier.isAbstract(i.getModifiers())).filter(i -> !Modifier.isInterface(i.getModifiers()))
            .filter(i -> !Modifier.isNative(i.getModifiers())).filter(i -> !Modifier.isStatic(i.getModifiers()))
            .filter(l_filter), methods(p_class.getSuperclass(), p_root));
}

From source file:org.apache.openjpa.enhance.PCSubclassValidator.java

private void checkMethodIsSubclassable(Method meth, FieldMetaData fmd) {
    String className = fmd.getDefiningMetaData().getDescribedType().getName();
    if (!(Modifier.isProtected(meth.getModifiers()) || Modifier.isPublic(meth.getModifiers())))
        addError(loc.get("subclasser-private-accessors-unsupported", className, meth.getName()), fmd);
    if (Modifier.isFinal(meth.getModifiers()))
        addError(loc.get("subclasser-final-methods-not-allowed", className, meth.getName()), fmd);
    if (Modifier.isNative(meth.getModifiers()))
        addContractViolation(loc.get("subclasser-native-methods-not-allowed", className, meth.getName()), fmd);
    if (Modifier.isStatic(meth.getModifiers()))
        addError(loc.get("subclasser-static-methods-not-supported", className, meth.getName()), fmd);
}

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));
    }//from   ww  w .ja  v  a  2 s. com
}