Skip to content

Commit 06058d8

Browse files
mbelladesebersole
authored andcommitted
#63 - Remove AnnotationUsage#getAnnotationTarget
1 parent 2ec3b1e commit 06058d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+161
-265
lines changed

src/main/java/org/hibernate/models/internal/AbstractTypeDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public V createValue(
4141

4242
//noinspection unchecked
4343
final ValueWrapper<V, Object> valueWrapper = (ValueWrapper<V, Object>) createJdkWrapper( context );
44-
return valueWrapper.wrap( defaultValue, target, context );
44+
return valueWrapper.wrap( defaultValue, context );
4545
}
4646

4747
@Override

src/main/java/org/hibernate/models/internal/ArrayTypeDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public List<V> createValue(
6262
return Collections.emptyList();
6363
}
6464

65-
return jdkValueWrapper.wrap( defaultValue, target, context );
65+
return jdkValueWrapper.wrap( defaultValue, context );
6666
}
6767

6868
@Override

src/main/java/org/hibernate/models/internal/dynamic/DynamicAnnotationUsage.java

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
import java.util.Map;
1616

1717
import org.hibernate.models.AnnotationAccessException;
18-
import org.hibernate.models.UnknownAnnotationAttributeException;
1918
import org.hibernate.models.internal.AnnotationProxy;
2019
import org.hibernate.models.spi.AnnotationDescriptor;
21-
import org.hibernate.models.spi.AnnotationTarget;
2220
import org.hibernate.models.spi.AttributeDescriptor;
2321
import org.hibernate.models.spi.MutableAnnotationUsage;
2422
import org.hibernate.models.spi.SourceModelContext;
@@ -30,29 +28,15 @@
3028
*/
3129
public class DynamicAnnotationUsage<A extends Annotation> implements MutableAnnotationUsage<A> {
3230
private final AnnotationDescriptor<A> annotationDescriptor;
33-
private final AnnotationTarget target;
3431

3532
private Map<String, Object> values;
3633

37-
public DynamicAnnotationUsage(
38-
AnnotationDescriptor<A> annotationDescriptor,
39-
SourceModelContext context) {
40-
this( annotationDescriptor, null, context );
41-
}
42-
43-
public DynamicAnnotationUsage(
44-
AnnotationDescriptor<A> annotationDescriptor,
45-
AnnotationTarget target,
46-
SourceModelContext context) {
47-
this( annotationDescriptor, target, extractBaselineValues( annotationDescriptor, target, context ) );
34+
public DynamicAnnotationUsage( AnnotationDescriptor<A> annotationDescriptor, SourceModelContext context) {
35+
this( annotationDescriptor, extractBaselineValues( annotationDescriptor, context ) );
4836
}
4937

50-
private DynamicAnnotationUsage(
51-
AnnotationDescriptor<A> annotationDescriptor,
52-
AnnotationTarget target,
53-
Map<String, Object> values) {
38+
private DynamicAnnotationUsage(AnnotationDescriptor<A> annotationDescriptor, Map<String, Object> values) {
5439
this.annotationDescriptor = annotationDescriptor;
55-
this.target = target;
5640
this.values = values;
5741
}
5842

@@ -61,11 +45,6 @@ public AnnotationDescriptor<A> getAnnotationDescriptor() {
6145
return annotationDescriptor;
6246
}
6347

64-
@Override
65-
public AnnotationTarget getAnnotationTarget() {
66-
return target;
67-
}
68-
6948
@Override
7049
public A toAnnotation() {
7150
return AnnotationProxy.makeProxy( annotationDescriptor, values );
@@ -117,32 +96,28 @@ public <V> V setAttributeValue(String name, V value) {
11796

11897
private static <A extends Annotation> Map<String, Object> extractBaselineValues(
11998
AnnotationDescriptor<A> annotationDescriptor,
120-
AnnotationTarget target,
12199
SourceModelContext context) {
122100
final HashMap<String, Object> values = new HashMap<>();
123101
for ( AttributeDescriptor<?> attribute : annotationDescriptor.getAttributes() ) {
124102
values.put(
125103
attribute.getName(),
126-
extractDefaultValue( attribute.getAttributeMethod().getDefaultValue(), target, context )
104+
extractDefaultValue( attribute.getAttributeMethod().getDefaultValue(), context )
127105
);
128106
}
129107
return values;
130108
}
131109

132-
private static Object extractDefaultValue(
133-
Object value,
134-
AnnotationTarget target,
135-
SourceModelContext context) {
110+
private static Object extractDefaultValue(Object value, SourceModelContext context) {
136111
if ( value != null ) {
137112
if ( value.getClass().isArray() ) {
138-
return extractList( value, target, context );
113+
return extractList( value, context );
139114
}
140115
else if ( value instanceof Class<?> clazz ) {
141116
return context.getClassDetailsRegistry().resolveClassDetails( clazz.getName() );
142117
}
143118
else if ( value instanceof Annotation annotation ) {
144119
try {
145-
return extractAnnotation( annotation, target, context );
120+
return extractAnnotation( annotation, context );
146121
}
147122
catch (InvocationTargetException | IllegalAccessException e) {
148123
throw new AnnotationAccessException( "Error accessing default annotation-typed attribute", e );
@@ -152,33 +127,28 @@ else if ( value instanceof Annotation annotation ) {
152127
return value;
153128
}
154129

155-
private static <E> List<Object> extractList(
156-
Object value,
157-
AnnotationTarget target,
158-
SourceModelContext context) {
130+
private static <E> List<Object> extractList(Object value, SourceModelContext context) {
159131
final List<Object> result = new ArrayList<>();
160132
//noinspection unchecked
161133
final E[] array = (E[]) value;
162134
for ( E element : array ) {
163-
result.add( extractDefaultValue( element, target, context ) );
135+
result.add( extractDefaultValue( element, context ) );
164136
}
165137
return result;
166138
}
167139

168-
private static DynamicAnnotationUsage<?> extractAnnotation(
169-
Annotation annotation,
170-
AnnotationTarget target,
171-
SourceModelContext context) throws InvocationTargetException, IllegalAccessException {
140+
private static DynamicAnnotationUsage<?> extractAnnotation(Annotation annotation, SourceModelContext context)
141+
throws InvocationTargetException, IllegalAccessException {
172142
final Class<? extends Annotation> annotationType = annotation.annotationType();
173143
final AnnotationDescriptor<?> descriptor = context.getAnnotationDescriptorRegistry()
174144
.getDescriptor( annotationType );
175145
final Map<String, Object> values = new HashMap<>();
176146
for ( AttributeDescriptor<?> attribute : descriptor.getAttributes() ) {
177147
values.put(
178148
attribute.getName(),
179-
extractDefaultValue( attribute.getAttributeMethod().invoke( annotation ), target, context )
149+
extractDefaultValue( attribute.getAttributeMethod().invoke( annotation ), context )
180150
);
181151
}
182-
return new DynamicAnnotationUsage<>( descriptor, target, values );
152+
return new DynamicAnnotationUsage<>( descriptor, values );
183153
}
184154
}

src/main/java/org/hibernate/models/internal/jandex/AbstractAnnotationTarget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public AbstractAnnotationTarget(SourceModelBuildingContext buildingContext) {
3434
@Override
3535
public Map<Class<? extends Annotation>, AnnotationUsage<?>> getUsageMap() {
3636
if ( usageMap == null ) {
37-
usageMap = AnnotationUsageBuilder.collectUsages( getJandexAnnotationTarget(), this, buildingContext );
37+
usageMap = AnnotationUsageBuilder.collectUsages( getJandexAnnotationTarget(), buildingContext );
3838
}
3939
return usageMap;
4040
}

src/main/java/org/hibernate/models/internal/jandex/AbstractValueExtractor.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.hibernate.models.internal.jandex;
88

9-
import org.hibernate.models.spi.AnnotationTarget;
109
import org.hibernate.models.spi.SourceModelBuildingContext;
1110
import org.hibernate.models.spi.ValueExtractor;
1211

@@ -18,20 +17,16 @@
1817
*/
1918
public abstract class AbstractValueExtractor<W> implements ValueExtractor<AnnotationInstance,W> {
2019

21-
protected abstract W extractAndWrap(
22-
AnnotationValue jandexValue,
23-
AnnotationTarget target,
24-
SourceModelBuildingContext buildingContext);
20+
protected abstract W extractAndWrap(AnnotationValue jandexValue, SourceModelBuildingContext buildingContext);
2521

2622
@Override
2723
public W extractValue(
2824
AnnotationInstance annotation,
2925
String attributeName,
30-
AnnotationTarget target,
3126
SourceModelBuildingContext buildingContext) {
3227
final AnnotationValue jandexValue = resolveAnnotationValue( annotation, attributeName, buildingContext );
3328
assert jandexValue != null;
34-
return extractAndWrap( jandexValue, target, buildingContext );
29+
return extractAndWrap( jandexValue, buildingContext );
3530
}
3631

3732
protected AnnotationValue resolveAnnotationValue(

src/main/java/org/hibernate/models/internal/jandex/AnnotationUsageBuilder.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.hibernate.models.internal.util.CollectionHelper;
2222
import org.hibernate.models.spi.AnnotationDescriptor;
2323
import org.hibernate.models.spi.AnnotationDescriptorRegistry;
24-
import org.hibernate.models.spi.AnnotationTarget;
2524
import org.hibernate.models.spi.AnnotationUsage;
2625
import org.hibernate.models.spi.AttributeDescriptor;
2726
import org.hibernate.models.spi.SourceModelBuildingContext;
@@ -47,15 +46,13 @@ public class AnnotationUsageBuilder {
4746
*/
4847
public static Map<Class<? extends Annotation>, AnnotationUsage<?>> collectUsages(
4948
org.jboss.jandex.AnnotationTarget jandexAnnotationTarget,
50-
AnnotationTarget target,
5149
SourceModelBuildingContext buildingContext) {
5250
if ( jandexAnnotationTarget == null ) {
5351
return Collections.emptyMap();
5452
}
5553
final Map<Class<? extends Annotation>, AnnotationUsage<?>> result = new HashMap<>();
5654
processAnnotations(
5755
jandexAnnotationTarget.declaredAnnotations(),
58-
target,
5956
result::put,
6057
buildingContext
6158
);
@@ -67,7 +64,6 @@ public static Map<Class<? extends Annotation>, AnnotationUsage<?>> collectUsages
6764
*/
6865
public static void processAnnotations(
6966
Collection<AnnotationInstance> annotations,
70-
AnnotationTarget target,
7167
BiConsumer<Class<? extends Annotation>, AnnotationUsage<?>> consumer,
7268
SourceModelBuildingContext buildingContext) {
7369
final AnnotationDescriptorRegistry annotationDescriptorRegistry = buildingContext.getAnnotationDescriptorRegistry();
@@ -88,7 +84,6 @@ public static void processAnnotations(
8884
final AnnotationUsage<?> usage = makeUsage(
8985
annotation,
9086
annotationDescriptor,
91-
target,
9287
buildingContext
9388
);
9489
consumer.accept( annotationType, usage );
@@ -98,9 +93,8 @@ public static void processAnnotations(
9893
public static <A extends Annotation> AnnotationUsage<A> makeUsage(
9994
AnnotationInstance annotation,
10095
AnnotationDescriptor<A> annotationDescriptor,
101-
AnnotationTarget target,
10296
SourceModelBuildingContext buildingContext) {
103-
return new JandexAnnotationUsage<>( annotation, annotationDescriptor, target, buildingContext );
97+
return new JandexAnnotationUsage<>( annotation, annotationDescriptor, buildingContext );
10498
}
10599

106100
/**
@@ -110,7 +104,6 @@ public static <A extends Annotation> AnnotationUsage<A> makeUsage(
110104
public static <A extends Annotation> Map<String,?> extractAttributeValues(
111105
AnnotationInstance annotationInstance,
112106
AnnotationDescriptor<A> annotationDescriptor,
113-
AnnotationTarget target,
114107
SourceModelBuildingContext buildingContext) {
115108
if ( CollectionHelper.isEmpty( annotationDescriptor.getAttributes() ) ) {
116109
return Collections.emptyMap();
@@ -122,7 +115,7 @@ public static <A extends Annotation> Map<String,?> extractAttributeValues(
122115
final ValueExtractor<AnnotationInstance, ?> extractor = attributeDescriptor
123116
.getTypeDescriptor()
124117
.createJandexExtractor( buildingContext );
125-
final Object attributeValue = extractor.extractValue( annotationInstance, attributeDescriptor, target, buildingContext );
118+
final Object attributeValue = extractor.extractValue( annotationInstance, attributeDescriptor, buildingContext );
126119
valueMap.put( attributeDescriptor.getName(), attributeValue );
127120
}
128121
return valueMap;

src/main/java/org/hibernate/models/internal/jandex/ArrayValueExtractor.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import java.util.List;
1010

11-
import org.hibernate.models.spi.AnnotationTarget;
1211
import org.hibernate.models.spi.SourceModelBuildingContext;
1312
import org.hibernate.models.spi.ValueWrapper;
1413

@@ -25,15 +24,12 @@ public ArrayValueExtractor(ValueWrapper<List<V>,AnnotationValue> wrapper) {
2524
}
2625

2726
@Override
28-
protected List<V> extractAndWrap(
29-
AnnotationValue jandexValue,
30-
AnnotationTarget target,
31-
SourceModelBuildingContext buildingContext) {
27+
protected List<V> extractAndWrap(AnnotationValue jandexValue, SourceModelBuildingContext buildingContext) {
3228
assert jandexValue != null;
3329

3430
final List<AnnotationValue> values = jandexValue.asArrayList();
3531
assert values != null;
3632

37-
return wrapper.wrap( jandexValue, target, buildingContext );
33+
return wrapper.wrap( jandexValue, buildingContext );
3834
}
3935
}

src/main/java/org/hibernate/models/internal/jandex/ArrayValueWrapper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.Collections;
1111
import java.util.List;
1212

13-
import org.hibernate.models.spi.AnnotationTarget;
1413
import org.hibernate.models.spi.SourceModelBuildingContext;
1514
import org.hibernate.models.spi.ValueWrapper;
1615

@@ -27,7 +26,7 @@ public ArrayValueWrapper(ValueWrapper<V, AnnotationValue> elementWrapper) {
2726
}
2827

2928
@Override
30-
public List<V> wrap(AnnotationValue rawValue, AnnotationTarget target, SourceModelBuildingContext buildingContext) {
29+
public List<V> wrap(AnnotationValue rawValue, SourceModelBuildingContext buildingContext) {
3130
assert rawValue != null;
3231

3332
final List<AnnotationValue> values = rawValue.asArrayList();
@@ -38,12 +37,12 @@ public List<V> wrap(AnnotationValue rawValue, AnnotationTarget target, SourceMod
3837
}
3938

4039
if ( values.size() == 1 ) {
41-
return Collections.singletonList( elementWrapper.wrap( values.get(0), target, buildingContext ) );
40+
return Collections.singletonList( elementWrapper.wrap( values.get(0), buildingContext ) );
4241
}
4342

4443
final List<V> results = new ArrayList<>( values.size() );
4544
values.forEach( (value) -> {
46-
results.add( elementWrapper.wrap( value, target, buildingContext ) );
45+
results.add( elementWrapper.wrap( value, buildingContext ) );
4746
} );
4847
return results;
4948
}

src/main/java/org/hibernate/models/internal/jandex/BooleanValueExtractor.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.hibernate.models.internal.jandex;
88

9-
import org.hibernate.models.spi.AnnotationTarget;
109
import org.hibernate.models.spi.SourceModelBuildingContext;
1110

1211
import org.jboss.jandex.AnnotationValue;
@@ -20,11 +19,8 @@ public class BooleanValueExtractor extends AbstractValueExtractor<Boolean> {
2019
public static final BooleanValueExtractor JANDEX_BOOLEAN_EXTRACTOR = new BooleanValueExtractor();
2120

2221
@Override
23-
protected Boolean extractAndWrap(
24-
AnnotationValue jandexValue,
25-
AnnotationTarget target,
26-
SourceModelBuildingContext buildingContext) {
22+
protected Boolean extractAndWrap(AnnotationValue jandexValue, SourceModelBuildingContext buildingContext) {
2723
assert jandexValue != null;
28-
return BooleanValueWrapper.JANDEX_BOOLEAN_VALUE_WRAPPER.wrap( jandexValue, target, buildingContext );
24+
return BooleanValueWrapper.JANDEX_BOOLEAN_VALUE_WRAPPER.wrap( jandexValue, buildingContext );
2925
}
3026
}

src/main/java/org/hibernate/models/internal/jandex/BooleanValueWrapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.hibernate.models.internal.jandex;
88

9-
import org.hibernate.models.spi.AnnotationTarget;
109
import org.hibernate.models.spi.SourceModelBuildingContext;
1110
import org.hibernate.models.spi.ValueWrapper;
1211

@@ -21,7 +20,7 @@ public class BooleanValueWrapper implements ValueWrapper<Boolean, AnnotationValu
2120
public static final BooleanValueWrapper JANDEX_BOOLEAN_VALUE_WRAPPER = new BooleanValueWrapper();
2221

2322
@Override
24-
public Boolean wrap(AnnotationValue rawValue, AnnotationTarget target, SourceModelBuildingContext buildingContext) {
23+
public Boolean wrap(AnnotationValue rawValue, SourceModelBuildingContext buildingContext) {
2524
assert rawValue != null;
2625
return rawValue.asBoolean();
2726
}

src/main/java/org/hibernate/models/internal/jandex/ByteValueExtractor.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.hibernate.models.internal.jandex;
88

9-
import org.hibernate.models.spi.AnnotationTarget;
109
import org.hibernate.models.spi.SourceModelBuildingContext;
1110

1211
import org.jboss.jandex.AnnotationValue;
@@ -20,11 +19,8 @@ public class ByteValueExtractor extends AbstractValueExtractor<Byte> {
2019
public static final ByteValueExtractor JANDEX_BYTE_EXTRACTOR = new ByteValueExtractor();
2120

2221
@Override
23-
protected Byte extractAndWrap(
24-
AnnotationValue jandexValue,
25-
AnnotationTarget target,
26-
SourceModelBuildingContext buildingContext) {
22+
protected Byte extractAndWrap(AnnotationValue jandexValue, SourceModelBuildingContext buildingContext) {
2723
assert jandexValue != null;
28-
return ByteValueWrapper.JANDEX_BYTE_VALUE_WRAPPER.wrap( jandexValue, target, buildingContext );
24+
return ByteValueWrapper.JANDEX_BYTE_VALUE_WRAPPER.wrap( jandexValue, buildingContext );
2925
}
3026
}

src/main/java/org/hibernate/models/internal/jandex/ByteValueWrapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.hibernate.models.internal.jandex;
88

9-
import org.hibernate.models.spi.AnnotationTarget;
109
import org.hibernate.models.spi.SourceModelBuildingContext;
1110
import org.hibernate.models.spi.ValueWrapper;
1211

@@ -21,7 +20,7 @@ public class ByteValueWrapper implements ValueWrapper<Byte, AnnotationValue> {
2120
public static final ByteValueWrapper JANDEX_BYTE_VALUE_WRAPPER = new ByteValueWrapper();
2221

2322
@Override
24-
public Byte wrap(AnnotationValue rawValue, AnnotationTarget target, SourceModelBuildingContext buildingContext) {
23+
public Byte wrap(AnnotationValue rawValue, SourceModelBuildingContext buildingContext) {
2524
assert rawValue != null;
2625
return rawValue.asByte();
2726
}

0 commit comments

Comments
 (0)