Example usage for java.lang.reflect Member getModifiers

List of usage examples for java.lang.reflect Member getModifiers

Introduction

In this page you can find the example usage for java.lang.reflect Member getModifiers.

Prototype

public int getModifiers();

Source Link

Document

Returns the Java language modifiers for the member or constructor represented by this Member, as an integer.

Usage

From source file:org.opoo.util.ClassUtils.java

public static boolean isPublic(Class clazz, Member member) {
    return Modifier.isPublic(member.getModifiers()) && Modifier.isPublic(clazz.getModifiers());
}

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

/***********************************************************************************************
 * Show the Member Modifiers./* www. j  ava 2s  . co  m*/
 *
 * @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:org.hibernate.internal.util.ReflectHelper.java

/**
 * Is this member publicly accessible.//from w ww  .  j a  va 2  s. c  o m
 *
 * @param clazz The class which defines the member
 * @param member The memeber.
 * @return True if the member is publicly accessible, false otherwise.
 */
public static boolean isPublic(Class clazz, Member member) {
    return Modifier.isPublic(member.getModifiers()) && Modifier.isPublic(clazz.getModifiers());
}

From source file:io.fabric8.cxf.endpoint.BeanValidationAnnotationIntrospector.java

@Override
public boolean hasIgnoreMarker(AnnotatedMember m) {
    Member member = m.getMember();
    int modifiers = member.getModifiers();
    if (Modifier.isTransient(modifiers)) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Ignoring transient member " + m);
        }// w  w w .  j  a va2  s  .  c  o m
        return true;
    } else if (m instanceof AnnotatedMethod) {
        AnnotatedMethod method = (AnnotatedMethod) m;
        String methodName = method.getName();
        // lets see if there is a transient field of the same name as the getter
        if (methodName.startsWith("get") && method.getParameterCount() == 0) {
            String fieldName = Introspector.decapitalize(methodName.substring(3));
            Class<?> declaringClass = method.getDeclaringClass();
            Field field = findField(fieldName, declaringClass);
            if (field != null) {
                int fieldModifiers = field.getModifiers();
                if (Modifier.isTransient(fieldModifiers)) {
                    LOG.fine("Ignoring member " + m + " due to transient field called " + fieldName);
                    return true;
                }
            }
        }
    }
    return super.hasIgnoreMarker(m);

}

From source file:com.link_intersystems.lang.reflect.MemberModifierPredicate.java

/**
 * {@inheritDoc}//  w  w w  .j a va  2  s . co m
 *
 * @return true if the object evaluated against is a {@link Member} and that
 *         {@link Member}s modifiers match the modifiers that this
 *         {@link MemberModifierPredicate} was constructed with according to
 *         the {@link Match} type.
 * @param object
 *            must be a {@link Member}.
 * @since 1.0.0.0
 * @throws IllegalArgumentException
 *             if the object this {@link Predicate} is evaluated against is
 *             not a {@link Member}.
 */
public boolean evaluate(Member object) {
    Member member = (Member) object;
    int modifiers = member.getModifiers();
    if (match.equals(Match.EXACT)) {
        return this.modifiers == modifiers;
    } else if (match.equals(Match.AT_LEAST_ONE)) {
        return (modifiers & this.modifiers) != 0;
    } else {
        return (modifiers & this.modifiers) == this.modifiers;
    }
}

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

@Test
public void usingFilterTest() {
    memberCriteria.membersOfType(Method.class);
    memberCriteria.add(new ToStringPredicate());
    ClassCriteria classCriteria = new ClassCriteria();
    Iterable<Class<?>> classIterable = classCriteria.getIterable(Object.class);
    Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable);
    Iterator<Member> iterator = memberIterable.iterator();
    assertTrue(iterator.hasNext());/*from w  w w . j a  v  a2 s  .c o  m*/
    Member member = iterator.next();
    int modifiers = member.getModifiers();
    assertTrue(Modifier.isPublic(modifiers));
    assertFalse(iterator.hasNext());
}

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

@Test
public void publicMethods() {
    memberCriteria.membersOfType(Method.class);
    memberCriteria.withAccess(AccessType.PUBLIC);
    ClassCriteria classCriteria = new ClassCriteria();
    Iterable<Class<?>> classIterable = classCriteria.getIterable(ArrayList.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();
        assertTrue(Modifier.isPublic(modifiers));
        assertFalse(Modifier.isProtected(modifiers));
        assertFalse(Modifier.isPrivate(modifiers));
    }//from ww  w . j a  va  2  s  . com
}

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

@Test
public void defaultAccessMethods() {
    memberCriteria.membersOfType(Method.class);
    memberCriteria.withAccess(AccessType.DEFAULT);
    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));
    }//from   w  ww.  j  a  v a  2 s . c  o m
}

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

@Test
public void privateStaticFields() {
    memberCriteria.membersOfType(Field.class);
    memberCriteria.withAccess(AccessType.PRIVATE);
    memberCriteria.withModifiers(Modifier.STATIC);
    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 field", member instanceof Field);
        int modifiers = member.getModifiers();
        assertFalse(Modifier.isPublic(modifiers));
        assertFalse(Modifier.isProtected(modifiers));
        assertTrue(Modifier.isPrivate(modifiers));
        assertTrue(Modifier.isStatic(modifiers));
    }//from  ww  w .j  ava2s .  c om
}

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));
    }// ww w  .ja  va2  s .  c  o m
}