Skip to content

Commit

Permalink
Fix Scala-generated QueryDSL path classes.
Browse files Browse the repository at this point in the history
Resolve the static field of the given type inside the specified domain class by considering both the provided Java and Scala object path class names.

Useful for handling of Scala-generated QueryDSL path classes.

Issue: 1392
  • Loading branch information
etrandafir93 committed Jan 19, 2024
1 parent fe885b3 commit 83350f9
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public <T> EntityPath<T> createPath(Class<T> domainClass) {
Class<?> pathClass = ClassUtils.forName(pathClassName, domainClass.getClassLoader());

return getStaticFieldOfType(pathClass)//
.or(() -> getFieldForScalaObject(domainClass, pathClassName))//
.map(it -> (EntityPath<T>) ReflectionUtils.getField(it, null))//
.orElseThrow(() -> new IllegalStateException(String.format(NO_FIELD_FOUND_TEMPLATE, pathClass)));

Expand All @@ -80,6 +81,23 @@ public <T> EntityPath<T> createPath(Class<T> domainClass) {
}
}

/**
* Resolves the static field of the given type inside the specified domain class.
* Useful for handling Scala-generated QueryDSL path classes.
*
* @param domainClass The domain class for which the static field needs to be resolved.
* @param javaPathClassName The Java path class name without the "$" suffix.
* @return
*/
private <T> Optional<Field> getFieldForScalaObject(Class<T> domainClass, String javaPathClassName) {
try {
Class<?> scalaPathClass = ClassUtils.forName(javaPathClassName + "$", domainClass.getClassLoader());
return getStaticFieldOfType(scalaPathClass);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

/**
* Returns the first static field of the given type inside the given type.
*
Expand Down

0 comments on commit 83350f9

Please sign in to comment.