当前位置: 首页>>代码示例>>Java>>正文


Java AccessibleObject类代码示例

本文整理汇总了Java中java.lang.reflect.AccessibleObject的典型用法代码示例。如果您正苦于以下问题:Java AccessibleObject类的具体用法?Java AccessibleObject怎么用?Java AccessibleObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AccessibleObject类属于java.lang.reflect包,在下文中一共展示了AccessibleObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setAndGetAccessible

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
/**
 * 放回一个可以访问的字段或者方法
 *
 */
public static <T extends AccessibleObject> T setAndGetAccessible(T accessible) {
	if (accessible == null) {
		return null;
	}

	if (accessible instanceof Member) {
		Member member = (Member) accessible;

		if (Modifier.isPublic(member.getModifiers())
				&& Modifier.isPublic(member.getDeclaringClass().getModifiers())) {

			return accessible;
		}
	}

	if (!accessible.isAccessible()) {
		accessible.setAccessible(true);
	}

	return accessible;
}
 
开发者ID:variflight,项目名称:feeyo-redisproxy,代码行数:26,代码来源:ReflectUtil.java

示例2: 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;
}
 
开发者ID:zkwlx,项目名称:DroidTelescope,代码行数:17,代码来源:MemberUtils.java

示例3: cloneFields

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
protected void cloneFields(Class<? extends WizardControl> clazz, WizardControl control)
{
	Field[] declaredFields = clazz.getDeclaredFields();
	AccessibleObject.setAccessible(declaredFields, true);
	for( Field field : declaredFields )
	{
		try
		{
			if( (field.getModifiers() & (Modifier.STATIC | Modifier.FINAL)) == 0 )
			{
				field.set(control, field.get(this));
			}
		}
		catch( Exception e )
		{
			throw new RuntimeException(e);
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:20,代码来源:WizardControl.java

示例4: reflectionAppend

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
/**
 * <p>Appends the fields and values defined by the given object of the
 * given Class.</p>
 * 
 * @param lhs  the left hand object
 * @param rhs  the right hand object
 * @param clazz  the class to append details of
 * @param builder  the builder to append to
 * @param useTransients  whether to test transient fields
 * @param excludeFields  array of field names to exclude from testing
 */
private static void reflectionAppend(
    Object lhs,
    Object rhs,
    Class clazz,
    EqualsBuilder builder,
    boolean useTransients,
    String[] excludeFields) {
    Field[] fields = clazz.getDeclaredFields();
    AccessibleObject.setAccessible(fields, true);
    for (int i = 0; i < fields.length && builder.isEquals; i++) {
        Field f = fields[i];
        if (!ArrayUtils.contains(excludeFields, f.getName())
            && (f.getName().indexOf('$') == -1)
            && (useTransients || !Modifier.isTransient(f.getModifiers()))
            && (!Modifier.isStatic(f.getModifiers()))) {
            try {
                builder.append(f.get(lhs), f.get(rhs));
            } catch (IllegalAccessException e) {
                //this can't happen. Would get a Security exception instead
                //throw a runtime exception in case the impossible happens.
                throw new InternalError("Unexpected IllegalAccessException");
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:EqualsBuilder.java

示例5: getClassLoader

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
/**
 * Enable sharing of the class-loader with 3rd party.
 *
 * @return the class-loader user be the helper.
 */
public ClassLoader getClassLoader() {
    // To follow the same behavior of Class.forName(...) I had to play
    // dirty (Supported by Sun, IBM & BEA JVMs)
    try {
        // Get a reference to this class' class-loader
        ClassLoader cl = this.getClass().getClassLoader();
        // Create a method instance representing the protected
        // getCallerClassLoader method of class ClassLoader
        Method mthd = ClassLoader.class.getDeclaredMethod(
                "getCallerClassLoader", new Class<?>[0]);
        // Make the method accessible.
        AccessibleObject.setAccessible(new AccessibleObject[] {mthd}, true);
        // Try to get the caller's class-loader
        return (ClassLoader)mthd.invoke(cl, new Object[0]);
    } catch (Throwable all) {
        // Use this class' class-loader
        return this.getClass().getClassLoader();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:SimpleClassLoadHelper.java

示例6: getClassLoader

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
/**
 * Enable sharing of the class-loader with 3rd party.
 *
 * @return the class-loader user be the helper.
 */
public ClassLoader getClassLoader() {
    // To follow the same behavior of Class.forName(...) I had to play
    // dirty (Supported by Sun, IBM & BEA JVMs)
    try {
        // Get a reference to this class' class-loader
        ClassLoader cl = this.getClass().getClassLoader();
        // Create a method instance representing the protected
        // getCallerClassLoader method of class ClassLoader
        Method mthd = ClassLoader.class.getDeclaredMethod(
                "getCallerClassLoader", new Class[0]);
        // Make the method accessible.
        AccessibleObject.setAccessible(new AccessibleObject[] {mthd}, true);
        // Try to get the caller's class-loader
        return (ClassLoader)mthd.invoke(cl, new Object[0]);
    } catch (Exception all) {
        // Use this class' class-loader
        return this.getClass().getClassLoader();
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:25,代码来源:SimpleClassLoadHelper.java

示例7: checkAccess

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
public static void checkAccess(AccessibleObject accessibleObject, Object obj)
    throws IllegalAccessException,
           InvocationTargetException,
           InstantiationException
{
    if (accessibleObject instanceof Field) {
        Field field = (Field) accessibleObject;
        field.set(obj, 42);
        field.get(obj);
    } else if (accessibleObject instanceof Method) {
        Method method = (Method) accessibleObject;
        method.invoke(obj);
    } else if (accessibleObject instanceof Constructor) {
        Constructor<?> constructor = (Constructor<?>) accessibleObject;
        Object[] params = new Object[constructor.getParameterCount()];
        constructor.newInstance(params);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:PublicSuper.java

示例8: getReadMember

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
Member getReadMember(Class targetClass) throws NameNotFoundException {
  // mapping: public field (same name), method (getAttribute()),
  // method (attribute())
  List key = new ArrayList();
  key.add(targetClass);
  key.add(_name);

  Member m = (Member) _cache.get(key);
  if (m != null)
    return m;

  m = getReadField(targetClass);
  if (m == null)
    m = getReadMethod(targetClass);
  if (m != null)
    _cache.putIfAbsent(key, m);
  else
    throw new NameNotFoundException(
        LocalizedStrings.AttributeDescriptor_NO_PUBLIC_ATTRIBUTE_NAMED_0_WAS_FOUND_IN_CLASS_1
            .toLocalizedString(new Object[] {_name, targetClass.getName()}));
  // override security for nonpublic derived classes with public members
  ((AccessibleObject) m).setAccessible(true);
  return m;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:25,代码来源:AttributeDescriptor.java

示例9: setAccessibility

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
public static void setAccessibility(boolean b) {
    if (!b) {
        accessibility = false;
    } else {
        String.class.getDeclaredMethods(); // test basic access
        try {
            final AccessibleObject member = String.class.getDeclaredField("value");
            member.setAccessible(true);
            member.setAccessible(false);
        } catch (NoSuchFieldException e) {
            // ignore
        }
        accessibility = true;
    }
    KrineClassManager.clearResolveCache();
}
 
开发者ID:imkiva,项目名称:Krine,代码行数:17,代码来源:Capabilities.java

示例10: getParameterNames

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
private String[] getParameterNames(AccessibleObject a, String name, Class<?>[] types, String raw) {
    if (types.length == 0)
        return new String[0];

    StringBuilder regex = new StringBuilder();
    regex.append(format(">\\Q%s\\E</A></(?:B|strong)>\\(", name));
    for (Class<?> klass : types) {
        regex.append(format(
                ",?\\s*(?:<A[^>]+>)?[\\w.]*\\Q%s\\E(?:</A>)?(?:&lt;[^&]+&gt;)?&nbsp;([^),\\s]+)",
                klass.getSimpleName()
        ));
    }
    regex.append(format("\\)</CODE>"));

    Pattern pattern = Pattern.compile(regex.toString(), Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(raw);

    if (!matcher.find())
        throw new ParameterNamesNotFoundException(a + ", " + regex);

    String[] names = new String[types.length];
    for (int i = 0 ; i < names.length ; i++)
        names[i] = matcher.group(1 + i).trim();

    return names;
}
 
开发者ID:Yoio,项目名称:X4J,代码行数:27,代码来源:JavadocParanamer.java

示例11: annotatedName

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
private static String annotatedName(AccessibleObject obj) {
  if (obj.isAnnotationPresent(PropertyName.class)) {
    PropertyName annotation = obj.getAnnotation(PropertyName.class);
    return annotation.value();
  }

  return null;
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:9,代码来源:CustomClassMapper.java

示例12: lookupParameterNames

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
public String[] lookupParameterNames(AccessibleObject methodOrCtor, boolean throwExceptionIfMissing) {
    for (int i = 0; i < paranamers.length; i++) {
        Paranamer paranamer = paranamers[i];
        String[] names = paranamer.lookupParameterNames(methodOrCtor, i+1 < paranamers.length ? false : throwExceptionIfMissing);
        if (names != Paranamer.EMPTY_NAMES) {
            return names;
        }
    }
    return Paranamer.EMPTY_NAMES;
}
 
开发者ID:Yoio,项目名称:X4J,代码行数:11,代码来源:AdaptiveParanamer.java

示例13: MethodIntrospector

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
public MethodIntrospector(AccessibleObject methodOrCtor) {
    super();
    this.methodOrCtor = methodOrCtor;
    this.classes = getClasses(methodOrCtor);
    this.types = getGenericParameterTypes(methodOrCtor);
    this.names = getParameterNames(methodOrCtor);
    this.parameterDescriptions = mergeToParameters(names, types);

}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:10,代码来源:MethodIntrospector.java

示例14: getJpaAnnotatedMembers

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
public List<AccessibleObject> getJpaAnnotatedMembers(Class<?> c, Class<? extends Annotation> annotation) {
    final List<AccessibleObject> jpaAnnotated = new ArrayList<AccessibleObject>();
    for (Class<?> cl = c; cl != Object.class && cl != null; cl = cl.getSuperclass()) {
        parseClass(annotation, jpaAnnotated, cl);
    }
    return jpaAnnotated;
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:8,代码来源:AnnotationScanner.java

示例15: lookupParameterNames

import java.lang.reflect.AccessibleObject; //导入依赖的package包/类
public String[] lookupParameterNames(AccessibleObject methodOrCtor, boolean throwExceptionIfMissing) {
    String[] names = methodCache.get(methodOrCtor);
    // refer PARANAMER-19
    if(names == null) {
        names = delegate.lookupParameterNames(methodOrCtor, throwExceptionIfMissing);
        methodCache.put(methodOrCtor, names);
    }
    return names;
}
 
开发者ID:Yoio,项目名称:X4J,代码行数:10,代码来源:CachingParanamer.java


注:本文中的java.lang.reflect.AccessibleObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。