Skip to content

Commit

Permalink
HV-568: Caching composing constraints, retrieving annotation type fro…
Browse files Browse the repository at this point in the history
…m cache
  • Loading branch information
gunnarmorling committed May 8, 2012
1 parent e73efab commit 132d98d
Showing 1 changed file with 25 additions and 6 deletions.
Expand Up @@ -131,6 +131,11 @@ public enum AnnotationType {

private final Map<Name, AnnotationType> annotationTypeCache;

/**
* Caches composing constraints.
*/
private final Map<Name, Set<AnnotationMirror>> composingConstraintsByConstraints;

private final Types typeUtils;

private final AnnotationApiHelper annotationApiHelper;
Expand All @@ -142,6 +147,7 @@ public ConstraintHelper(Types typeUtils, AnnotationApiHelper annotationApiHelper

annotationTypeCache = CollectionHelper.newHashMap();
supportedTypesByConstraint = CollectionHelper.newHashMap();
composingConstraintsByConstraints = CollectionHelper.newHashMap();

//register BV-defined constraints
registerAllowedTypesForBuiltInConstraint( BeanValidationTypes.ASSERT_FALSE, Boolean.class );
Expand Down Expand Up @@ -704,27 +710,40 @@ private Name getName(Element element) {

private Set<AnnotationMirror> getComposingConstraints(DeclaredType constraintAnnotationType) {

Set<AnnotationMirror> theValue = CollectionHelper.newHashSet();
Name key = getName( constraintAnnotationType );

Set<AnnotationMirror> composingConstraints = composingConstraintsByConstraints.get( key );

if( composingConstraints != null ) {
return composingConstraints;
}

composingConstraints = CollectionHelper.newHashSet();

List<? extends AnnotationMirror> annotationMirrors = constraintAnnotationType.asElement()
.getAnnotationMirrors();

for ( AnnotationMirror oneAnnotationMirror : annotationMirrors ) {
if ( isConstraintAnnotation( oneAnnotationMirror.getAnnotationType().asElement() ) ) {
theValue.add( oneAnnotationMirror );

AnnotationType annotationType = getAnnotationType(oneAnnotationMirror);

if ( annotationType == AnnotationType.CONSTRAINT_ANNOTATION ) {
composingConstraints.add( oneAnnotationMirror );
}
else if ( isMultiValuedConstraint( oneAnnotationMirror ) ) {
else if ( annotationType == AnnotationType.MULTI_VALUED_CONSTRAINT_ANNOTATION ) {
List<? extends AnnotationValue> value = annotationApiHelper.getAnnotationArrayValue(
oneAnnotationMirror,
"value"
);
for ( AnnotationValue annotationValue : value ) {
theValue.add( (AnnotationMirror) annotationValue );
composingConstraints.add( (AnnotationMirror) annotationValue );
}
}
}

return theValue;
composingConstraintsByConstraints.put( key, composingConstraints );

return composingConstraints;
}

private List<TypeMirror> asMirrors(Class<?>... types) {
Expand Down

0 comments on commit 132d98d

Please sign in to comment.