java.lang.Class.isLocalClass()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(284)

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

Class.isLocalClass介绍

[英]Tests whether the class represented by this Class is defined locally.
[中]测试此类表示的类是否在本地定义。

代码示例

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

/**
 * {@inheritDoc}
 */
public boolean isLocalType() {
  return type.isLocalClass();
}

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

public static boolean callIsLocalClass(Class thiz)
{
  return thiz.isLocalClass();
}

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

@Override
 @Nullable
 Class<?> getOwnerType(Class<?> rawType) {
  if (rawType.isLocalClass()) {
   return null;
  } else {
   return rawType.getEnclosingClass();
  }
 }
};

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

private void checkNotLocal(Field field) {
  if(field.getType().isLocalClass()) {
    throw new MockitoException("the type '" + field.getType().getSimpleName() + "' is a local class.");
  }
}

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

@NullableDecl
 @Override
 Class<?> getOwnerType(Class<?> rawType) {
  if (rawType.isLocalClass()) {
   return null;
  } else {
   return rawType.getEnclosingClass();
  }
 }
};

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

@Nullable
  @Override
  Class<?> getOwnerType(Class<?> rawType) {
    if (rawType.isLocalClass()) {
      return null;
    } else {
      return rawType.getEnclosingClass();
    }
  }
};

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

@Override
 @NullableDecl
 Class<?> getOwnerType(Class<?> rawType) {
  if (rawType.isLocalClass()) {
   return null;
  } else {
   return rawType.getEnclosingClass();
  }
 }
};

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

private void checkNotLocal(Field field) {
  if(field.getType().isLocalClass()) {
    throw new MockitoException("the type '" + field.getType().getSimpleName() + "' is a local class.");
  }
}

代码示例来源:origin: kiegroup/optaplanner

public static <T> T newInstance(Object bean, String propertyName, Class<T> clazz) {
  try {
    return clazz.newInstance();
  } catch (InstantiationException | IllegalAccessException e) {
    throw new IllegalArgumentException("The " + bean.getClass().getSimpleName() + "'s " + propertyName + " ("
        + clazz.getName() + ") does not have a public no-arg constructor"
        // Inner classes include local, anonymous and non-static member classes
        + ((clazz.isLocalClass() || clazz.isAnonymousClass() || clazz.isMemberClass())
        && !Modifier.isStatic(clazz.getModifiers()) ? " because it is an inner class." : "."), e);
  }
}

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

@NullableDecl
 @Override
 Class<?> getOwnerType(Class<?> rawType) {
  if (rawType.isLocalClass()) {
   return null;
  } else {
   return rawType.getEnclosingClass();
  }
 }
};

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

/**
 * Check if the class is acceptable as a JAX-RS provider or resource.
 * <p/>
 * Method returns {@code false} if the class is either
 * <ul>
 * <li>abstract</li>
 * <li>interface</li>
 * <li>annotation</li>
 * <li>primitive</li>
 * <li>local class</li>
 * <li>non-static member class</li>
 * </ul>
 *
 * @param c class to be checked.
 * @return {@code true} if the class is an acceptable JAX-RS provider or
 * resource, {@code false} otherwise.
 */
public static boolean isAcceptable(Class<?> c) {
  return !((c.getModifiers() & Modifier.ABSTRACT) != 0
           || c.isPrimitive()
           || c.isAnnotation()
           || c.isInterface()
           || c.isLocalClass()
           || (c.isMemberClass() && (c.getModifiers() & Modifier.STATIC) == 0));
}

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

/**
 * Check if the class is acceptable as a JAX-RS provider or resource.
 * <p/>
 * Method returns {@code false} if the class is either
 * <ul>
 * <li>abstract</li>
 * <li>interface</li>
 * <li>annotation</li>
 * <li>primitive</li>
 * <li>local class</li>
 * <li>non-static member class</li>
 * </ul>
 *
 * @param c class to be checked.
 * @return {@code true} if the class is an acceptable JAX-RS provider or
 * resource, {@code false} otherwise.
 */
public static boolean isAcceptable(Class<?> c) {
  return !((c.getModifiers() & Modifier.ABSTRACT) != 0
           || c.isPrimitive()
           || c.isAnnotation()
           || c.isInterface()
           || c.isLocalClass()
           || (c.isMemberClass() && (c.getModifiers() & Modifier.STATIC) == 0));
}

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

private Class<?> checkSecurity(Class<?> clazz) throws ClassNotFoundException {
 Class<?> target = clazz;
 while (target.isArray()) {
   target = target.getComponentType();
 }
 while (target.isAnonymousClass() || target.isLocalClass()) {
   target = target.getEnclosingClass();
 }
 if (!target.isPrimitive()) {
   if (!isTrustedType(target)) {
    throw new ClassNotFoundException("Forbidden " + clazz + "! " +
                      "This class is not trusted to be deserialized under the current configuration. " +
                      "Please refer to the documentation for more information on how to configure trusted classes.");
   }
 }
 return clazz;
}

