本文整理汇总了Java中java.lang.reflect.AccessibleObject.isAccessible方法的典型用法代码示例。如果您正苦于以下问题:Java AccessibleObject.isAccessible方法的具体用法?Java AccessibleObject.isAccessible怎么用?Java AccessibleObject.isAccessible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.AccessibleObject
的用法示例。
在下文中一共展示了AccessibleObject.isAccessible方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setAccessibleWorkaround
import java.lang.reflect.AccessibleObject; //导入方法依赖的package包/类
static boolean setAccessibleWorkaround(final AccessibleObject o) {
if (o == null || o.isAccessible()) {
return false;
}
final Member m = (Member) o;
if (!o.isAccessible() && Modifier.isPublic(m.getModifiers()) && isPackageAccess(m
.getDeclaringClass().getModifiers())) {
try {
o.setAccessible(true);
return true;
} catch (final SecurityException e) { // NOPMD
// ignore in favor of subsequent IllegalAccessException
}
}
return false;
}
示例2: tryToMakeAccessible
import java.lang.reflect.AccessibleObject; //导入方法依赖的package包/类
@Override
protected boolean tryToMakeAccessible(Object accessibleObject)
{
if (!(accessibleObject instanceof AccessibleObject)) {
return false;
}
AccessibleObject accessible = (AccessibleObject)accessibleObject;
if (accessible.isAccessible()) {
return true;
}
try {
accessible.setAccessible(true);
} catch (Exception ex) { }
return accessible.isAccessible();
}
示例3: setAccessible
import java.lang.reflect.AccessibleObject; //导入方法依赖的package包/类
static void setAccessible(AccessibleObject obj){
if(!setAccessibleEnable){
return;
}
if(obj.isAccessible()){
return;
}
try{
obj.setAccessible(true);
} catch(AccessControlException error){
setAccessibleEnable = false;
}
}
示例4: tryToMakeAccessible
import java.lang.reflect.AccessibleObject; //导入方法依赖的package包/类
@Override
protected boolean tryToMakeAccessible(AccessibleObject accessible)
{
if (accessible.isAccessible()) {
return true;
}
try {
accessible.setAccessible(true);
} catch (Exception ex) { }
return accessible.isAccessible();
}
示例5: setAccessibleWorkaround
import java.lang.reflect.AccessibleObject; //导入方法依赖的package包/类
/**
* XXX Default access superclass workaround
*
* 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) to prevent access even when the modifer 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(AccessibleObject o) {
if (o == null || o.isAccessible()) {
return;
}
Member m = (Member) o;
if (Modifier.isPublic(m.getModifiers())
&& isPackageAccess(m.getDeclaringClass().getModifiers())) {
try {
o.setAccessible(true);
} catch (SecurityException e) {
// ignore in favor of subsequent IllegalAccessException
}
}
}
示例6: setAccessibleWorkaround
import java.lang.reflect.AccessibleObject; //导入方法依赖的package包/类
static boolean setAccessibleWorkaround(final AccessibleObject o) {
if (o == null || o.isAccessible()) {
return false;
}
final Member m = (Member) o;
if (!o.isAccessible() && Modifier.isPublic(m.getModifiers()) && isPackageAccess(m.getDeclaringClass().getModifiers())) {
try {
o.setAccessible(true);
return true;
} catch (final SecurityException e) { // NOPMD
// ignore in favor of subsequent IllegalAccessException
}
}
return false;
}
示例7: setAccessible
import java.lang.reflect.AccessibleObject; //导入方法依赖的package包/类
static void setAccessible(AccessibleObject obj) {
if (setAccessibleEnable && !obj.isAccessible()) {
try {
obj.setAccessible(true);
} catch (AccessControlException e) {
setAccessibleEnable = false;
}
}
}
示例8: makeAccessible
import java.lang.reflect.AccessibleObject; //导入方法依赖的package包/类
protected static void makeAccessible(AccessibleObject object) {
if (!object.isAccessible()) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
object.setAccessible(true);
return null;
});
}
}
示例9: setAccessible
import java.lang.reflect.AccessibleObject; //导入方法依赖的package包/类
static void setAccessible(AccessibleObject obj) {
if (!setAccessibleEnable) {
return;
}
if (obj.isAccessible()) {
return;
}
try {
obj.setAccessible(true);
} catch (AccessControlException error) {
setAccessibleEnable = false;
}
}
示例10: getDataMutator
import java.lang.reflect.AccessibleObject; //导入方法依赖的package包/类
/** Returns the Field object, if available, or the setter Method, corresponding to the input dataFieldName.
* @param dataFieldName the name of the data field.
* @return the Field object, if available, or the setter Method, corresponding to the input dataFieldName.
*/
public AccessibleObject getDataMutator(String dataFieldName) {
AccessibleObject accessibleObject = containsDataField(dataFieldName) ? elementMap.get(dataFieldName).getGraphField() : null;
if (accessibleObject == null) {
PropertyDescriptor pd = getDataFieldDescriptor(dataFieldName);
if (pd != null) {
accessibleObject = pd.getWriteMethod();
if (!accessibleObject.isAccessible())
accessibleObject.setAccessible(true);
}
}
return accessibleObject;
}
示例11: setAccessibleWorkaround
import java.lang.reflect.AccessibleObject; //导入方法依赖的package包/类
/**
* XXX Default access superclass workaround
* <p>
* 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(AccessibleObject o) {
if (o == null || o.isAccessible()) {
return;
}
Member m = (Member) o;
if (Modifier.isPublic(m.getModifiers())
&& isPackageAccess(m.getDeclaringClass().getModifiers())) {
try {
o.setAccessible(true);
} catch (SecurityException e) { // NOPMD
// ignore in favor of subsequent IllegalAccessException
}
}
}
示例12: setAccessible
import java.lang.reflect.AccessibleObject; //导入方法依赖的package包/类
public static void setAccessible(AccessibleObject ao, boolean value) {
if (ao.isAccessible() != value) {
ao.setAccessible(value);
}
}