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


Java Member.getDeclaringClass方法代码示例

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


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

示例1: conservativeCheckMemberAccess

import java.lang.reflect.Member; //导入方法依赖的package包/类
/**
 * Does a conservative approximation of member access check. Use this if
 * you don't have an actual 'userland' caller Class/ClassLoader available.
 * This might be more restrictive than a precise member access check where
 * you have a caller, but should never allow a member access that is
 * forbidden.
 *
 * @param m the {@code Member} about to be accessed
 */
public static void conservativeCheckMemberAccess(Member m) throws SecurityException{
    final SecurityManager sm = System.getSecurityManager();
    if (sm == null)
        return;

    // Check for package access on the declaring class.
    //
    // In addition, unless the member and the declaring class are both
    // public check for access declared member permissions.
    //
    // This is done regardless of ClassLoader relations between the {@code
    // Member m} and any potential caller.

    final Class<?> declaringClass = m.getDeclaringClass();

    checkPackageAccess(declaringClass);

    if (Modifier.isPublic(m.getModifiers()) &&
            Modifier.isPublic(declaringClass.getModifiers()))
        return;

    // Check for declared member access.
    sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:ReflectUtil.java

示例2: isAccessible

import java.lang.reflect.Member; //导入方法依赖的package包/类
boolean isAccessible(final Member m) {
    final Class<?> declaring = m.getDeclaringClass();
    // (declaring == clazz) is just an optimization - we're calling this only from code that operates on a
    // non-restriced class, so if the declaring class is identical to the class being inspected, then forego
    // a potentially expensive restricted-package check.
    return declaring == clazz || !CheckRestrictedPackage.isRestrictedClass(declaring);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:FacetIntrospector.java

示例3: createDynamicMethod

import java.lang.reflect.Member; //导入方法依赖的package包/类
/**
 * Given a reflective method or a constructor, creates a dynamic method that represents it. This method will
 * distinguish between caller sensitive and ordinary methods/constructors, and create appropriate caller sensitive
 * dynamic method when needed.
 * @param m the reflective member
 * @return the single dynamic method representing the reflective member
 */
private static SingleDynamicMethod createDynamicMethod(final AccessibleObject m) {
    if(CallerSensitiveDetector.isCallerSensitive(m)) {
        // Method has @CallerSensitive annotation
        return new CallerSensitiveDynamicMethod(m);
    }
    // Method has no @CallerSensitive annotation
    final MethodHandle mh;
    try {
        mh = unreflectSafely(m);
    } catch (final IllegalAccessError e) {
        // java.lang.invoke can in some case conservatively treat as caller sensitive methods that aren't
        // marked with the annotation. In this case, we'll fall back to treating it as caller sensitive.
        return new CallerSensitiveDynamicMethod(m);
    }
    // Proceed with non-caller sensitive
    final Member member = (Member)m;
    return new SimpleDynamicMethod(mh, member.getDeclaringClass(), member.getName(), m instanceof Constructor);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:AbstractJavaLinker.java

示例4: forMember

import java.lang.reflect.Member; //导入方法依赖的package包/类
public static Object forMember(Member member) {
  if (member == null) {
    return SourceProvider.UNKNOWN_SOURCE;
  }

  Class declaringClass = member.getDeclaringClass();

  /*if[AOP]*/
  LineNumbers lineNumbers = lineNumbersCache.getUnchecked(declaringClass);
  String fileName = lineNumbers.getSource();
  Integer lineNumberOrNull = lineNumbers.getLineNumber(member);
  int lineNumber = lineNumberOrNull == null ? lineNumbers.getFirstLine() : lineNumberOrNull;
  /*end[AOP]*/
  /*if[NO_AOP]
  String fileName = null;
  int lineNumber = -1;
  end[NO_AOP]*/

  Class<? extends Member> memberType = Classes.memberType(member);
  String memberName = memberType == Constructor.class ? "<init>" : member.getName();
  return new StackTraceElement(declaringClass.getName(), memberName, fileName, lineNumber);
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:23,代码来源:StackTraceElements.java

示例5: conservativeCheckMemberAccess

import java.lang.reflect.Member; //导入方法依赖的package包/类
/**
 * Does a conservative approximation of member access check. Use this if
 * you don't have an actual 'userland' caller Class/ClassLoader available.
 * This might be more restrictive than a precise member access check where
 * you have a caller, but should never allow a member access that is
 * forbidden.
 *
 * @param m the {@code Member} about to be accessed
 */
public static void conservativeCheckMemberAccess(Member m) throws SecurityException{
    final SecurityManager sm = System.getSecurityManager();
    if (sm == null)
        return;

    // Check for package access on the declaring class.
    //
    // In addition, unless the member and the declaring class are both
    // public check for access declared member permissions.
    //
    // This is done regardless of ClassLoader relations between the {@code
    // Member m} and any potential caller.

    final Class<?> declaringClass = m.getDeclaringClass();

    privateCheckPackageAccess(sm, declaringClass);

    if (Modifier.isPublic(m.getModifiers()) &&
            Modifier.isPublic(declaringClass.getModifiers()))
        return;

    // Check for declared member access.
    sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:ReflectUtil.java

示例6: isAccessible

import java.lang.reflect.Member; //导入方法依赖的package包/类
boolean isAccessible(final Member m) {
    final Class<?> declaring = m.getDeclaringClass();
    // (declaring == clazz) is just an optimization - we're calling this only from code that operates on a
    // non-restricted class, so if the declaring class is identical to the class being inspected, then forego
    // a potentially expensive restricted-package check.
    return declaring == clazz || !CheckRestrictedPackage.isRestrictedClass(declaring);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:FacetIntrospector.java

示例7: createDynamicMethod

import java.lang.reflect.Member; //导入方法依赖的package包/类
/**
 * Given a reflective method or a constructor, creates a dynamic method that represents it. This method will
 * distinguish between caller sensitive and ordinary methods/constructors, and create appropriate caller sensitive
 * dynamic method when needed.
 * @param m the reflective member
 * @return the single dynamic method representing the reflective member
 */
private static SingleDynamicMethod createDynamicMethod(final AccessibleObject m) {
    if (m.isAnnotationPresent(CallerSensitive.class)) {
        // Method has @CallerSensitive annotation
        return new CallerSensitiveDynamicMethod(m);
    }
    // Method has no @CallerSensitive annotation
    final MethodHandle mh;
    try {
        mh = unreflectSafely(m);
    } catch (final IllegalAccessError e) {
        // java.lang.invoke can in some case conservatively treat as caller sensitive methods that aren't
        // marked with the annotation. In this case, we'll fall back to treating it as caller sensitive.
        return new CallerSensitiveDynamicMethod(m);
    }
    // Proceed with non-caller sensitive
    final Member member = (Member)m;
    return new SimpleDynamicMethod(mh, member.getDeclaringClass(), member.getName(), m instanceof Constructor);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:AbstractJavaLinker.java

示例8: forMember

import java.lang.reflect.Member; //导入方法依赖的package包/类
public static Object forMember(Member member) {
    if (member == null) {
        return SourceProvider.UNKNOWN_SOURCE;
    }

    Class declaringClass = member.getDeclaringClass();

    String fileName = null;
    int lineNumber = -1;

    Class<? extends Member> memberType = MoreTypes.memberType(member);
    String memberName = memberType == Constructor.class ? "<init>" : member.getName();
    return new StackTraceElement(declaringClass.getName(), memberName, fileName, lineNumber);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:StackTraceElements.java

示例9: MemberImpl

import java.lang.reflect.Member; //导入方法依赖的package包/类
private MemberImpl(Member member) {
    this.declaringClass = member.getDeclaringClass();
    this.name = member.getName();
    this.modifiers = member.getModifiers();
    this.synthetic = member.isSynthetic();
    this.memberType = memberType(member);
    this.memberKey = memberKey(member);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:MoreTypes.java


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