Skip to content

Commit a8f235e

Browse files
committed
apply same rule to Restriction that we apply to Order/Sort
at least for now
1 parent 7840593 commit a8f235e

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,33 +1791,33 @@ private void createCriteriaFinder(
17911791
);
17921792
}
17931793

1794-
private void checkFinderParameter(@Nullable TypeElement entity, VariableElement parameter) {
1794+
private void checkFinderParameter(@Nullable TypeElement entityType, VariableElement parameter) {
17951795
final Types types = context.getTypeUtils();
17961796
final TypeMirror parameterType = parameterType(parameter);
17971797
final String typeName = parameterType.toString();
1798-
if ( isRestrictionParam( typeName ) ) {
1799-
final TypeMirror typeArgument = getTypeArgument( parameterType );
1800-
final TypeElement implicitEntityType = entity == null ? primaryEntity : entity;
1801-
if ( implicitEntityType != null ) {
1802-
if ( typeArgument == null ) {
1803-
missingTypeArgError( implicitEntityType.getSimpleName().toString(), parameter, typeName );
1804-
}
1805-
else if ( !types.isSameType( typeArgument, implicitEntityType.asType() ) ) {
1806-
wrongTypeArgError( implicitEntityType.getSimpleName().toString(), parameter, typeName );
1807-
}
1808-
}
1809-
// else {
1810-
// message( parameter, "repository method does have well-defined entity type", Diagnostic.Kind.ERROR );
1798+
// TODO: we could allow restrictions even when the query returns a projection,
1799+
// but this would require some sort of change to Hibernate core, perhaps
1800+
// adding <T> SelectionQuery<T> setProjection(Class<T> recordType)
1801+
// if ( isRestrictionParam( typeName ) ) {
1802+
// final TypeMirror typeArgument = getTypeArgument( parameterType );
1803+
// final TypeElement implicitEntityType = entityType == null ? primaryEntity : entityType;
1804+
// if ( implicitEntityType != null ) {
1805+
// if ( typeArgument == null ) {
1806+
// missingTypeArgError( implicitEntityType.getSimpleName().toString(), parameter, typeName );
1807+
// }
1808+
// else if ( !types.isSameType( typeArgument, implicitEntityType.asType() ) ) {
1809+
// wrongTypeArgError( implicitEntityType.getSimpleName().toString(), parameter, typeName );
1810+
// }
18111811
// }
1812-
}
1813-
else if ( isOrderParam( typeName ) ) {
1812+
// }
1813+
if ( isOrderParam( typeName ) || isRestrictionParam( typeName ) ) {
18141814
final TypeMirror typeArgument = getTypeArgument( parameterType );
1815-
if ( entity != null ) {
1815+
if ( entityType != null ) {
18161816
if ( typeArgument == null ) {
1817-
missingTypeArgError( entity.getSimpleName().toString(), parameter, typeName );
1817+
missingTypeArgError( entityType, parameter, typeName );
18181818
}
1819-
else if ( !types.isSameType( typeArgument, entity.asType() ) ) {
1820-
wrongTypeArgError( entity.getSimpleName().toString(), parameter, typeName );
1819+
else if ( !types.isSameType( typeArgument, entityType.asType() ) ) {
1820+
wrongTypeArgError( entityType, parameter, typeName );
18211821
}
18221822
}
18231823
else {
@@ -1869,31 +1869,32 @@ private void createCriteriaDelete(ExecutableElement method) {
18691869
}
18701870
}
18711871

1872-
private void wrongTypeArgError(String entity, VariableElement parameter, String parameterType) {
1873-
message(parameter, "mismatched type of " + message(parameterType, entity),
1872+
private void wrongTypeArgError(TypeElement entityType, VariableElement parameter, String parameterType) {
1873+
message(parameter, "mismatched type of " + message(parameterType, entityType),
18741874
Diagnostic.Kind.ERROR );
18751875
}
18761876

1877-
private void missingTypeArgError(String entity, VariableElement parameter, String parameterType) {
1878-
message(parameter, "missing type of " + message(parameterType, entity),
1877+
private void missingTypeArgError(TypeElement entityType, VariableElement parameter, String parameterType) {
1878+
message(parameter, "missing type of " + message(parameterType, entityType),
18791879
Diagnostic.Kind.ERROR );
18801880
}
18811881

1882-
private String message(String parameterType, String entity) {
1882+
private String message(String parameterType, TypeElement entityType) {
1883+
final String entityTypeName = entityType.getSimpleName().toString();
18831884
if (parameterType.startsWith(HIB_ORDER) || parameterType.startsWith(JD_ORDER)) {
1884-
return "order (should be 'Order<? super " + entity + ">')";
1885+
return "order (should be 'Order<? super " + entityTypeName + ">')";
18851886
}
18861887
else if (parameterType.startsWith(LIST + "<" + HIB_ORDER)) {
1887-
return "order (should be 'List<Order<? super " + entity + ">>')";
1888+
return "order (should be 'List<Order<? super " + entityTypeName + ">>')";
18881889
}
18891890
else if (parameterType.startsWith(HIB_RESTRICTION)) {
1890-
return "restriction (should be 'Restriction<? super " + entity + ">')";
1891+
return "restriction (should be 'Restriction<? super " + entityTypeName + ">')";
18911892
}
18921893
else if (parameterType.startsWith(LIST + "<" + HIB_RESTRICTION)) {
1893-
return "restriction (should be 'List<Restriction<? super " + entity + ">>')";
1894+
return "restriction (should be 'List<Restriction<? super " + entityTypeName + ">>')";
18941895
}
18951896
else if (parameterType.startsWith(JD_SORT)) {
1896-
return "sort (should be 'Sort<? super " + entity + ">')";
1897+
return "sort (should be 'Sort<? super " + entityTypeName + ">')";
18971898
}
18981899
else {
18991900
return "parameter";

0 commit comments

Comments
 (0)