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
This commit is contained in:
Čedomir Igaly 2024-12-04 17:23:14 +01:00 committed by Gavin King
parent dcdeb04a13
commit d91d87c516
2 changed files with 14 additions and 4 deletions

View File

@ -100,6 +100,9 @@ public class CompilationStatement extends Statement {
} }
private String getPathToSource(Class<?> testClass) { private String getPathToSource(Class<?> testClass) {
if ( testClass.isMemberClass() ) {
return getPathToSource( testClass.getDeclaringClass() );
}
return TestUtil.getSourceBaseDir( testClass ).getAbsolutePath() + File.separator + testClass.getName() return TestUtil.getSourceBaseDir( testClass ).getAbsolutePath() + File.separator + testClass.getName()
.replace( PACKAGE_SEPARATOR, File.separator ) + ".java"; .replace( PACKAGE_SEPARATOR, File.separator ) + ".java";
} }

View File

@ -335,6 +335,9 @@ public class TestUtil {
} }
public static File getMetaModelSourceFileFor(Class<?> clazz, boolean prefix) { public static File getMetaModelSourceFileFor(Class<?> clazz, boolean prefix) {
if ( clazz.isMemberClass() ) {
return getMetaModelSourceFileFor( clazz.getEnclosingClass(), prefix );
}
String metaModelClassName = getMetaModelClassName(clazz, prefix); String metaModelClassName = getMetaModelClassName(clazz, prefix);
// generate the file name // generate the file name
String fileName = metaModelClassName.replace( PACKAGE_SEPARATOR, PATH_SEPARATOR ); String fileName = metaModelClassName.replace( PACKAGE_SEPARATOR, PATH_SEPARATOR );
@ -351,13 +354,17 @@ public class TestUtil {
} }
private static String getMetaModelClassName(Class<?> clazz, boolean prefix) { private static String getMetaModelClassName(Class<?> clazz, boolean prefix) {
return prefix final String packageName = clazz.getPackageName();
? clazz.getPackageName() + '.' + META_MODEL_CLASS_POSTFIX + clazz.getSimpleName() return prefix ? packageName + '.' + META_MODEL_CLASS_POSTFIX + clazz.getName().substring( packageName.length() + 1 )
: clazz.getName() + META_MODEL_CLASS_POSTFIX; .replaceAll( "\\$", "\\$_" )
: packageName + clazz.getName().substring( packageName.length() )
.replaceAll( "\\$", "_\\$" ) + META_MODEL_CLASS_POSTFIX;
} }
private static String getMetaModelClassName(String className) { 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) { public static String getMetaModelSourceAsString(Class<?> clazz) {