sun.reflect.Reflection类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(355)

本文整理了Java中sun.reflect.Reflection类的一些代码示例,展示了Reflection类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reflection类的具体详情如下:
包路径:sun.reflect.Reflection
类名称:Reflection

Reflection介绍

[英]Common utility routines used by both java.lang and java.lang.reflect
[中]java和java使用的通用实用程序例程。语言和java。朗,反思

代码示例

代码示例来源:origin: wildfly/wildfly

public static Class<?> getCallerClass(int n){
  return Reflection.getCallerClass(n);
}

代码示例来源:origin: net.java.openjfx.backport/openjfx-78-backport-compat

if (!Modifier.isPublic(getClassAccessFlags(memberClass))) {
  isSameClassPackage = isSameClassPackage(currentClass, memberClass);
  gotIsSameClassPackage = true;
  if (!isSameClassPackage) {
  if (isSubclassOf(currentClass, memberClass)) {
    successSoFar = true;
    isSameClassPackage = isSameClassPackage(currentClass,
                        memberClass);
    gotIsSameClassPackage = true;
  if (targetClass != currentClass) {
    if (!gotIsSameClassPackage) {
      isSameClassPackage = isSameClassPackage(currentClass, memberClass);
      gotIsSameClassPackage = true;
      if (!isSubclassOf(targetClass, currentClass)) {
        return false;

代码示例来源:origin: io.apisense/rhino-android

public static Method[] filterMethods(Class containingClass, Method[] methods) {
  if (methodFilterMap == null) {
    // Bootstrapping
    return methods;
  }
  return (Method[])filter(methods, methodFilterMap.get(containingClass));
}

代码示例来源:origin: net.java.openjfx.backport/openjfx-78-backport-compat

/** A quick "fast-path" check to try to avoid getCallerClass()
  calls. */
public static boolean quickCheckMemberAccess(Class<?> memberClass,
                       int modifiers)
{
  return Modifier.isPublic(getClassAccessFlags(memberClass) & modifiers);
}

代码示例来源:origin: org.jboss.spec.javax.sql/jboss-javax-sql-api_7.0_spec

Reflection.ensureMemberAccess(currentClass,
               memberClass,
               target,
  Reflection.ensureMemberAccess(currentClass,
                 memberClass,
                 target,
Reflection.ensureMemberAccess(currentClass,
               memberClass,
               target,

代码示例来源:origin: io.apisense/rhino-android

if (!Modifier.isPublic(getClassAccessFlags(memberClass))) {
  isSameClassPackage = isSameClassPackage(currentClass, memberClass);
  gotIsSameClassPackage = true;
  if (!isSameClassPackage) {
  if (isSubclassOf(currentClass, memberClass)) {
    successSoFar = true;
    isSameClassPackage = isSameClassPackage(currentClass,
                        memberClass);
    gotIsSameClassPackage = true;
  if (targetClass != currentClass) {
    if (!gotIsSameClassPackage) {
      isSameClassPackage = isSameClassPackage(currentClass, memberClass);
      gotIsSameClassPackage = true;
      if (!isSubclassOf(targetClass, currentClass)) {
        return false;

代码示例来源:origin: net.java.openjfx.backport/openjfx-78-backport-compat

public static Method[] filterMethods(Class<?> containingClass, Method[] methods) {
  if (methodFilterMap == null) {
    // Bootstrapping
    return methods;
  }
  return (Method[])filter(methods, methodFilterMap.get(containingClass));
}

代码示例来源:origin: io.apisense/rhino-android

/** A quick "fast-path" check to try to avoid getCallerClass()
  calls. */
public static boolean quickCheckMemberAccess(Class memberClass,
                       int modifiers)
{
  return Modifier.isPublic(getClassAccessFlags(memberClass) & modifiers);
}

代码示例来源:origin: net.java.openjfx.backport/openjfx-78-backport-compat

Reflection.ensureMemberAccess(currentClass,
               memberClass,
               target,
  Reflection.ensureMemberAccess(currentClass,
                 memberClass,
                 target,
Reflection.ensureMemberAccess(currentClass,
               memberClass,
               target,

代码示例来源:origin: btraceio/btrace

/**
 * Returns the Class object of the currently
 * probed (or traced) class.
 * @deprecated Since 1.1. Use {@linkplain ProbeClassName} and {@linkplain Self} annotations instead
 */
@Deprecated
public static Class probeClass() {
  return Reflection.getCallerClass(STACK_DEC);
}

代码示例来源:origin: io.apisense/rhino-android

public static Field[] filterFields(Class containingClass,
                  Field[] fields) {
  if (fieldFilterMap == null) {
    // Bootstrapping
    return fields;
  }
  return (Field[])filter(fields, fieldFilterMap.get(containingClass));
}

代码示例来源:origin: btraceio/btrace

@CallerSensitive
public Class defineClass(byte[] code) {
  Class caller = isNewerThan8 ? Reflection.getCallerClass() : Reflection.getCallerClass(2);
  if (! caller.getName().startsWith("com.sun.btrace.")) {
    throw new SecurityException("unsafe defineClass");
  }
  return defineClassImpl(code, true);
}

代码示例来源:origin: net.java.openjfx.backport/openjfx-78-backport-compat

public static Field[] filterFields(Class<?> containingClass,
                  Field[] fields) {
  if (fieldFilterMap == null) {
    // Bootstrapping
    return fields;
  }
  return (Field[])filter(fields, fieldFilterMap.get(containingClass));
}

代码示例来源:origin: btraceio/btrace

/**
 * Returns Class object for given class name.
 */
public static Class classForName(String name) {
  ClassLoader callerLoader = Reflection.getCallerClass(STACK_DEC).getClassLoader();
  return classForName(name, callerLoader);
}

代码示例来源:origin: btraceio/btrace

@CallerSensitive
public Class defineClass(byte[] code, boolean mustBeBootstrap) {
  Class caller = isNewerThan8 ? Reflection.getCallerClass() : Reflection.getCallerClass(2);
  if (! caller.getName().startsWith("com.sun.btrace.")) {
    throw new SecurityException("unsafe defineClass");
  }
  return defineClassImpl(code, mustBeBootstrap);
}

代码示例来源:origin: btraceio/btrace

@CallerSensitive
public static void init(PerfReader perfRead) {
  initUnsafe();
  Class caller = isNewerThan8 ? Reflection.getCallerClass() : Reflection.getCallerClass(2);
  if (! caller.getName().equals("com.sun.btrace.agent.Client")) {
    throw new SecurityException("unsafe init");
  }
  perfReader = perfRead;
  loadLibrary(perfRead.getClass().getClassLoader());
}

代码示例来源:origin: btraceio/btrace

/**
 * Returns a <code>Field</code> object that reflects the specified declared
 * field of the class or interface represented by the given <code>Class</code>
 * object. The <code>name</code> parameter is a <code>String</code> that
 * specifies the simple name of the desired field. Throws a <code>RuntimeException</code>
 * when field is not found.
 *
 * @param clazz Class whose field is returned
 * @param name the name of the field
 * @return the <code>Field</code> object for the specified field in this
 * class
 */
public static Field field(String clazz, String name) {
  ClassLoader callerLoader = Reflection.getCallerClass(STACK_DEC).getClassLoader();
  return Reflective.field(classForName(clazz, callerLoader), name);
}

代码示例来源:origin: btraceio/btrace

/**
 * Returns a <code>Field</code> object that reflects the specified declared
 * field of the class or interface represented by the given <code>Class</code>
 * object. The <code>name</code> parameter is a <code>String</code> that
 * specifies the simple name of the desired field. Throws a <code>RuntimeException</code>
 * when field is not found.
 *
 * @param clazz Class whose field is returned
 * @param name the name of the field
 * @return the <code>Field</code> object for the specified field in this
 * class
 */
public static Field field(String clazz, String name) {
  ClassLoader callerLoader = Reflection.getCallerClass(STACK_DEC).getClassLoader();
  return field(classForName(clazz, callerLoader), name);
}

代码示例来源:origin: btraceio/btrace

/**
 * Returns a <code>Field</code> object that reflects the specified declared
 * field of the class or interface represented by the given <code>Class</code>
 * object. The <code>name</code> parameter is a <code>String</code> that
 * specifies the simple name of the desired field. Returns <code>null</code> on not finding
 * field if throwException parameter is <code>false</code>. Else throws a <code>RuntimeException</code>
 * when field is not found.
 *
 * @param clazz Class whose field is returned
 * @param name the name of the field
 * @param throwException whether to throw exception on failing to find field or not
 * @return the <code>Field</code> object for the specified field in this
 * class
 */
public static Field field(String clazz, String name, boolean throwException) {
  ClassLoader callerLoader = Reflection.getCallerClass(STACK_DEC).getClassLoader();
  return Reflective.field(classForName(clazz, callerLoader), name, throwException);
}

代码示例来源:origin: btraceio/btrace

/**
 * Returns a <code>Field</code> object that reflects the specified declared
 * field of the class or interface represented by the given <code>Class</code>
 * object. The <code>name</code> parameter is a <code>String</code> that
 * specifies the simple name of the desired field. Returns <code>null</code> on not finding
 * field if throwException parameter is <code>false</code>. Else throws a <code>RuntimeException</code>
 * when field is not found.
 *
 * @param clazz Class whose field is returned
 * @param name the name of the field
 * @param throwException whether to throw exception on failing to find field or not
 * @return the <code>Field</code> object for the specified field in this
 * class
 */
public static Field field(String clazz, String name, boolean throwException) {
  ClassLoader callerLoader = Reflection.getCallerClass(STACK_DEC).getClassLoader();
  return field(classForName(clazz, callerLoader), name, throwException);
}

相关文章