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

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

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

Class.isAnnotation介绍

[英]Tests whether this Class represents an annotation class.
[中]测试此类是否表示注释类。

代码示例

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

@Override
public boolean isAnnotation() {
  return this.introspectedClass.isAnnotation();
}

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

/** Determines if the supplied Class object represents an annotation type. */
static public boolean isAnnotation (Class c) {
  return c.isAnnotation();
}

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

/** Determines if the supplied Class object represents an annotation type. */
static public boolean isAnnotation (Class c) {
  return c.isAnnotation();
}

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

@Override
public boolean isAnnotation() {
  return type.isAnnotation();
}

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

@Override
public boolean isAnnotation() {
  return this.introspectedClass.isAnnotation();
}

代码示例来源:origin: spockframework/spock

@SuppressWarnings("unchecked")
public IncludeExcludeCriteria(Class<?>... criteria) {
 for (Class<?> criterium : criteria)
  if (criterium.isAnnotation())
   annotations.add((Class<? extends Annotation>)criterium);
  else
   baseClasses.add(criterium);
}

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

/**
 * @return Null if class might be a bean; type String (that identifies
 *   why it's not a bean) if not
 */
public static String canBeABeanType(Class<?> type)
{
  // First: language constructs that ain't beans:
  if (type.isAnnotation()) {
    return "annotation";
  }
  if (type.isArray()) {
    return "array";
  }
  if (type.isEnum()) {
    return "enum";
  }
  if (type.isPrimitive()) {
    return "primitive";
  }
  // Anything else? Seems valid, then
  return null;
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * <p>Checks if the specified type is permitted as an annotation member.</p>
 *
 * <p>The Java language specification only permits certain types to be used
 * in annotations. These include {@link String}, {@link Class}, primitive
 * types, {@link Annotation}, {@link Enum}, and single-dimensional arrays of
 * these types.</p>
 *
 * @param type the type to check, {@code null}
 * @return {@code true} if the type is a valid type to use in an annotation
 */
public static boolean isValidAnnotationMemberType(Class<?> type) {
  if (type == null) {
    return false;
  }
  if (type.isArray()) {
    type = type.getComponentType();
  }
  return type.isPrimitive() || type.isEnum() || type.isAnnotation()
      || String.class.equals(type) || Class.class.equals(type);
}

代码示例来源:origin: nutzam/nutz

public boolean checkClass(Class<?> klass) {
  return !(klass.isInterface()
       || klass.isArray()
       || klass.isEnum()
       || klass.isPrimitive()
       || klass.isMemberClass()
       || klass.isAnnotation()
       || klass.isAnonymousClass());
}

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

@Override
  public String[] resolve(Class<?> testClass) {
    return testClass.isAnnotation() ? new String[] { "@" + testClass.getSimpleName() }
        : new String[] { testClass.getSimpleName() };
  }
}

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

public static boolean isJUnitTest(Class c) {
  if (!haveJUnit()) {
    return false;
  }
  //only public classes are interesting, so filter out the rest
  if (!Modifier.isPublic(c.getModifiers()) || c.isInterface() || c.isAnnotation() || c.isEnum()) {
    return false;
  }
  return (junit3 != null && junit3.isTest(c)) || (junit4 != null && junit4.isTest(c));
}

代码示例来源:origin: alibaba/fastjson

public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    Class objClass = object.getClass();
    Class[] interfaces = objClass.getInterfaces();
    if (interfaces.length == 1 && interfaces[0].isAnnotation()) {
      Class annotationClass = interfaces[0];
      AnnotationType type = AnnotationType.getInstance(annotationClass);
      Map<String, Method> members = type.members();
      JSONObject json = new JSONObject(members.size());
      Iterator<Map.Entry<String, Method>> iterator = members.entrySet().iterator();
      Map.Entry<String, Method> entry;
      Object val = null;
      while (iterator.hasNext()) {
        entry = iterator.next();
        try {
          val = entry.getValue().invoke(object);
        } catch (IllegalAccessException e) {
          // skip
        } catch (InvocationTargetException e) {
          // skip
        }
        json.put(entry.getKey(), JSON.toJSON(val));
      }
      serializer.write(json);
      return;
    }
  }
}

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

@SuppressWarnings("unchecked")
private static Class<? extends Annotation> asAnnotation(Class<?> clazz) {
 if (clazz.isAnnotation()) {
  return (Class<? extends Annotation>) clazz;
 } else {
  throw new IllegalArgumentException(rootLocaleFormat("%s is not an annotation.", clazz));
 }
}

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

