Skip to content

Commit ffa686a

Browse files
committed
#80 - Investigate use of MethodHandles instead of Constructor and Method references
1 parent bb96f1e commit ffa686a

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

hibernate-models/src/main/java/org/hibernate/models/internal/AnnotationUsageHelper.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static <A extends Annotation, C extends Annotation> void forEachRepeatedA
101101
if ( container != null ) {
102102
final AnnotationDescriptor<C> containerDescriptor = modelContext.getAnnotationDescriptorRegistry().getDescriptor( containerType );
103103
final AttributeDescriptor<A[]> attribute = containerDescriptor.getAttribute( "value" );
104-
final A[] repetitions = AnnotationHelper.extractValue( container, attribute, modelContext );
104+
final A[] repetitions = AnnotationHelper.extractValue( container, attribute );
105105
CollectionHelper.forEach( repetitions, consumer );
106106
}
107107
}
@@ -122,7 +122,7 @@ public static <A extends Annotation> void forEachRepeatedAnnotationUsages(
122122
if ( container != null ) {
123123
final AnnotationDescriptor<?> containerDescriptor = modelContext.getAnnotationDescriptorRegistry().getDescriptor( containerType );
124124
final AttributeDescriptor<A[]> attribute = containerDescriptor.getAttribute( "value" );
125-
final A[] repetitions = AnnotationHelper.extractValue( container, attribute, modelContext );
125+
final A[] repetitions = AnnotationHelper.extractValue( container, attribute );
126126
CollectionHelper.forEach( repetitions, consumer );
127127
}
128128
}
@@ -140,7 +140,7 @@ public static <A extends Annotation> A[] getRepeatedUsages(
140140

141141
if ( containerUsage != null ) {
142142
final AttributeDescriptor<A[]> attribute = type.getRepeatableContainer().getAttribute( "value" );
143-
final A[] repeatableValues = AnnotationHelper.extractValue( containerUsage, attribute, modelContext );
143+
final A[] repeatableValues = AnnotationHelper.extractValue( containerUsage, attribute );
144144

145145
if ( CollectionHelper.isNotEmpty( repeatableValues ) ) {
146146
if ( usage != null ) {
@@ -207,7 +207,7 @@ private static <A extends Annotation> boolean nameMatches(
207207
String attributeToMatch,
208208
SourceModelBuildingContext modelContext) {
209209
final AttributeDescriptor<String> attributeDescriptor = descriptor.getAttribute( attributeToMatch );
210-
final String usageName = AnnotationHelper.extractValue( annotationUsage, attributeDescriptor, modelContext );
210+
final String usageName = AnnotationHelper.extractValue( annotationUsage, attributeDescriptor );
211211
return matchValue.equals( usageName );
212212
}
213213

hibernate-models/src/main/java/org/hibernate/models/internal/OrmAnnotationDescriptor.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.List;
1313
import java.util.Map;
1414

15+
import org.hibernate.models.ModelsException;
1516
import org.hibernate.models.spi.AnnotationDescriptor;
1617
import org.hibernate.models.spi.AttributeDescriptor;
1718
import org.hibernate.models.spi.MutableAnnotationDescriptor;
@@ -116,7 +117,7 @@ private static <A extends Annotation, C extends A> MethodHandle resolveConstruct
116117
return MethodHandles.publicLookup().findConstructor( concreteClass, methodType );
117118
}
118119
catch (Exception e) {
119-
throw new MethodResolutionException( "Unable to locate default-variant constructor for `" + concreteClass.getName() + "`", e );
120+
throw new ModelsException( "Unable to locate default-variant constructor for `" + concreteClass.getName() + "`", e );
120121
}
121122
}
122123

@@ -131,7 +132,7 @@ public C createUsage(SourceModelBuildingContext context) {
131132
return (C) constructor.invoke( context );
132133
}
133134
catch (Throwable e) {
134-
throw new MethodInvocationException( "Unable to invoke default-variant constructor for `" + concreteClass.getName() + "`", e );
135+
throw new ModelsException( "Unable to invoke default-variant constructor for `" + concreteClass.getName() + "`", e );
135136
}
136137
}
137138
}
@@ -152,7 +153,7 @@ private static <A extends Annotation, C extends A> MethodHandle resolveConstruct
152153
return MethodHandles.publicLookup().findConstructor( concreteClass, methodType );
153154
}
154155
catch (Exception e) {
155-
throw new MethodResolutionException( "Unable to locate JDK-variant constructor for `" + concreteClass.getName() + "`", e );
156+
throw new ModelsException( "Unable to locate JDK-variant constructor for `" + concreteClass.getName() + "`", e );
156157
}
157158
}
158159

@@ -167,7 +168,7 @@ public C createUsage(A jdkAnnotation, SourceModelBuildingContext context) {
167168
return (C) constructor.invoke( jdkAnnotation, context );
168169
}
169170
catch (Throwable e) {
170-
throw new MethodInvocationException( "Unable to invoke JDK-variant constructor for `" + concreteClass.getName() + "`", e );
171+
throw new ModelsException( "Unable to invoke JDK-variant constructor for `" + concreteClass.getName() + "`", e );
171172
}
172173
}
173174
}
@@ -182,11 +183,11 @@ public DeTypedCreator(Class<A> annotationType, Class<C> concreteClass) {
182183

183184
private static <A extends Annotation, C extends A> MethodHandle resolveConstructor(Class<C> concreteClass) {
184185
try {
185-
final MethodType methodType = MethodType.methodType( void.class, AnnotationInstance.class, SourceModelBuildingContext.class );
186+
final MethodType methodType = MethodType.methodType( void.class, Map.class, SourceModelBuildingContext.class );
186187
return MethodHandles.publicLookup().findConstructor( concreteClass, methodType );
187188
}
188189
catch (Exception e) {
189-
throw new MethodResolutionException( "Unable to locate Jandex-variant constructor for `" + concreteClass.getName() + "`", e );
190+
throw new ModelsException( "Unable to locate Jandex-variant constructor for `" + concreteClass.getName() + "`", e );
190191
}
191192
}
192193

@@ -201,7 +202,7 @@ public C createUsage(Map<String,?> attributeValues, SourceModelBuildingContext c
201202
return (C) constructor.invoke( attributeValues, context );
202203
}
203204
catch (Throwable e) {
204-
throw new MethodInvocationException( "Unable to invoke Jandex-variant constructor for `" + concreteClass.getName() + "`", e );
205+
throw new ModelsException( "Unable to invoke Jandex-variant constructor for `" + concreteClass.getName() + "`", e );
205206
}
206207
}
207208
}

0 commit comments

Comments
 (0)