代码示例来源:origin: openzipkin/brave

/** Validating instance creator that ensures the supplier type is static or top-level */
public static <T> T newInstance(Class<T> type, ClassLoader loader) {
 assertThat(type)
   .withFailMessage(type + " should be a static member class")
   .satisfies(c -> {
    assertThat(c.isLocalClass()).isFalse();
    assertThat(Modifier.isPublic(c.getModifiers())).isFalse();
   });
 try {
  Class<T> classToInstantiate = (Class<T>) loader.loadClass(type.getName());
  Constructor<T> ctor = classToInstantiate.getDeclaredConstructor();
  ctor.setAccessible(true);
  return ctor.newInstance();
 } catch (ReflectiveOperationException e) {
  throw new IllegalStateException(e);
 }
}

代码示例来源:origin: oldmanpushcart/greys-anatomy

/**
 * 计算ClassType
 *
 * @param targetClass 目标类
 * @return 计算出的ClassType
 */
public static int computeClassType(Class<?> targetClass) {
  int type = 0;
  if (targetClass.isAnnotation())
    type |= TYPE_ANNOTATION;
  if (targetClass.isAnonymousClass())
    type |= TYPE_ANONYMOUS;
  if (targetClass.isArray())
    type |= TYPE_ARRAY;
  if (targetClass.isEnum())
    type |= TYPE_ENUM;
  if (targetClass.isInterface())
    type |= TYPE_INTERFACE;
  if (targetClass.isLocalClass())
    type |= TYPE_LOCAL;
  if (targetClass.isMemberClass())
    type |= TYPE_MEMBER;
  if (targetClass.isPrimitive())
    type |= TYPE_PRIMITIVE;
  if (targetClass.isSynthetic())
    type |= TYPE_SYNTHETIC;
  return type;
}

代码示例来源:origin: square/moshi

throw new IllegalArgumentException("Cannot serialize anonymous class " + rawType.getName());
if (rawType.isLocalClass()) {
 throw new IllegalArgumentException("Cannot serialize local class " + rawType.getName());

代码示例来源:origin: org.junit.jupiter/junit-jupiter-engine

@Override
public boolean test(Class<?> candidate) {
  // Please do not collapse the following into a single statement.
  if (isPrivate(candidate)) {
    return false;
  }
  if (isAbstract(candidate)) {
    return false;
  }
  if (candidate.isLocalClass()) {
    return false;
  }
  if (candidate.isAnonymousClass()) {
    return false;
  }
  return !isInnerClass(candidate);
}

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

private <T> void validateClass(Class<T> entityClass) {
  if (entityClass.isAnonymousClass() || entityClass.isLocalClass()) {
    throw new IllegalArgumentException(entityClass.getName() + " is not publically accessable.");

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

private <T> void validateClass(Class<T> entityClass) {
  if (entityClass.isAnonymousClass() || entityClass.isLocalClass()) {
    throw new IllegalArgumentException(entityClass.getName() + " is not publically accessable.");

代码示例来源:origin: oldmanpushcart/greys-anatomy

private String drawClassInfo() {
  final CodeSource cs = clazz.getProtectionDomain().getCodeSource();
  final TTable tTable = new TTable(new TTable.ColumnDefine[]{
      new TTable.ColumnDefine(50, TTable.Align.RIGHT),
      new TTable.ColumnDefine(80, TTable.Align.LEFT)
  })
      .addRow("class-info", tranClassName(clazz))
      .addRow("code-source", getCodeSource(cs))
      .addRow("name", tranClassName(clazz))
      .addRow("isInterface", clazz.isInterface())
      .addRow("isAnnotation", clazz.isAnnotation())
      .addRow("isEnum", clazz.isEnum())
      .addRow("isAnonymousClass", clazz.isAnonymousClass())
      .addRow("isArray", clazz.isArray())
      .addRow("isLocalClass", clazz.isLocalClass())
      .addRow("isMemberClass", clazz.isMemberClass())
      .addRow("isPrimitive", clazz.isPrimitive())
      .addRow("isSynthetic", clazz.isSynthetic())
      .addRow("simple-name", clazz.getSimpleName())
      .addRow("modifier", tranModifier(clazz.getModifiers()))
      .addRow("annotation", drawAnnotation())
      .addRow("interfaces", drawInterface())
      .addRow("super-class", drawSuperClass())
      .addRow("class-loader", drawClassLoader());
  if (isPrintField) {
    tTable.addRow("fields", drawField());
  }
  return tTable.padding(1).rendering();
}

相关文章

Class类方法