當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。