HHH-14768 Fix recursive type variable rendering

This commit is contained in:
Christian Beikov 2021-08-02 09:32:15 +02:00
parent 96c96c67ea
commit d87e8a387f
3 changed files with 23 additions and 1 deletions

View File

@ -6,7 +6,9 @@
*/
package org.hibernate.jpamodelgen.util;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeParameterElement;
@ -30,6 +32,7 @@ import javax.lang.model.util.SimpleTypeVisitor8;
public final class TypeRenderingVisitor extends SimpleTypeVisitor8<Object, Object> {
private final StringBuilder sb = new StringBuilder();
private final Set<TypeVariable> visitedTypeVariables = new HashSet<>();
private TypeRenderingVisitor() {
}
@ -129,9 +132,10 @@ public final class TypeRenderingVisitor extends SimpleTypeVisitor8<Object, Objec
if ( typeVariableElement instanceof TypeParameterElement ) {
final TypeParameterElement typeParameter = (TypeParameterElement) typeVariableElement;
sb.append( typeParameter );
if ( !"java.lang.Object".equals( t.getUpperBound().toString() ) ) {
if ( !"java.lang.Object".equals( t.getUpperBound().toString() ) && visitedTypeVariables.add( t ) ) {
sb.append( " extends " );
t.getUpperBound().accept( this, null );
visitedTypeVariables.remove( t );
}
}
else {

View File

@ -93,4 +93,11 @@ public class CollectionAsBasicTypeTest extends CompilationTest {
public void testIntersectionType() {
assertMetamodelClassGeneratedFor( ConcreteLike.class );
}
@Test
@TestForIssue(jiraKey = "HHH-14724")
@WithClasses({ EnumHolder.class })
public void testRecursiveTypeVariable() {
assertMetamodelClassGeneratedFor( EnumHolder.class );
}
}

View File

@ -0,0 +1,11 @@
package org.hibernate.jpamodelgen.test.collectionbasictype;
import javax.persistence.Entity;
@Entity
public class EnumHolder {
public <E extends Enum<E>> E getMyEnum() {
return null;
}
}