Example usage for java.lang.reflect Member getDeclaringClass

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

Introduction

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

Prototype

public Class<?> getDeclaringClass();

Source Link

Document

Returns the Class object representing the class or interface that declares the member or constructor represented by this Member.

Usage

From source file:Main.java

public static String getDeclaringTypeString(final Member m) {
    if (m == null) {
        return " null ";
    }/* www .  j  av a  2s  .  co m*/

    return m.getDeclaringClass().getName();
}

From source file:Util.java

/**
 * Returns true if a Member is accessible via reflection under normal Java access
 * controls./*from w  w w. ja v  a2  s  .  c om*/
 * 
 * @since 1.2
 */
public static boolean isAccessible(Member member) {
    return Modifier.isPublic(member.getModifiers())
            && Modifier.isPublic(member.getDeclaringClass().getModifiers());
}

From source file:org.robobinding.util.MemberUtils.java

/**
 * /*from w  w w  .ja v a  2  s .  c  o m*/
 * When a public class has a default access superclass with public members,
 * these members are accessible. Calling them from compiled code works fine.
 * Unfortunately, on some JVMs, using reflection to invoke these members
 * seems to (wrongly) prevent access even when the modifier is public.
 * Calling setAccessible(true) solves the problem but will only work from
 * sufficiently privileged code. Better workarounds would be gratefully
 * accepted.
 * 
 * @param o
 *            the AccessibleObject to set as accessible
 */
static void setAccessibleWorkaround(final AccessibleObject o) {
    if (o == null || o.isAccessible()) {
        return;
    }
    final Member m = (Member) o;
    if (Modifier.isPublic(m.getModifiers()) && isPackageAccess(m.getDeclaringClass().getModifiers())) {
        try {
            o.setAccessible(true);
        } catch (final SecurityException e) { // NOPMD
            // ignore in favor of
            // subsequent
            // IllegalAccessException
        }
    }
}

From source file:org.apache.bval.util.reflection.Reflection.java

/**
 * Set the accessibility of {@code o} to {@code accessible}. If running without a {@link SecurityManager}
 * and {@code accessible == false}, this call is ignored (because any code could reflectively make any
 * object accessible at any time)./*from w ww . jav a 2 s  . c  om*/
 * @param o
 * @param accessible
 * @return whether a change was made.
 */
public static boolean setAccessible(final AccessibleObject o, boolean accessible) {
    if (o == null || o.isAccessible() == accessible) {
        return false;
    }
    if (!accessible && System.getSecurityManager() == null) {
        return false;
    }
    final Member m = (Member) o;

    // For public members whose declaring classes are public, we need do nothing:
    if (Modifier.isPublic(m.getModifiers()) && Modifier.isPublic(m.getDeclaringClass().getModifiers())) {
        return false;
    }
    o.setAccessible(accessible);
    return true;
}

From source file:Main.java

public static void checkAndFixAccess(Member paramMember) {
    AccessibleObject localAccessibleObject = (AccessibleObject) paramMember;
    try {/*w  ww.ja va  2  s. com*/
        localAccessibleObject.setAccessible(true);
        return;
    } catch (SecurityException localSecurityException) {
        while (localAccessibleObject.isAccessible())
            ;
        Class localClass = paramMember.getDeclaringClass();
        throw new IllegalArgumentException("Can not access " + paramMember + " (from class "
                + localClass.getName() + "; failed to set access: " + localSecurityException.getMessage());
    }
}

From source file:org.dozer.classmap.ClassMapBuilder.java

private static void validate(Mapping annotation, Member member) {
    if (annotation.value().trim().equals("")) {
        throw new MappingException("Mapping annotation value missing at " + member.getDeclaringClass().getName()
                + "." + member.getName());
    }//  www.ja va  2s.c o  m
}

From source file:IntrospectionUtil.java

public static boolean isInheritable(Package pack, Member member) {
    if (pack == null)
        return false;
    if (member == null)
        return false;

    int modifiers = member.getModifiers();
    if (Modifier.isPublic(modifiers))
        return true;
    if (Modifier.isProtected(modifiers))
        return true;
    if (!Modifier.isPrivate(modifiers) && pack.equals(member.getDeclaringClass().getPackage()))
        return true;

    return false;
}

From source file:org.hibernate.internal.util.ReflectHelper.java

/**
 * Is this member publicly accessible./*  www  .  j a  va  2 s . com*/
 * <p/>
 * Short-hand for {@link #isPublic(Class, Member)} passing the member + {@link Member#getDeclaringClass()}
 *
 * @param member The member to check
 * @return True if the member is publicly accessible.
 */
public static boolean isPublic(Member member) {
    return isPublic(member.getDeclaringClass(), member);
}

From source file:org.dhatim.cdr.annotation.Configurator.java

private static String getLongMemberName(Member field) {
    return field.getDeclaringClass().getName() + "#" + field.getName();
}

From source file:org.batoo.common.reflect.ReflectHelper.java

/**
 * Returns the qualified name for the member.
 * /*w  ww  .  j  ava2 s .c  o m*/
 * @param member
 *            the member to qualify
 * @return the qualified name for the member
 * 
 * @since 2.0.1
 */
public static String createMemberName(Member member) {
    return member.getDeclaringClass().getName() + "." + member.getName();
}