private static boolean isProperField(Field field) {
  if (isStatic(field) || isFinal(field)) {
    return false;
  }
  Class<?> type = field.getType();
  return !type.isAnnotation();
}

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

/**
 * Creates a factory for an offset mapping that binds an annotation property.
 *
 * @param annotationType The annotation type to bind.
 * @param property       The property to bind.
 * @param <S>            The annotation type.
 * @return A factory for binding a property of the annotation type.
 */
public static <S extends Annotation> OffsetMapping.Factory<S> of(Class<S> annotationType, String property) {
  if (!annotationType.isAnnotation()) {
    throw new IllegalArgumentException("Not an annotation type: " + annotationType);
  }
  try {
    return new OfAnnotationProperty<S>(annotationType, new MethodDescription.ForLoadedMethod(annotationType.getMethod(property)));
  } catch (NoSuchMethodException exception) {
    throw new IllegalArgumentException("Cannot find a property " + property + " on " + annotationType, exception);
  }
}

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

/**
 * Binds an annotation to a dynamically computed value. Whenever the {@link Advice} component discovers the given annotation on
 * a parameter of an advice method, the dynamic value is asked to provide a value that is then assigned to the parameter in question.
 *
 * @param offsetMapping The dynamic value that is computed for binding the parameter to a value.
 * @return A new builder for an advice that considers the supplied annotation type during binding.
 */
public WithCustomMapping bind(OffsetMapping.Factory<?> offsetMapping) {
  Map<Class<? extends Annotation>, OffsetMapping.Factory<?>> offsetMappings = new HashMap<Class<? extends Annotation>, OffsetMapping.Factory<?>>(this.offsetMappings);
  if (!offsetMapping.getAnnotationType().isAnnotation()) {
    throw new IllegalArgumentException("Not an annotation type: " + offsetMapping.getAnnotationType());
  } else if (offsetMappings.put(offsetMapping.getAnnotationType(), offsetMapping) != null) {
    throw new IllegalArgumentException("Annotation type already mapped: " + offsetMapping.getAnnotationType());
  }
  return new WithCustomMapping(offsetMappings);
}

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

/**
 * Verifies that the actual {@code Class} is an annotation.
 * 
 * @param info contains information about the assertion.
 * @param actual the "actual" {@code Class}.
 * @throws AssertionError if {@code actual} is {@code null}.
 * @throws AssertionError if the actual {@code Class} is not an annotation.
 */
public void assertIsAnnotation(AssertionInfo info, Class<?> actual) {
 assertNotNull(info, actual);
 if (!actual.isAnnotation()) throw failures.failure(info, shouldBeAnnotation(actual));
}

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

/**
 * Verifies that the actual {@code Class} is not an annotation.
 * 
 * @param info contains information about the assertion.
 * @param actual the "actual" {@code Class}.
 * @throws AssertionError if {@code actual} is {@code null}.
 * @throws AssertionError if the actual {@code Class} is an annotation.
 */
public void assertIsNotAnnotation(AssertionInfo info, Class<?> actual) {
 assertNotNull(info, actual);
 if (actual.isAnnotation()) throw failures.failure(info, shouldNotBeAnnotation(actual));
}

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

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public Loaded<Annotation> load(ClassLoader classLoader) throws ClassNotFoundException {
  Class<?> type = Class.forName(annotationToken.getBinaryName(), false, classLoader);
  if (type.isAnnotation()) {
    return new ForAnnotationDescription.Loaded<Annotation>(AnnotationDescription.AnnotationInvocationHandler.of(classLoader,
        (Class<? extends Annotation>) type,
        annotationToken.getValues()));
  } else {
    return new ForAnnotationDescription.IncompatibleRuntimeType(type);
  }
}

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

public static <E extends Enum<?> & Feature<?>> void assertGoodFeatureEnum(
  Class<E> featureEnumClass) {
 final Class<?>[] classes = featureEnumClass.getDeclaredClasses();
 for (Class<?> containedClass : classes) {
  if (containedClass.getSimpleName().equals("Require")) {
   if (containedClass.isAnnotation()) {
    assertGoodTesterAnnotation(asAnnotation(containedClass));
   } else {
    fail(
      rootLocaleFormat(
        "Feature enum %s contains a class named "
          + "'Require' but it is not an annotation.",
        featureEnumClass));
   }
   return;
  }
 }
 fail(
   rootLocaleFormat(
     "Feature enum %s should contain an " + "annotation named 'Require'.",
     featureEnumClass));
}

相关文章

Class类方法