From d91d87c516ce4c95eb7c18d7cf478651cfdd2497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Cedomir=20Igaly?= Date: Wed, 4 Dec 2024 17:23:14 +0100 Subject: [PATCH] HHH-18693 Changed name generation for metamodel classes and sources Generated metadata for inner class A.B is A_.B_ Path source for inner class is identical to path source for enclosing class --- .../processor/test/util/CompilationStatement.java | 3 +++ .../hibernate/processor/test/util/TestUtil.java | 15 +++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/util/CompilationStatement.java b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/util/CompilationStatement.java index d9cfa8b7db..d6171c002c 100644 --- a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/util/CompilationStatement.java +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/util/CompilationStatement.java @@ -100,6 +100,9 @@ public class CompilationStatement extends Statement { } private String getPathToSource(Class testClass) { + if ( testClass.isMemberClass() ) { + return getPathToSource( testClass.getDeclaringClass() ); + } return TestUtil.getSourceBaseDir( testClass ).getAbsolutePath() + File.separator + testClass.getName() .replace( PACKAGE_SEPARATOR, File.separator ) + ".java"; } diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/util/TestUtil.java b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/util/TestUtil.java index 39f6559cf0..8e35ea1021 100644 --- a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/util/TestUtil.java +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/util/TestUtil.java @@ -335,6 +335,9 @@ public class TestUtil { } public static File getMetaModelSourceFileFor(Class clazz, boolean prefix) { + if ( clazz.isMemberClass() ) { + return getMetaModelSourceFileFor( clazz.getEnclosingClass(), prefix ); + } String metaModelClassName = getMetaModelClassName(clazz, prefix); // generate the file name String fileName = metaModelClassName.replace( PACKAGE_SEPARATOR, PATH_SEPARATOR ); @@ -351,13 +354,17 @@ public class TestUtil { } private static String getMetaModelClassName(Class clazz, boolean prefix) { - return prefix - ? clazz.getPackageName() + '.' + META_MODEL_CLASS_POSTFIX + clazz.getSimpleName() - : clazz.getName() + META_MODEL_CLASS_POSTFIX; + final String packageName = clazz.getPackageName(); + return prefix ? packageName + '.' + META_MODEL_CLASS_POSTFIX + clazz.getName().substring( packageName.length() + 1 ) + .replaceAll( "\\$", "\\$_" ) + : packageName + clazz.getName().substring( packageName.length() ) + .replaceAll( "\\$", "_\\$" ) + META_MODEL_CLASS_POSTFIX; } private static String getMetaModelClassName(String className) { - return className + META_MODEL_CLASS_POSTFIX; + final int index = className.lastIndexOf( '.' ); + final String packageName = className.substring( 0, index + 1 ); + return packageName + className.substring( packageName.length() ).replaceAll( "\\$", "_\\$" ) + META_MODEL_CLASS_POSTFIX; } public static String getMetaModelSourceAsString(Class clazz) {