java.lang.reflect.AnnotatedElement#toString ( )源码实例Demo

下面列出了java.lang.reflect.AnnotatedElement#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Validates the specified {@link CacheOperation}.
 * <p>Throws an {@link IllegalStateException} if the state of the operation is
 * invalid. As there might be multiple sources for default values, this ensure
 * that the operation is in a proper state before being returned.
 * @param ae the annotated element of the cache operation
 * @param operation the {@link CacheOperation} to validate
 */
private void validateCacheOperation(AnnotatedElement ae, CacheOperation operation) {
	if (StringUtils.hasText(operation.getKey()) && StringUtils.hasText(operation.getKeyGenerator())) {
		throw new IllegalStateException("Invalid cache annotation configuration on '" +
				ae.toString() + "'. Both 'key' and 'keyGenerator' attributes have been set. " +
				"These attributes are mutually exclusive: either set the SpEL expression used to" +
				"compute the key at runtime or set the name of the KeyGenerator bean to use.");
	}
	if (StringUtils.hasText(operation.getCacheManager()) && StringUtils.hasText(operation.getCacheResolver())) {
		throw new IllegalStateException("Invalid cache annotation configuration on '" +
				ae.toString() + "'. Both 'cacheManager' and 'cacheResolver' attributes have been set. " +
				"These attributes are mutually exclusive: the cache manager is used to configure a" +
				"default cache resolver if none is set. If a cache resolver is set, the cache manager" +
				"won't be used.");
	}
}
 
/**
 * Validates the specified {@link CacheOperation}.
 * <p>Throws an {@link IllegalStateException} if the state of the operation is
 * invalid. As there might be multiple sources for default values, this ensure
 * that the operation is in a proper state before being returned.
 * @param ae the annotated element of the cache operation
 * @param operation the {@link CacheOperation} to validate
 */
private void validateCacheOperation(AnnotatedElement ae, CacheOperation operation) {
	if (StringUtils.hasText(operation.getKey()) && StringUtils.hasText(operation.getKeyGenerator())) {
		throw new IllegalStateException("Invalid cache annotation configuration on '" +
				ae.toString() + "'. Both 'key' and 'keyGenerator' attributes have been set. " +
				"These attributes are mutually exclusive: either set the SpEL expression used to" +
				"compute the key at runtime or set the name of the KeyGenerator bean to use.");
	}
	if (StringUtils.hasText(operation.getCacheManager()) && StringUtils.hasText(operation.getCacheResolver())) {
		throw new IllegalStateException("Invalid cache annotation configuration on '" +
				ae.toString() + "'. Both 'cacheManager' and 'cacheResolver' attributes have been set. " +
				"These attributes are mutually exclusive: the cache manager is used to configure a" +
				"default cache resolver if none is set. If a cache resolver is set, the cache manager" +
				"won't be used.");
	}
}
 
源代码3 项目: lams   文件: SpringCacheAnnotationParser.java
/**
 * Validates the specified {@link CacheOperation}.
 * <p>Throws an {@link IllegalStateException} if the state of the operation is
 * invalid. As there might be multiple sources for default values, this ensure
 * that the operation is in a proper state before being returned.
 * @param ae the annotated element of the cache operation
 * @param operation the {@link CacheOperation} to validate
 */
private void validateCacheOperation(AnnotatedElement ae, CacheOperation operation) {
	if (StringUtils.hasText(operation.getKey()) && StringUtils.hasText(operation.getKeyGenerator())) {
		throw new IllegalStateException("Invalid cache annotation configuration on '" +
				ae.toString() + "'. Both 'key' and 'keyGenerator' attributes have been set. " +
				"These attributes are mutually exclusive: either set the SpEL expression used to" +
				"compute the key at runtime or set the name of the KeyGenerator bean to use.");
	}
	if (StringUtils.hasText(operation.getCacheManager()) && StringUtils.hasText(operation.getCacheResolver())) {
		throw new IllegalStateException("Invalid cache annotation configuration on '" +
				ae.toString() + "'. Both 'cacheManager' and 'cacheResolver' attributes have been set. " +
				"These attributes are mutually exclusive: the cache manager is used to configure a" +
				"default cache resolver if none is set. If a cache resolver is set, the cache manager" +
				"won't be used.");
	}
}
 
/**
 * Validates the specified {@link CacheOperation}.
 * <p>Throws an {@link IllegalStateException} if the state of the operation is
 * invalid. As there might be multiple sources for default values, this ensure
 * that the operation is in a proper state before being returned.
 *
 * @param ae        the annotated element of the cache operation
 * @param operation the {@link CacheOperation} to validate
 */
