List of usage examples for java.lang.reflect Member getModifiers
public int getModifiers();
From source file:org.apache.brooklyn.util.javalang.MethodAccessibleReflections.java
static boolean isAccessible(Member m) { return m != null && Modifier.isPublic(m.getModifiers()); }
From source file:org.robobinding.util.MemberUtils.java
/** * Returns whether a Member is accessible. * /* w w w . j ava 2 s .c o m*/ * @param m * Member to check * @return true if <code>m</code> is accessible */ static boolean isAccessible(final Member m) { return m != null && Modifier.isPublic(m.getModifiers()) && !m.isSynthetic(); }
From source file:org.robobinding.util.MemberUtils.java
/** * //from w w w .j a va 2s .co 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.jdto.util.MemberUtils.java
/** * Check a Member for basic accessibility. * * @param m Member to check/*from w w w.j a v a 2 s.c o m*/ * @return true if * <code>m</code> is accessible */ static boolean isAccessible(Member m) { return m != null && Modifier.isPublic(m.getModifiers()) && !isSynthetic(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.compass.core.util.reflection.ReflectionFactory.java
private static boolean canGenerateAsm(Member member) { // we can only generate for members that are not private (so we can set them) // and that the class is public and not static (i.e. not intenral class within another class) return !Modifier.isPrivate(member.getModifiers()); }
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)./* ww w .j ava 2 s . com*/ * @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:ShowClass.java
public static void printMethodOrConstructor(Member member) { Class returntype = null, parameters[], exceptions[]; if (member instanceof Method) { Method m = (Method) member; returntype = m.getReturnType();/*from w ww . ja v a 2 s.c o m*/ parameters = m.getParameterTypes(); exceptions = m.getExceptionTypes(); System.out.print( " " + modifiers(member.getModifiers()) + typeName(returntype) + " " + member.getName() + "("); } else { Constructor c = (Constructor) member; parameters = c.getParameterTypes(); exceptions = c.getExceptionTypes(); System.out.print(" " + modifiers(member.getModifiers()) + typeName(c.getDeclaringClass()) + "("); } for (int i = 0; i < parameters.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typeName(parameters[i])); } System.out.print(")"); if (exceptions.length > 0) System.out.print(" throws "); for (int i = 0; i < exceptions.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typeName(exceptions[i])); } System.out.println(";"); }
From source file:Main.java
public static void print_method_or_constructor(Member member) { Class returntype = null, parameters[], exceptions[]; if (member instanceof Method) { Method m = (Method) member; returntype = m.getReturnType();/*from w w w . j a v a 2s .c om*/ parameters = m.getParameterTypes(); exceptions = m.getExceptionTypes(); System.out.print( " " + modifiers(member.getModifiers()) + typename(returntype) + " " + member.getName() + "("); } else { Constructor c = (Constructor) member; parameters = c.getParameterTypes(); exceptions = c.getExceptionTypes(); System.out.print(" " + modifiers(member.getModifiers()) + typename(c.getDeclaringClass()) + "("); } for (int i = 0; i < parameters.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typename(parameters[i])); } System.out.print(")"); if (exceptions.length > 0) System.out.print(" throws "); for (int i = 0; i < exceptions.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typename(exceptions[i])); } System.out.println(";"); }
From source file:ShowClass.java
/** * Print the modifiers, return type, name, parameter types and exception type * of a method or constructor. Note the use of the Member interface to allow * this method to work with both Method and Constructor objects *//*ww w . j a va 2s .c om*/ public static void print_method_or_constructor(Member member) { Class returntype = null, parameters[], exceptions[]; if (member instanceof Method) { Method m = (Method) member; returntype = m.getReturnType(); parameters = m.getParameterTypes(); exceptions = m.getExceptionTypes(); System.out.print( " " + modifiers(member.getModifiers()) + typename(returntype) + " " + member.getName() + "("); } else { Constructor c = (Constructor) member; parameters = c.getParameterTypes(); exceptions = c.getExceptionTypes(); System.out.print(" " + modifiers(member.getModifiers()) + typename(c.getDeclaringClass()) + "("); } for (int i = 0; i < parameters.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typename(parameters[i])); } System.out.print(")"); if (exceptions.length > 0) System.out.print(" throws "); for (int i = 0; i < exceptions.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typename(exceptions[i])); } System.out.println(";"); }