Java Code Examples for java.lang.reflect.AnnotatedElement#toString()

The following examples show how to use java.lang.reflect.AnnotatedElement#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringCacheAnnotationParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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.");
	}
}
 
Example 2
Source File: SpringCacheAnnotationParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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.");
	}
}
 
Example 3
Source File: SpringCacheAnnotationParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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.");
	}
}
 
Example 4
Source File: FixUseSupperClassAnnotationParser.java    From hsweb-framework with Apache License 2.0 6 votes vote down vote up
/**
 * 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.");
    }
}
 
Example 5
Source File: SpringCacheAnnotationParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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.");
	}
}
 
Example 6
Source File: EmbeddedDatabaseReporter.java    From embedded-database-spring-test with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 7
Source File: ClassUtils.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 8
Source File: AnnotationSizeOfFilter.java    From sizeof with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: SerializableAnnotationBeanPostProcessor.java    From jdal with Apache License 2.0 5 votes vote down vote up
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() + "]");
}