private void validateCacheOperation(AnnotatedElement ae, CacheOperation operation) {
    if (StringUtils.hasText(operation.getKey()) && StringUtils.hasText(operation.getKeyGenerator())) {
        throw new IllegalStateException("Invalid cache annotation configuration on '" +
                ae.toString() + "'. Both 'key' and 'keyGenerator' attributes have been set. " +
                "These attributes are mutually exclusive: either set the SpEL expression used to" +
                "compute the key at runtime or set the name of the KeyGenerator bean to use.");
    }
    if (StringUtils.hasText(operation.getCacheManager()) && StringUtils.hasText(operation.getCacheResolver())) {
        throw new IllegalStateException("Invalid cache annotation configuration on '" +
                ae.toString() + "'. Both 'cacheManager' and 'cacheResolver' attributes have been set. " +
                "These attributes are mutually exclusive: the cache manager is used to configure a" +
                "default cache resolver if none is set. If a cache resolver is set, the cache manager" +
                "won't be used.");
    }
}
 
/**
 * Validates the specified {@link CacheOperation}.
 * <p>Throws an {@link IllegalStateException} if the state of the operation is
 * invalid. As there might be multiple sources for default values, this ensure
 * that the operation is in a proper state before being returned.
 * @param ae the annotated element of the cache operation
 * @param operation the {@link CacheOperation} to validate
 */
private void validateCacheOperation(AnnotatedElement ae, CacheOperation operation) {
	if (StringUtils.hasText(operation.getKey()) && StringUtils.hasText(operation.getKeyGenerator())) {
		throw new IllegalStateException("Invalid cache annotation configuration on '" +
				ae.toString() + "'. Both 'key' and 'keyGenerator' attributes have been set. " +
				"These attributes are mutually exclusive: either set the SpEL expression used to" +
				"compute the key at runtime or set the name of the KeyGenerator bean to use.");
	}
	if (StringUtils.hasText(operation.getCacheManager()) && StringUtils.hasText(operation.getCacheResolver())) {
		throw new IllegalStateException("Invalid cache annotation configuration on '" +
				ae.toString() + "'. Both 'cacheManager' and 'cacheResolver' attributes have been set. " +
				"These attributes are mutually exclusive: the cache manager is used to configure a" +
				"default cache resolver if none is set. If a cache resolver is set, the cache manager" +
				"won't be used.");
	}
}
 
private static String getElementName(AnnotatedElement element) {
    if (element instanceof Class) {
        return ((Class) element).getSimpleName();
    } else if (element instanceof Method) {
        Method method = (Method) element;
        return getElementName(method.getDeclaringClass()) + "#" + method.getName();
    } else {
        return element.toString();
    }
}
 
源代码7 项目: graphql-spqr   文件: ClassUtils.java
public static String toString(AnnotatedElement element) {
    if (element instanceof Parameter) {
        return ((Parameter) element).getDeclaringExecutable() + "#" + ((Parameter) element).getName();
    }
    if (element instanceof AnnotatedType) {
        return toString((AnnotatedType) element);
    }
    return element.toString();
}
 
源代码8 项目: sizeof   文件: AnnotationSizeOfFilter.java
private <T extends Annotation> T getAnnotationOn(AnnotatedElement element, Class<T> referenceAnnotation, Pattern matchingAnnotationPattern) {
    T matchingAnnotation = null;
    Annotation[] annotations = element.getAnnotations();
    for (Annotation annotation : annotations) {
        if (validateCustomAnnotationPattern(annotation.annotationType().getName(), matchingAnnotationPattern)) {
            if (matchingAnnotation != null) {
                throw new IllegalStateException("You are not allowed to use more than one @" + referenceAnnotation.getName()
                                                + " annotations for the same element : "
                                                + element.toString());
            }
            matchingAnnotation = AnnotationProxyFactory.getAnnotationProxy(annotation, referenceAnnotation);
        }
    }
    return matchingAnnotation;
}
 
private ResolvableType getResolvableType(AnnotatedElement element) {
	if (element instanceof Field)
		return ResolvableType.forField((Field) element);
	else if (element instanceof Method)
		return ResolvableType.forMethodParameter(
				new MethodParameter((Method) element, 0));
	
	throw new IllegalArgumentException("SerializableProxy annotation should only be applied on types" +
			", fields or methods but was found in [" + element.toString() + "]");
}