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