Skip to content

Commit

Permalink
Revert "#67 - Remove target arg from AnnotationDescriptor#ceateUsage …
Browse files Browse the repository at this point in the history
…forms"

This reverts commit c18eeb9.
  • Loading branch information
sebersole committed Apr 25, 2024
1 parent 79ab850 commit b69d810
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 99 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
import java.util.HashMap;
import java.util.Map;

import org.hibernate.models.RepeatableAnnotationException;
import org.hibernate.models.internal.AnnotationTargetSupport;
import org.hibernate.models.spi.AnnotationUsage;
import org.hibernate.models.spi.SourceModelBuildingContext;

import static org.hibernate.models.internal.ModelsLogging.MODELS_LOGGER;

/**
* @author Steve Ebersole
*/
Expand All @@ -43,20 +40,17 @@ public void clearAnnotationUsages() {
usageMap.clear();
}

@Override
/**
* Applies the given {@code annotationUsage} to this target.
*
* @todo It is undefined currently what happens if the annotation type is already applied on this target.
*/
public <X extends Annotation> void addAnnotationUsage(AnnotationUsage<X> annotationUsage) {
assert annotationUsage.getAnnotationDescriptor().getAllowableTargets().contains( getKind() );
final AnnotationUsage<?> previous = usageMap.put( annotationUsage.getAnnotationType(), annotationUsage );

if ( annotationUsage.getAnnotationDescriptor().isRepeatable() ) {
throw new RepeatableAnnotationException( annotationUsage.getAnnotationDescriptor(), this );
}

final AnnotationUsage<? extends Annotation> previous = getUsageMap().put(
annotationUsage.getAnnotationType(),
annotationUsage
);
if ( previous != null && MODELS_LOGGER.isDebugEnabled() ) {
MODELS_LOGGER.debugf( "AnnotationUsage (%s) was replaced (%s)", annotationUsage, previous );
if ( previous != null ) {
// todo : ignore? log? exception?
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
import java.lang.annotation.Annotation;
import java.util.Map;

import org.hibernate.models.RepeatableAnnotationException;
import org.hibernate.models.internal.AnnotationTargetSupport;
import org.hibernate.models.spi.AnnotationUsage;
import org.hibernate.models.spi.SourceModelBuildingContext;

import static org.hibernate.models.internal.ModelsLogging.MODELS_LOGGER;

/**
* @author Steve Ebersole
*/
Expand Down Expand Up @@ -50,18 +47,7 @@ public void clearAnnotationUsages() {
@Override
public <X extends Annotation> void addAnnotationUsage(AnnotationUsage<X> annotationUsage) {
assert annotationUsage.getAnnotationDescriptor().getAllowableTargets().contains( getKind() );

if ( annotationUsage.getAnnotationDescriptor().isRepeatable() ) {
throw new RepeatableAnnotationException( annotationUsage.getAnnotationDescriptor(), this );
}

final AnnotationUsage<? extends Annotation> previous = getUsageMap().put(
annotationUsage.getAnnotationType(),
annotationUsage
);
if ( previous != null && MODELS_LOGGER.isDebugEnabled() ) {
MODELS_LOGGER.debugf( "AnnotationUsage (%s) was replaced (%s)", annotationUsage, previous );
}
getUsageMap().put( annotationUsage.getAnnotationType(), annotationUsage );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
import java.util.Map;
import java.util.function.Supplier;

import org.hibernate.models.RepeatableAnnotationException;
import org.hibernate.models.internal.AnnotationTargetSupport;
import org.hibernate.models.spi.AnnotationUsage;
import org.hibernate.models.spi.SourceModelBuildingContext;

import static org.hibernate.models.internal.ModelsLogging.MODELS_LOGGER;

/**
* AnnotationTarget where we know the annotations up front, but
* want to delay processing them until (unless!) they are needed
Expand Down Expand Up @@ -68,16 +65,6 @@ public void clearAnnotationUsages() {
@Override
public <X extends Annotation> void addAnnotationUsage(AnnotationUsage<X> annotationUsage) {
assert annotationUsage.getAnnotationDescriptor().getAllowableTargets().contains( getKind() );
if ( annotationUsage.getAnnotationDescriptor().isRepeatable() ) {
throw new RepeatableAnnotationException( annotationUsage.getAnnotationDescriptor(), this );
}

final AnnotationUsage<? extends Annotation> previous = getUsageMap().put(
annotationUsage.getAnnotationType(),
annotationUsage
);
if ( previous != null && MODELS_LOGGER.isDebugEnabled() ) {
MODELS_LOGGER.debugf( "AnnotationUsage (%s) was replaced (%s)", annotationUsage, previous );
}
getUsageMap().put( annotationUsage.getAnnotationType(), annotationUsage );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import java.lang.annotation.Annotation;

import org.hibernate.models.RepeatableAnnotationException;

/**
* Extension of AnnotationTarget which allows manipulation of the annotations
*
Expand All @@ -24,38 +22,22 @@ public interface MutableAnnotationTarget extends AnnotationTarget {

/**
* Add an annotation usage to this target
*
* @apiNote Expects the {@linkplain AnnotationDescriptor#getRepeatableContainer() container} form instead of
* {@linkplain AnnotationDescriptor#isRepeatable() repeatable} annotations.
*
* @throws RepeatableAnnotationException Indicates a {@linkplain AnnotationDescriptor#isRepeatable() repeatable}
* annotation was passed.
*/
<X extends Annotation> void addAnnotationUsage(AnnotationUsage<X> annotationUsage);

/**
* Applies a usage of the given {@code annotationType} to this target. Will return
* an existing usage, if one, or create a new usage.
*
* @apiNote Expects the {@linkplain AnnotationDescriptor#getRepeatableContainer() container} form instead of
* {@linkplain AnnotationDescriptor#isRepeatable() repeatable} annotations.
*
* @throws RepeatableAnnotationException Indicates a {@linkplain AnnotationDescriptor#isRepeatable() repeatable}
* annotation was passed.
*/
default <A extends Annotation> MutableAnnotationUsage<A> applyAnnotationUsage(
AnnotationDescriptor<A> annotationDescriptor,
AnnotationDescriptor<A> annotationType,
SourceModelBuildingContext buildingContext) {
if ( annotationDescriptor.isRepeatable() ) {
throw new RepeatableAnnotationException( annotationDescriptor, this );
}

final MutableAnnotationUsage<A> existing = (MutableAnnotationUsage<A>) getAnnotationUsage( annotationDescriptor );
final MutableAnnotationUsage<A> existing = (MutableAnnotationUsage<A>) getAnnotationUsage( annotationType );
if ( existing != null ) {
return existing;
}

final MutableAnnotationUsage<A> usage = annotationDescriptor.createUsage( buildingContext );
final MutableAnnotationUsage<A> usage = annotationType.createUsage( buildingContext );
addAnnotationUsage( usage );
return usage;
}
Expand Down

1 comment on commit b69d810

@sebersole
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#72

Please sign in to comment.