Skip to content

Commit 9a79cdf

Browse files
committed
Javadoc, tests and cleanup
1 parent a87aac8 commit 9a79cdf

13 files changed

+188
-85
lines changed

src/main/java/org/hibernate/models/IllegalCastException.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77

88
package org.hibernate.models;
99

10+
import org.hibernate.models.spi.AnnotationTarget;
11+
1012
/**
13+
* Indicates an illegal cast through one of the safe cast methods
14+
* such as {@linkplain AnnotationTarget#asClassDetails()},
15+
* {@linkplain AnnotationTarget#asMemberDetails()}, etc.
16+
*
1117
* @author Steve Ebersole
1218
*/
1319
public class IllegalCastException extends ModelsException {

src/main/java/org/hibernate/models/ModelsException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
package org.hibernate.models;
99

1010
/**
11-
* Base exception for models building
11+
* Base exception for hibernate-models
1212
*
1313
* @author Steve Ebersole
1414
*/

src/main/java/org/hibernate/models/UnknownAnnotationAttributeException.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
*/
2020
public class UnknownAnnotationAttributeException extends ModelsException {
2121
public UnknownAnnotationAttributeException(Class<? extends Annotation> annotationType, String attributeName) {
22-
this(
23-
String.format(
24-
Locale.ROOT,
25-
"Unable to locate attribute named `%s` on annotation `%s`",
26-
attributeName,
27-
annotationType.getName()
28-
)
29-
);
22+
this( String.format(
23+
Locale.ROOT,
24+
"Unable to locate attribute named `%s` on annotation `%s`",
25+
attributeName,
26+
annotationType.getName()
27+
) );
3028
}
3129

3230
public UnknownAnnotationAttributeException(String message) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import java.lang.annotation.Annotation;
1010
import java.lang.annotation.Repeatable;
11+
import java.util.Collections;
12+
import java.util.HashMap;
1113

1214
import org.hibernate.models.internal.jdk.AnnotationDescriptorImpl;
1315
import org.hibernate.models.spi.AnnotationDescriptor;
@@ -79,6 +81,9 @@ private <A extends Annotation> AnnotationDescriptor<A> buildAdHocAnnotationDescr
7981

8082
@Override
8183
public AnnotationDescriptorRegistry makeImmutableCopy() {
82-
return new AnnotationDescriptorRegistryImmutable( descriptorMap, repeatableByContainerMap );
84+
return new AnnotationDescriptorRegistryImmutable(
85+
java.util.Map.copyOf( descriptorMap ),
86+
java.util.Map.copyOf( repeatableByContainerMap )
87+
);
8388
}
8489
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.util.ArrayList;
1010
import java.util.List;
11+
import java.util.Map;
1112

1213
import org.hibernate.models.UnknownClassException;
1314
import org.hibernate.models.internal.jandex.JandexBuilders;
@@ -134,6 +135,9 @@ public ClassDetails buildClassDetails(String name, SourceModelBuildingContext bu
134135

135136
@Override
136137
public ClassDetailsRegistry makeImmutableCopy() {
137-
return new ClassDetailsRegistryImmutable( classDetailsMap, subTypeClassDetailsMap );
138+
return new ClassDetailsRegistryImmutable(
139+
Map.copyOf( classDetailsMap ),
140+
Map.copyOf( subTypeClassDetailsMap )
141+
);
138142
}
139143
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,31 @@
1717
import org.jboss.jandex.Indexer;
1818

1919
/**
20+
* Helper for dealing with the Jandex {@linkplain Indexer}
21+
*
2022
* @author Steve Ebersole
2123
*/
2224
public class JandexIndexerHelper {
25+
/**
26+
* Apply a class to the indexer
27+
*
28+
* @param clazz The class to apply to the indexer
29+
* @param indexer The Jandex Indexer
30+
* @param classLoading Used to load the class file (bytes)
31+
*
32+
* @implNote Simply delegates to {@linkplain #apply(String, Indexer, ClassLoading)} with the class name
33+
*/
2334
public static void apply(Class<?> clazz, Indexer indexer, ClassLoading classLoading) {
2435
apply( clazz.getName(), indexer, classLoading );
2536
}
2637

38+
/**
39+
* Apply a class to the indexer
40+
*
41+
* @param className The class to apply to the indexer
42+
* @param indexer The Jandex Indexer
43+
* @param classLoading Used to load the class file (bytes)
44+
*/
2745
public static void apply(String className, Indexer indexer, ClassLoading classLoading) {
2846
final String resourceName = StringHelper.classNameToResourceName( className );
2947
final URL resource = classLoading.locateResource( resourceName );

src/main/java/org/hibernate/models/internal/jdk/JdkClassDetails.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.hibernate.models.internal.ClassDetailsSupport;
2020
import org.hibernate.models.internal.util.CollectionHelper;
21-
import org.hibernate.models.internal.util.TypeHelper;
2221
import org.hibernate.models.spi.ClassDetails;
2322
import org.hibernate.models.spi.ClassDetailsRegistry;
2423
import org.hibernate.models.spi.FieldDetails;
@@ -89,7 +88,7 @@ public String getClassName() {
8988

9089
@Override
9190
public boolean isResolved() {
92-
return TypeHelper.isResolved( managedClass );
91+
return true;
9392
}
9493

9594
@Override

src/main/java/org/hibernate/models/internal/util/TypeHelper.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/main/java/org/hibernate/models/spi/AnnotationDescriptorRegistry.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public interface AnnotationDescriptorRegistry {
3434
*/
3535
<A extends Annotation> AnnotationDescriptor<A> getContainedRepeatableDescriptor(Class<A> javaType);
3636

37+
/**
38+
* Make a copy of this registry which cannot be added-to.
39+
*/
3740
AnnotationDescriptorRegistry makeImmutableCopy();
3841

3942
@FunctionalInterface

src/main/java/org/hibernate/models/spi/TypeDetailsHelper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,16 @@ public class TypeDetailsHelper {
4343
*/
4444
public static TypeDetails resolveRelativeType(TypeDetails type, TypeVariableScope container) {
4545
switch ( type.getTypeKind() ) {
46-
case CLASS, PRIMITIVE, VOID, ARRAY, WILDCARD_TYPE -> {
46+
case CLASS, PRIMITIVE, VOID, WILDCARD_TYPE -> {
4747
return type;
4848
}
49+
case ARRAY -> {
50+
final ArrayTypeDetails arrayType = type.asArrayType();
51+
return new ArrayTypeDetailsImpl(
52+
arrayType.getArrayClassDetails(),
53+
arrayType.getConstituentType().determineRelativeType( container )
54+
);
55+
}
4956
case PARAMETERIZED_TYPE -> {
5057
final ParameterizedTypeDetails parameterizedType = type.asParameterizedType();
5158
final List<TypeDetails> resolvedArguments;

0 commit comments

Comments
 (0)