diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/Context.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/Context.java index c2076f02ff..8350400e6f 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/Context.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/Context.java @@ -504,12 +504,25 @@ public final class Context { return enumTypesByValue; } - public void addEnumValue(String type, String value) { - enumTypesByValue.computeIfAbsent( value, s -> new TreeSet<>() ).add( type ); + public void addEnumValue( + String qualifiedTypeName, String shortTypeName, + @Nullable String outerTypeQualifiedName, @Nullable String outerShortTypeName, + String value) { + addEnumValue( qualifiedTypeName, value ); + addEnumValue( qualifiedTypeName, qualifiedTypeName + '.' + value ); + addEnumValue( qualifiedTypeName, shortTypeName + '.' + value ); + if ( outerShortTypeName != null ) { + addEnumValue( qualifiedTypeName, outerShortTypeName + '.' + shortTypeName + '.' + value ); + addEnumValue( qualifiedTypeName, outerShortTypeName + '$' + shortTypeName + '.' + value ); + addEnumValue( qualifiedTypeName, outerTypeQualifiedName + '$' + shortTypeName + '.' + value ); + } } - @Nullable - public TypeElement entityType(String entityName) { + private void addEnumValue(String qualifiedTypeName, String value) { + enumTypesByValue.computeIfAbsent( value, s -> new TreeSet<>() ).add( qualifiedTypeName ); + } + + public @Nullable TypeElement entityType(String entityName) { final Elements elementUtils = getElementUtils(); final String qualifiedName = qualifiedNameForEntityName(entityName); if ( qualifiedName != null ) { diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java index 67be05713c..88e5696910 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java @@ -643,9 +643,15 @@ public class HibernateProcessor extends AbstractProcessor { final DeclaredType declaredType = (DeclaredType) type; final TypeElement fieldType = (TypeElement) declaredType.asElement(); if ( fieldType.getKind() == ElementKind.ENUM ) { - for (Element enumMember : fieldType.getEnclosedElements() ) { + for ( Element enumMember : fieldType.getEnclosedElements() ) { if ( enumMember.getKind() == ElementKind.ENUM_CONSTANT ) { + final Element enclosingElement = fieldType.getEnclosingElement(); + final boolean hasOuterType = + enclosingElement.getKind().isClass() || enclosingElement.getKind().isInterface(); context.addEnumValue( fieldType.getQualifiedName().toString(), + fieldType.getSimpleName().toString(), + hasOuterType ? ((TypeElement) enclosingElement).getQualifiedName().toString() : null, + hasOuterType ? enclosingElement.getSimpleName().toString() : null, enumMember.getSimpleName().toString() ); } } diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/ProcessorSessionFactory.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/ProcessorSessionFactory.java index 806df14483..f257e343ed 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/ProcessorSessionFactory.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/ProcessorSessionFactory.java @@ -57,7 +57,6 @@ import static org.hibernate.internal.util.StringHelper.qualify; import static org.hibernate.internal.util.StringHelper.root; import static org.hibernate.internal.util.StringHelper.split; import static org.hibernate.internal.util.StringHelper.unroot; -import static org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl.addAllowedEnumLiteralsToEnumTypesMap; import static org.hibernate.processor.util.Constants.JAVA_OBJECT; /** @@ -90,7 +89,7 @@ public abstract class ProcessorSessionFactory extends MockSessionFactory { private final Types typeUtil; private final Filer filer; private final Map entityNameMappings; - private final Map> allowedEnumLiteralsToEnumTypeNames; + private final Map> enumTypesByValue; public ProcessorSessionFactory( ProcessingEnvironment processingEnvironment, @@ -100,23 +99,7 @@ public abstract class ProcessorSessionFactory extends MockSessionFactory { typeUtil = processingEnvironment.getTypeUtils(); filer = processingEnvironment.getFiler(); this.entityNameMappings = entityNameMappings; - final Map> allowedEnumLiteralsToEnumTypeNames = new HashMap<>( enumTypesByValue.size() << 2 ); - for ( Map.Entry> entry : enumTypesByValue.entrySet() ) { - final String enumConstantName = entry.getKey(); - for ( String enumClassName : entry.getValue() ) { - final TypeElement enumTypeElement = elementUtil.getTypeElement( enumClassName ); - if ( enumTypeElement != null ) { - addAllowedEnumLiteralsToEnumTypesMap( - allowedEnumLiteralsToEnumTypeNames, - enumConstantName, - enumTypeElement.getSimpleName().toString(), - elementUtil.getBinaryName( enumTypeElement ).toString(), - enumClassName - ); - } - } - } - this.allowedEnumLiteralsToEnumTypeNames = allowedEnumLiteralsToEnumTypeNames; + this.enumTypesByValue = enumTypesByValue; } @Override @@ -233,7 +216,7 @@ public abstract class ProcessorSessionFactory extends MockSessionFactory { @Override @Nullable Set getEnumTypesForValue(String value) { - final Set result = allowedEnumLiteralsToEnumTypeNames.get( value); + final Set result = enumTypesByValue.get(value); if ( result != null ) { return result; }