java.lang.reflect.Member.getDeclaringClass()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(188)

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

Member.getDeclaringClass介绍

[英]Returns the class that declares this member.
[中]返回声明此成员的类。

代码示例

代码示例来源:origin: google/guava

@Override
public Class<?> getDeclaringClass() {
 return member.getDeclaringClass();
}

代码示例来源:origin: prestodb/presto

@Override
public Class<?> getDeclaringClass() {
 return member.getDeclaringClass();
}

代码示例来源:origin: google/j2objc

@Override
public Class<?> getDeclaringClass() {
 return member.getDeclaringClass();
}

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

/**
 * Returns <code>true</code> if the first member is accessible from second one.
 */
public static boolean isAssignableFrom(Member member1, Member member2) {
  return member1.getDeclaringClass().isAssignableFrom(member2.getDeclaringClass());
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public boolean isCompilable() {
  return (Modifier.isPublic(this.member.getModifiers()) &&
      Modifier.isPublic(this.member.getDeclaringClass().getModifiers()));
}

代码示例来源:origin: oblac/jodd

/**
 * Returns <code>true</code> if the first member is accessible from second one.
 */
public static boolean isAssignableFrom(final Member member1, final Member member2) {
  return member1.getDeclaringClass().isAssignableFrom(member2.getDeclaringClass());
}

代码示例来源:origin: spring-projects/spring-framework

public ClassInfo getClassInfo() {
  if (ci == null)
    ci = ReflectUtils.getClassInfo(member.getDeclaringClass());
  return ci;
}

代码示例来源:origin: JakeWharton/butterknife

private static <T extends AccessibleObject & Member> void validateMember(T object) {
 int modifiers = object.getModifiers();
 if ((modifiers & (PRIVATE | STATIC)) != 0) {
  throw new IllegalStateException(object.getDeclaringClass().getName()
    + "."
    + object.getName()
    + " must not be private or static");
 }
 if ((modifiers & PUBLIC) == 0) {
  object.setAccessible(true);
 }
}

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

/**
 * Returns <code>true</code> if class member is public and if its declaring class is also public.
 */
public static boolean isPublicPublic(Member member) {
  if (Modifier.isPublic(member.getModifiers())) {
    if (Modifier.isPublic(member.getDeclaringClass().getModifiers())) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Determine if the given annotated element is defined in a
 * {@code java} or in the {@code org.springframework.lang} package.
 * @param annotatedElement the annotated element to check
 * @return {@code true} if the given element is in a {@code java}
 * package or in the {@code org.springframework.lang} package
 * @since 5.1
 */
static boolean hasPlainJavaAnnotationsOnly(@Nullable Object annotatedElement) {
  Class<?> clazz;
  if (annotatedElement instanceof Class) {
    clazz = (Class<?>) annotatedElement;
  }
  else if (annotatedElement instanceof Member) {
    clazz = ((Member) annotatedElement).getDeclaringClass();
  }
  else {
    return false;
  }
  String name = clazz.getName();
  return (name.startsWith("java") || name.startsWith("org.springframework.lang."));
}

代码示例来源:origin: oblac/jodd

/**
 * Returns <code>true</code> if class member is public and if its declaring class is also public.
 */
public static boolean isPublicPublic(final Member member) {
  if (Modifier.isPublic(member.getModifiers())) {
    if (Modifier.isPublic(member.getDeclaringClass().getModifiers())) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: google/j2objc

public ClassInfo getClassInfo() {
  if (ci == null)
    ci = ReflectUtils.getClassInfo(member.getDeclaringClass());
  return ci;
}
public int getModifiers() {

代码示例来源:origin: org.springframework/spring-core

public ClassInfo getClassInfo() {
  if (ci == null)
    ci = ReflectUtils.getClassInfo(member.getDeclaringClass());
  return ci;
}

代码示例来源:origin: org.easymock/easymock

public ClassInfo getClassInfo() {
  if (ci == null)
    ci = ReflectUtils.getClassInfo(member.getDeclaringClass());
  return ci;
}
public int getModifiers() {

代码示例来源:origin: com.google.inject/guice

/**
 * Returns a FastClass proxy for invoking the given member or {@code null} if access rules
 * disallow it.
 *
 * @see #newFastClassForMember(Class, Member) for a full description
 */
public static net.sf.cglib.reflect.FastClass newFastClassForMember(Member member) {
 return newFastClassForMember(member.getDeclaringClass(), member);
}

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

public ClassInfo getClassInfo() {
  if (ci == null)
    ci = ReflectUtils.getClassInfo(member.getDeclaringClass());
  return ci;
}
public int getModifiers() {

代码示例来源:origin: google/j2objc

public boolean evaluate(Object arg) {
    int mod = (arg instanceof Member) ? ((Member)arg).getModifiers() : ((Integer)arg).intValue();
    if (Modifier.isPrivate(mod)) {
      return false;
    } else if (Modifier.isPublic(mod)) {
      return true;
    } else if (Modifier.isProtected(mod)) {
      return protectedOk;
    } else {
      return pkg.equals(TypeUtils.getPackageName(Type.getType(((Member)arg).getDeclaringClass())));
    }
  }
}

代码示例来源:origin: com.google.inject/guice

@Override
public Logger get(InternalContext context, Dependency<?> dependency, boolean linked) {
 InjectionPoint injectionPoint = dependency.getInjectionPoint();
 return injectionPoint == null
   ? Logger.getAnonymousLogger()
   : Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}

代码示例来源:origin: hibernate/hibernate-orm

/**
   * Used by JDK serialization...
   *
   * @param oos The output stream to which we are being written...
   * @throws IOException Indicates a general IO stream exception
   */
  protected void writeObject(ObjectOutputStream oos) throws IOException {
    oos.defaultWriteObject();
    oos.writeObject( getJavaMember().getDeclaringClass().getName() );
    oos.writeObject( getJavaMember().getName() );
    // should only ever be a field or the getter-method...
    oos.writeObject( Method.class.isInstance( getJavaMember() ) ? "method" : "field" );
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  public void generateCode(String propertyName, MethodVisitor mv, CodeFlow cf) {
    boolean isStatic = Modifier.isStatic(this.member.getModifiers());
    String descriptor = cf.lastDescriptor();
    String classDesc = this.member.getDeclaringClass().getName().replace('.', '/');
    if (!isStatic) {
      if (descriptor == null) {
        cf.loadTarget(mv);
      }
      if (descriptor == null || !classDesc.equals(descriptor.substring(1))) {
        mv.visitTypeInsn(CHECKCAST, classDesc);
      }
    }
    else {
      if (descriptor != null) {
        // A static field/method call will not consume what is on the stack,
        // it needs to be popped off.
        mv.visitInsn(POP);
      }
    }
    if (this.member instanceof Method) {
      mv.visitMethodInsn((isStatic ? INVOKESTATIC : INVOKEVIRTUAL), classDesc, this.member.getName(),
          CodeFlow.createSignatureDescriptor((Method) this.member), false);
    }
    else {
      mv.visitFieldInsn((isStatic ? GETSTATIC : GETFIELD), classDesc, this.member.getName(),
          CodeFlow.toJvmDescriptor(((Field) this.member).getType()));
    }
  }
}

相关文章